Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/coveragereport/badge_linecoverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion .github/coveragereport/badge_methodcoverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* MIT License
*
* Copyright (c) 2026 Hydrologic Engineering Center
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package mil.army.usace.hec.cwms.data.api.client.controllers;

import static mil.army.usace.hec.cwms.data.api.client.controllers.CdaEndpointConstants.ACCEPT_HEADER_V2;
import static mil.army.usace.hec.cwms.data.api.client.controllers.CdaEndpointConstants.ACCEPT_QUERY_HEADER;

import java.io.IOException;
import mil.army.usace.hec.cwms.data.api.client.model.Pool;
import mil.army.usace.hec.cwms.data.api.client.model.Pools;
import mil.army.usace.hec.cwms.data.api.client.model.RadarObjectMapper;
import mil.army.usace.hec.cwms.http.client.ApiConnectionInfo;
import mil.army.usace.hec.cwms.http.client.HttpRequestBuilderImpl;
import mil.army.usace.hec.cwms.http.client.HttpRequestResponse;
import mil.army.usace.hec.cwms.http.client.request.HttpRequestExecutor;

public final class PoolController {

private static final String POOL_ENDPOINT = "pools";

public Pool retrievePool(ApiConnectionInfo apiConnectionInfo, PoolEndpointInput.GetOne input)
throws IOException {
String endpoint = POOL_ENDPOINT + "/" + input.poolId();
HttpRequestExecutor executor = new HttpRequestBuilderImpl(apiConnectionInfo, endpoint)
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V2)
.addEndpointInput(input)
.get();
try (HttpRequestResponse response = executor.execute()) {
return RadarObjectMapper.mapJsonToObject(response.getBody(), Pool.class);
}
}

public Pools retrievePools(ApiConnectionInfo apiConnectionInfo, PoolEndpointInput.GetAll input)
throws IOException {
HttpRequestExecutor executor = new HttpRequestBuilderImpl(apiConnectionInfo, POOL_ENDPOINT)
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V2)
.addEndpointInput(input)
.get();
try (HttpRequestResponse response = executor.execute()) {
return RadarObjectMapper.mapJsonToObject(response.getBody(), Pools.class);
}
}

public void storePool(ApiConnectionInfo apiConnectionInfo, PoolEndpointInput.Post input)
throws IOException {
String body = RadarObjectMapper.mapObjectToJson(input.pool());
new HttpRequestBuilderImpl(apiConnectionInfo, POOL_ENDPOINT)
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V2)
.addEndpointInput(input)
.post()
.withBody(body)
.withMediaType(ACCEPT_HEADER_V2)
.execute()
.close();
}

public void renamePool(ApiConnectionInfo apiConnectionInfo, PoolEndpointInput.Patch input)
throws IOException {
new HttpRequestBuilderImpl(apiConnectionInfo, POOL_ENDPOINT + "/" + input.poolId())
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V2)
.addEndpointInput(input)
.patch()
.withMediaType(ACCEPT_HEADER_V2)
.execute()
.close();
}

public void deletePool(ApiConnectionInfo apiConnectionInfo, PoolEndpointInput.Delete input)
throws IOException {
String endpoint = POOL_ENDPOINT + "/" + input.poolId();
new HttpRequestBuilderImpl(apiConnectionInfo, endpoint)
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V2)
.addEndpointInput(input)
.delete()
.execute()
.close();
}
}
Loading
Loading