Skip to content

Commit 95cee47

Browse files
add location kind client controller support (#293)
* add location kind client controller support * Apply suggestion from @rma-bryson Co-authored-by: Bryson Spilman <87150647+rma-bryson@users.noreply.github.com> --------- Co-authored-by: Bryson Spilman <87150647+rma-bryson@users.noreply.github.com>
1 parent 9a66258 commit 95cee47

7 files changed

Lines changed: 724 additions & 1 deletion

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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_V1;
28+
import static mil.army.usace.hec.cwms.data.api.client.controllers.CdaEndpointConstants.ACCEPT_QUERY_HEADER;
29+
30+
import java.io.IOException;
31+
import java.util.List;
32+
import mil.army.usace.hec.cwms.data.api.client.model.CwmsIdLocationKind;
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+
40+
public final class LocationKindController {
41+
private static final String LOCATION_KIND_ENDPOINT = "locations/with-kinds";
42+
43+
public List<CwmsIdLocationKind> getLocationsWithKind(ApiConnectionInfo apiConnectionInfo,
44+
LocationKindEndpointInput.GetAll input) throws IOException {
45+
String endpoint = LOCATION_KIND_ENDPOINT;
46+
HttpRequestExecutor executor = new HttpRequestBuilderImpl(apiConnectionInfo, endpoint)
47+
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V1)
48+
.addEndpointInput(input)
49+
.get();
50+
try (HttpRequestResponse response = executor.execute()) {
51+
return RadarObjectMapper.mapJsonToListOfObjects(response.getBody(), CwmsIdLocationKind.class);
52+
}
53+
}
54+
55+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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_V1;
28+
import static mil.army.usace.hec.cwms.data.api.client.controllers.CdaEndpointConstants.ACCEPT_QUERY_HEADER;
29+
30+
import mil.army.usace.hec.cwms.http.client.EndpointInput;
31+
import mil.army.usace.hec.cwms.http.client.HttpRequestBuilder;
32+
33+
34+
public final class LocationKindEndpointInput {
35+
36+
private LocationKindEndpointInput() {
37+
throw new AssertionError("factory class");
38+
}
39+
40+
public static LocationKindEndpointInput.GetAll getAll() {
41+
return new LocationKindEndpointInput.GetAll();
42+
}
43+
44+
public static final class GetAll extends EndpointInput {
45+
46+
static final String NAMES_QUERY_PARAMETER = "names";
47+
static final String LOCATION_KIND_LIKE_QUERY_PARAMETER = "location-kind-like";
48+
static final String OFFICE_QUERY_PARAMETER = "office";
49+
private String officeId;
50+
private String locationIdMask;
51+
private String locationKindMask;
52+
53+
private GetAll() {
54+
//Empty private ctor
55+
}
56+
57+
@Override
58+
protected HttpRequestBuilder addInputParameters(HttpRequestBuilder httpRequestBuilder) {
59+
return httpRequestBuilder.addQueryParameter(OFFICE_QUERY_PARAMETER, officeId)
60+
.addQueryParameter(NAMES_QUERY_PARAMETER, locationIdMask)
61+
.addQueryParameter(LOCATION_KIND_LIKE_QUERY_PARAMETER, locationKindMask)
62+
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V1);
63+
}
64+
65+
public LocationKindEndpointInput.GetAll officeId(String officeId) {
66+
this.officeId = officeId;
67+
return this;
68+
}
69+
70+
public LocationKindEndpointInput.GetAll locationIdMask(String locationIdMask) {
71+
this.locationIdMask = locationIdMask;
72+
return this;
73+
}
74+
75+
public LocationKindEndpointInput.GetAll locationKindMask(String locationKindMask) {
76+
this.locationKindMask = locationKindMask;
77+
return this;
78+
}
79+
80+
}
81+
82+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 org.junit.jupiter.api.Assertions.assertEquals;
28+
import static org.junit.jupiter.api.Assertions.assertFalse;
29+
30+
import mil.army.usace.hec.cwms.http.client.ApiConnectionInfo;
31+
import org.junit.jupiter.api.Test;
32+
33+
class TestLocationKindController extends TestController {
34+
35+
public static final String MASK = "PROJ-*";
36+
public static final String OFFICE = "SPK";
37+
38+
@Test
39+
void testGetLocationKindChildLocations() throws Exception {
40+
String collect = readJsonFile("radar/v1/json/cwmsid_location_kinds.json");
41+
mockHttpServer.enqueue(collect);
42+
mockHttpServer.start();
43+
LocationKindController controller = new LocationKindController();
44+
LocationKindEndpointInput.GetAll input = LocationKindEndpointInput.getAll()
45+
.locationIdMask(MASK)
46+
.officeId(OFFICE);
47+
ApiConnectionInfo apiConnectionInfo = buildConnectionInfo();
48+
var locations = controller.getLocationsWithKind(apiConnectionInfo, input);
49+
assertFalse(locations.isEmpty());
50+
var loc1 = locations.get(0);
51+
assertEquals("PROJ-ABCD", loc1.getLocationId().getName());
52+
assertEquals(OFFICE, loc1.getLocationId().getOfficeId());
53+
assertEquals("Outlet", loc1.getLocationKindId());
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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_V1;
28+
import static mil.army.usace.hec.cwms.data.api.client.controllers.CdaEndpointConstants.ACCEPT_QUERY_HEADER;
29+
import static org.junit.jupiter.api.Assertions.assertEquals;
30+
31+
import org.junit.jupiter.api.Test;
32+
33+
class TestLocationKindEndpointInput {
34+
35+
36+
@Test
37+
void testGetAllQueryRequest() {
38+
MockHttpRequestBuilder request = new MockHttpRequestBuilder();
39+
String projectId = "PROJ";
40+
String officeId = "SPK";
41+
String kind = "Outlet";
42+
LocationKindEndpointInput.GetAll input = LocationKindEndpointInput.getAll()
43+
.locationIdMask(projectId)
44+
.locationKindMask(kind)
45+
.officeId(officeId);
46+
input.addInputParameters(request);
47+
assertEquals(officeId, request.getQueryParameter(LocationKindEndpointInput.GetAll.OFFICE_QUERY_PARAMETER));
48+
assertEquals(projectId, request.getQueryParameter(LocationKindEndpointInput.GetAll.NAMES_QUERY_PARAMETER));
49+
assertEquals(kind, request.getQueryParameter(LocationKindEndpointInput.GetAll.LOCATION_KIND_LIKE_QUERY_PARAMETER));
50+
assertEquals(ACCEPT_HEADER_V1, request.getQueryHeader(ACCEPT_QUERY_HEADER));
51+
}
52+
53+
}

0 commit comments

Comments
 (0)