Skip to content

Commit 7c66894

Browse files
adamkoryntabuilduser
andauthored
add client pools support CRUD operations (#311)
* add client pools support CRUD operations * Autogenerated JaCoCo coverage badge --------- Co-authored-by: builduser <builduser@rmanet.com>
1 parent 3976bc2 commit 7c66894

12 files changed

Lines changed: 1381 additions & 2 deletions

File tree

.github/coveragereport/badge_linecoverage.svg

Lines changed: 1 addition & 1 deletion
Loading

.github/coveragereport/badge_methodcoverage.svg

Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2026 Hydrologic Engineering Center
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package mil.army.usace.hec.cwms.data.api.client.controllers;
26+
27+
import static mil.army.usace.hec.cwms.data.api.client.controllers.CdaEndpointConstants.ACCEPT_HEADER_V2;
28+
import static mil.army.usace.hec.cwms.data.api.client.controllers.CdaEndpointConstants.ACCEPT_QUERY_HEADER;
29+
30+
import java.io.IOException;
31+
import mil.army.usace.hec.cwms.data.api.client.model.Pool;
32+
import mil.army.usace.hec.cwms.data.api.client.model.Pools;
33+
import mil.army.usace.hec.cwms.data.api.client.model.RadarObjectMapper;
34+
import mil.army.usace.hec.cwms.http.client.ApiConnectionInfo;
35+
import mil.army.usace.hec.cwms.http.client.HttpRequestBuilderImpl;
36+
import mil.army.usace.hec.cwms.http.client.HttpRequestResponse;
37+
import mil.army.usace.hec.cwms.http.client.request.HttpRequestExecutor;
38+
39+
public final class PoolController {
40+
41+
private static final String POOL_ENDPOINT = "pools";
42+
43+
public Pool retrievePool(ApiConnectionInfo apiConnectionInfo, PoolEndpointInput.GetOne input)
44+
throws IOException {
45+
String endpoint = POOL_ENDPOINT + "/" + input.poolId();
46+
HttpRequestExecutor executor = new HttpRequestBuilderImpl(apiConnectionInfo, endpoint)
47+
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V2)
48+
.addEndpointInput(input)
49+
.get();
50+
try (HttpRequestResponse response = executor.execute()) {
51+
return RadarObjectMapper.mapJsonToObject(response.getBody(), Pool.class);
52+
}
53+
}
54+
55+
public Pools retrievePools(ApiConnectionInfo apiConnectionInfo, PoolEndpointInput.GetAll input)
56+
throws IOException {
57+
HttpRequestExecutor executor = new HttpRequestBuilderImpl(apiConnectionInfo, POOL_ENDPOINT)
58+
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V2)
59+
.addEndpointInput(input)
60+
.get();
61+
try (HttpRequestResponse response = executor.execute()) {
62+
return RadarObjectMapper.mapJsonToObject(response.getBody(), Pools.class);
63+
}
64+
}
65+
66+
public void storePool(ApiConnectionInfo apiConnectionInfo, PoolEndpointInput.Post input)
67+
throws IOException {
68+
String body = RadarObjectMapper.mapObjectToJson(input.pool());
69+
new HttpRequestBuilderImpl(apiConnectionInfo, POOL_ENDPOINT)
70+
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V2)
71+
.addEndpointInput(input)
72+
.post()
73+
.withBody(body)
74+
.withMediaType(ACCEPT_HEADER_V2)
75+
.execute()
76+
.close();
77+
}
78+
79+
public void renamePool(ApiConnectionInfo apiConnectionInfo, PoolEndpointInput.Patch input)
80+
throws IOException {
81+
new HttpRequestBuilderImpl(apiConnectionInfo, POOL_ENDPOINT + "/" + input.poolId())
82+
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V2)
83+
.addEndpointInput(input)
84+
.patch()
85+
.withMediaType(ACCEPT_HEADER_V2)
86+
.execute()
87+
.close();
88+
}
89+
90+
public void deletePool(ApiConnectionInfo apiConnectionInfo, PoolEndpointInput.Delete input)
91+
throws IOException {
92+
String endpoint = POOL_ENDPOINT + "/" + input.poolId();
93+
new HttpRequestBuilderImpl(apiConnectionInfo, endpoint)
94+
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V2)
95+
.addEndpointInput(input)
96+
.delete()
97+
.execute()
98+
.close();
99+
}
100+
}

0 commit comments

Comments
 (0)