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_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
Expand Up @@ -30,6 +30,7 @@
import java.io.IOException;
import java.util.Set;
import mil.army.usace.hec.cwms.data.api.client.model.LocationLevel;
import mil.army.usace.hec.cwms.data.api.client.model.LocationLevelRefs;
import mil.army.usace.hec.cwms.data.api.client.model.LocationLevels;
import mil.army.usace.hec.cwms.data.api.client.model.RadarObjectMapper;
import mil.army.usace.hec.cwms.data.api.client.model.SpecifiedLevel;
Expand All @@ -43,6 +44,7 @@ public final class LevelController {

private static final String SPECIFIED_LEVEL_ENDPOINT = "specified-levels";
private static final String LOCATION_LEVEL_ENDPOINT = "levels";
private static final String LOCATION_LEVEL_REFS_ENDPOINT = "level-refs";

public Set<SpecifiedLevel> retrieveSpecifiedLevels(ApiConnectionInfo apiConnectionInfo, SpecifiedLevelEndpointInput.GetAll input)
throws IOException {
Expand Down Expand Up @@ -107,6 +109,16 @@ public LocationLevels retrieveLocationLevels(ApiConnectionInfo apiConnectionInfo
}
}

public LocationLevelRefs retrieveLocationLevelRefs(ApiConnectionInfo apiConnectionInfo,
LocationLevelEndpointInput.GetAllRefs input) throws IOException {
HttpRequestExecutor executor = new HttpRequestBuilderImpl(apiConnectionInfo, LOCATION_LEVEL_REFS_ENDPOINT)
.addEndpointInput(input)
.get();
try (HttpRequestResponse response = executor.execute()) {
return RadarObjectMapper.mapJsonToObject(response.getBody(), LocationLevelRefs.class);
}
}

public void storeLevel(ApiConnectionInfo apiConnectionInfo, LocationLevelEndpointInput.Post input) throws IOException {
String body = RadarObjectMapper.mapObjectToJson(input.level());
new HttpRequestBuilderImpl(apiConnectionInfo, LOCATION_LEVEL_ENDPOINT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public static GetAll getAll() {
return new GetAll();
}

public static GetAllRefs getAllRefs() {
return new GetAllRefs();
}

public static Post post(LocationLevel level) {
return new Post(level);
}
Expand Down Expand Up @@ -211,6 +215,64 @@ public GetAll unit(String unit) {
}
}

public static final class GetAllRefs extends EndpointInput {
private String officeId;
private String levelIdMask = "*";
private Instant begin;
private Instant end;
private String page;
private Integer pageSize;

private GetAllRefs() {
//Empty private ctor
}

@Override
protected HttpRequestBuilder addInputParameters(HttpRequestBuilder httpRequestBuilder) {
String pageSizeString = Optional.ofNullable(pageSize).map(Object::toString).orElse(null);
String beginString = Optional.ofNullable(begin).map(Object::toString).orElse(null);
String endString = Optional.ofNullable(end).map(Object::toString).orElse(null);
return httpRequestBuilder.addQueryParameter(OFFICE_QUERY_PARAMETER, officeId)
.addQueryParameter(LEVEL_ID_MASK_QUERY_PARAMETER, levelIdMask)
.addQueryParameter(OFFICE_QUERY_PARAMETER, officeId)
.addQueryParameter(BEGIN_QUERY_PARAMETER, beginString)
.addQueryParameter(END_QUERY_PARAMETER, endString)
.addQueryParameter(PAGE_QUERY_PARAMETER, page)
.addQueryParameter(PAGE_SIZE_QUERY_PARAMETER, pageSizeString)
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V1);
}

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

public GetAllRefs levelIdMask(String levelIdMask) {
this.levelIdMask = levelIdMask;
return this;
}

public GetAllRefs begin(Instant begin) {
this.begin = begin;
return this;
}

public GetAllRefs end(Instant end) {
this.end = end;
return this;
}

public GetAllRefs page(String page) {
this.page = page;
return this;
}

public GetAllRefs pageSize(int pageSize) {
this.pageSize = pageSize;
return this;
}
}

public static final class Post extends EndpointInput {

private final LocationLevel level;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import mil.army.usace.hec.cwms.data.api.client.model.ConstantLocationLevel;
import mil.army.usace.hec.cwms.data.api.client.model.LocationLevel;
import mil.army.usace.hec.cwms.data.api.client.model.LocationLevelConstituent;
import mil.army.usace.hec.cwms.data.api.client.model.LocationLevelRef;
import mil.army.usace.hec.cwms.data.api.client.model.LocationLevelRefs;
import mil.army.usace.hec.cwms.data.api.client.model.LocationLevels;
import mil.army.usace.hec.cwms.data.api.client.model.RadarObjectMapper;
import mil.army.usace.hec.cwms.data.api.client.model.SeasonalLocationLevel;
Expand Down Expand Up @@ -129,6 +131,29 @@ void testRetrieveLocationLevels() throws IOException {
assertEquals("0", level.get().getDurationId());
}

@Test
void testRetrieveLocationLevelRefs() throws IOException {
String resource = "radar/v1/json/level_refs.json";
String collect = readJsonFile(resource);
mockHttpServer.enqueue(collect);
mockHttpServer.start();
LocationLevelEndpointInput.GetAllRefs input = LocationLevelEndpointInput.getAllRefs()
.officeId("NWDP");
LocationLevelRefs locationLevels = new LevelController().retrieveLocationLevelRefs(buildConnectionInfo(), input);
assertEquals(100, locationLevels.getPageSize());
assertNotNull(locationLevels.getPage());
assertNotNull(locationLevels.getNextPage());
List<LocationLevelRef> levels = locationLevels.getLevels();
assertFalse(levels.isEmpty());
Optional<LocationLevelRef> level = levels.stream()
.filter(s -> s.getLocationLevelId().getName().equals("AGNO.Flow.Inst.0.Flood"))
.findAny();
assertTrue(level.isPresent());
assertEquals("NWDP", level.get().getLocationLevelId().getOfficeId());
ZonedDateTime effectiveDate = ZonedDateTime.of(1900, 1, 1, 8, 0, 0, 0, ZoneId.of("UTC"));
assertEquals(effectiveDate.toInstant(), level.get().getEffectiveDates().get(0));
}

@Test
void testRetrieveLocationLevelSubtypes() throws IOException {
String resource = "radar/v2/json/location_levels.json";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,44 @@ void testQueryRequestNulls() {
assertEquals(ACCEPT_HEADER_V2, mockHttpRequestBuilder.getQueryHeader(ACCEPT_QUERY_HEADER));
}


@Test
void testQueryRequestRefs() {
MockHttpRequestBuilder mockHttpRequestBuilder = new MockHttpRequestBuilder();
ZoneId zoneId = ZoneId.of("America/Los_Angeles");
Instant begin = ZonedDateTime.of(2015, 1, 1, 0, 0, 0, 0, zoneId).toInstant();
Instant end = begin.plusSeconds(30);
LocationLevelEndpointInput.GetAllRefs input = LocationLevelEndpointInput.getAllRefs()
.officeId("SWT")
.levelIdMask("MASK")
.page("abc")
.pageSize(10)
.begin(begin)
.end(end);
input.addInputParameters(mockHttpRequestBuilder);
assertEquals("SWT", mockHttpRequestBuilder.getQueryParameter(OFFICE_QUERY_PARAMETER));
assertEquals("MASK", mockHttpRequestBuilder.getQueryParameter(LEVEL_ID_MASK_QUERY_PARAMETER));
assertEquals("10", mockHttpRequestBuilder.getQueryParameter(PAGE_SIZE_QUERY_PARAMETER));
assertEquals("abc", mockHttpRequestBuilder.getQueryParameter(PAGE_QUERY_PARAMETER));
assertEquals("2015-01-01T08:00:00Z", mockHttpRequestBuilder.getQueryParameter(BEGIN_QUERY_PARAMETER));
assertEquals("2015-01-01T08:00:30Z", mockHttpRequestBuilder.getQueryParameter(END_QUERY_PARAMETER));
assertEquals(ACCEPT_HEADER_V1, mockHttpRequestBuilder.getQueryHeader(ACCEPT_QUERY_HEADER));
}

@Test
void testQueryRequestRefsNulls() {
MockHttpRequestBuilder mockHttpRequestBuilder = new MockHttpRequestBuilder();
LocationLevelEndpointInput.GetAllRefs input = LocationLevelEndpointInput.getAllRefs();
input.addInputParameters(mockHttpRequestBuilder);
assertNull(mockHttpRequestBuilder.getQueryParameter(OFFICE_QUERY_PARAMETER));
assertEquals("*", mockHttpRequestBuilder.getQueryParameter(LEVEL_ID_MASK_QUERY_PARAMETER));
assertNull(mockHttpRequestBuilder.getQueryParameter(PAGE_SIZE_QUERY_PARAMETER));
assertNull(mockHttpRequestBuilder.getQueryParameter(PAGE_QUERY_PARAMETER));
assertNull(mockHttpRequestBuilder.getQueryParameter(BEGIN_QUERY_PARAMETER));
assertNull(mockHttpRequestBuilder.getQueryParameter(END_QUERY_PARAMETER));
assertEquals(ACCEPT_HEADER_V1, mockHttpRequestBuilder.getQueryHeader(ACCEPT_QUERY_HEADER));
}

@Test
void testGet() {
Instant now = Instant.now();
Expand Down
Loading