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
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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_V1;
import static mil.army.usace.hec.cwms.data.api.client.controllers.CdaEndpointConstants.ACCEPT_QUERY_HEADER;

import java.io.IOException;
import java.util.List;
import mil.army.usace.hec.cwms.data.api.client.model.CwmsIdLocationKind;
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 LocationKindController {
private static final String LOCATION_KIND_ENDPOINT = "locations/with-kinds";

public List<CwmsIdLocationKind> getLocationsWithKind(ApiConnectionInfo apiConnectionInfo,
LocationKindEndpointInput.GetAll input) throws IOException {
String endpoint = LOCATION_KIND_ENDPOINT;
HttpRequestExecutor executor = new HttpRequestBuilderImpl(apiConnectionInfo, endpoint)
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V1)
.addEndpointInput(input)
.get();
try (HttpRequestResponse response = executor.execute()) {
return RadarObjectMapper.mapJsonToListOfObjects(response.getBody(), CwmsIdLocationKind.class);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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_V1;
import static mil.army.usace.hec.cwms.data.api.client.controllers.CdaEndpointConstants.ACCEPT_QUERY_HEADER;

import mil.army.usace.hec.cwms.http.client.EndpointInput;
import mil.army.usace.hec.cwms.http.client.HttpRequestBuilder;


public final class LocationKindEndpointInput {

private LocationKindEndpointInput() {
throw new AssertionError("factory class");
}

public static LocationKindEndpointInput.GetAll getAll() {
return new LocationKindEndpointInput.GetAll();
}

public static final class GetAll extends EndpointInput {

static final String NAMES_QUERY_PARAMETER = "names";
static final String LOCATION_KIND_LIKE_QUERY_PARAMETER = "location-kind-like";
static final String OFFICE_QUERY_PARAMETER = "office";
private String officeId;
private String locationIdMask;
private String locationKindMask;

private GetAll() {
//Empty private ctor
}

@Override
protected HttpRequestBuilder addInputParameters(HttpRequestBuilder httpRequestBuilder) {
return httpRequestBuilder.addQueryParameter(OFFICE_QUERY_PARAMETER, officeId)
.addQueryParameter(NAMES_QUERY_PARAMETER, locationIdMask)
.addQueryParameter(LOCATION_KIND_LIKE_QUERY_PARAMETER, locationKindMask)
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V1);
}

public LocationKindEndpointInput.GetAll officeId(String officeId) {
this.officeId = officeId;
return this;
}

public LocationKindEndpointInput.GetAll locationIdMask(String locationIdMask) {
this.locationIdMask = locationIdMask;
return this;
}

public LocationKindEndpointInput.GetAll locationKindMask(String locationKindMask) {
this.locationKindMask = locationKindMask;
return this;
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

import mil.army.usace.hec.cwms.http.client.ApiConnectionInfo;
import org.junit.jupiter.api.Test;

class TestLocationKindController extends TestController {

public static final String MASK = "PROJ-*";
public static final String OFFICE = "SPK";

@Test
void testGetLocationKindChildLocations() throws Exception {
String collect = readJsonFile("radar/v1/json/cwmsid_location_kinds.json");
mockHttpServer.enqueue(collect);
mockHttpServer.start();
LocationKindController controller = new LocationKindController();
LocationKindEndpointInput.GetAll input = LocationKindEndpointInput.getAll()
.locationIdMask(MASK)
.officeId(OFFICE);
ApiConnectionInfo apiConnectionInfo = buildConnectionInfo();
var locations = controller.getLocationsWithKind(apiConnectionInfo, input);
assertFalse(locations.isEmpty());
var loc1 = locations.get(0);
assertEquals("PROJ-ABCD", loc1.getLocationId().getName());
assertEquals(OFFICE, loc1.getLocationId().getOfficeId());
assertEquals("Outlet", loc1.getLocationKindId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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_V1;
import static mil.army.usace.hec.cwms.data.api.client.controllers.CdaEndpointConstants.ACCEPT_QUERY_HEADER;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

class TestLocationKindEndpointInput {


@Test
void testGetAllQueryRequest() {
MockHttpRequestBuilder request = new MockHttpRequestBuilder();
String projectId = "PROJ";
String officeId = "SPK";
String kind = "Outlet";
LocationKindEndpointInput.GetAll input = LocationKindEndpointInput.getAll()
.locationIdMask(projectId)
.locationKindMask(kind)
.officeId(officeId);
input.addInputParameters(request);
assertEquals(officeId, request.getQueryParameter(LocationKindEndpointInput.GetAll.OFFICE_QUERY_PARAMETER));
assertEquals(projectId, request.getQueryParameter(LocationKindEndpointInput.GetAll.NAMES_QUERY_PARAMETER));
assertEquals(kind, request.getQueryParameter(LocationKindEndpointInput.GetAll.LOCATION_KIND_LIKE_QUERY_PARAMETER));
assertEquals(ACCEPT_HEADER_V1, request.getQueryHeader(ACCEPT_QUERY_HEADER));
}

}
Loading
Loading