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
Expand Up @@ -25,6 +25,8 @@
package mil.army.usace.hec.cwms.data.api.client.controllers;

import static mil.army.usace.hec.cwms.data.api.client.controllers.CdaEndpointConstants.ACCEPT_XML_HEADER_V2;
import static mil.army.usace.hec.cwms.data.api.client.controllers.RatingEffectiveDatesEndpointInput.EFFECTIVE_DATES_ENDPOINT;
import mil.army.usace.hec.cwms.data.api.client.model.RatingEffectiveDatesMap;
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;
Expand Down Expand Up @@ -58,6 +60,17 @@ public String retrieveRatingXml(ApiConnectionInfo apiConnectionInfo, RatingEndpo
}
}

public RatingEffectiveDatesMap retrieveRatingEffectiveDates(ApiConnectionInfo apiConnectionInfo, RatingEffectiveDatesEndpointInput.GetAll input) throws IOException {
HttpRequestExecutor executor = new HttpRequestBuilderImpl(apiConnectionInfo, RATINGS + "/" + EFFECTIVE_DATES_ENDPOINT)
.addEndpointInput(input)
.get()
.withMediaType(ACCEPT_XML_HEADER_V2);
try (HttpRequestResponse response = executor.execute()) {
String body = response.getBody();
return RadarObjectMapper.mapJsonToObject(body, RatingEffectiveDatesMap.class);
}
}

public void storeRatingSetXml(ApiConnectionInfo apiConnectionInfo, RatingEndpointInput.Post input) throws IOException {
new HttpRequestBuilderImpl(apiConnectionInfo, RATINGS)
.addEndpointInput(input)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package mil.army.usace.hec.cwms.data.api.client.controllers;

import java.time.Instant;
import java.time.ZoneId;
import java.util.Optional;
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 mil.army.usace.hec.cwms.http.client.EndpointInput;
import mil.army.usace.hec.cwms.http.client.HttpRequestBuilder;

public final class RatingEffectiveDatesEndpointInput {

static final String EFFECTIVE_DATES_ENDPOINT = "effective-dates";
static final String OFFICE_MASK_QUERY_PARAMETER = "office-mask";
static final String RATING_ID_MASK_QUERY_PARAMETER = "rating-id-mask";
static final String TIMEZONE_QUERY_PARAMETER = "timezone";
static final String BEGIN_QUERY_PARAMETER = "begin";
static final String END_QUERY_PARAMETER = "end";

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

public static final class GetAll extends EndpointInput{
private String officeMask;
private String ratingIdMask;
private Instant begin;
private Instant end;
private ZoneId zoneId;

private GetAll() {
//empty private ctor
}

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

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

public GetAll zoneId(ZoneId timezone) {
this.zoneId = timezone;
return this;
}

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

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

@Override
protected HttpRequestBuilder addInputParameters(HttpRequestBuilder httpRequestBuilder) {
String beginString = Optional.ofNullable(begin).map(Object::toString).orElse(null);
String endString = Optional.ofNullable(end).map(Object::toString).orElse(null);
String zoneIdString = Optional.ofNullable(this.zoneId).map(ZoneId::getId).orElse(null);
return httpRequestBuilder.addQueryParameter(OFFICE_MASK_QUERY_PARAMETER, officeMask)
.addQueryParameter(RATING_ID_MASK_QUERY_PARAMETER, ratingIdMask)
.addQueryParameter(TIMEZONE_QUERY_PARAMETER, zoneIdString)
.addQueryParameter(BEGIN_QUERY_PARAMETER, beginString)
.addQueryParameter(END_QUERY_PARAMETER, endString)
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V2);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

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

import java.util.Map;
import mil.army.usace.hec.cwms.data.api.client.model.AbstractRatingMetadata;
import mil.army.usace.hec.cwms.data.api.client.model.RatingMetadata;
import mil.army.usace.hec.cwms.data.api.client.model.RatingMetadataList;
Expand Down Expand Up @@ -76,6 +77,41 @@ void testUpdateRatingSet() throws IOException {
assertDoesNotThrow(() -> controller.updateRatingSetXml(apiConnectionInfo, input));
}

@Test
public void testRatingsEffectiveDates() throws Exception {
String collect = readJsonFile("radar/v2/json/rating_effective_dates.json");
mockHttpServer.enqueue(collect);
mockHttpServer.start();
RatingController ratingController = new RatingController();
ApiConnectionInfo apiConnectionInfo = buildConnectionInfo();
RatingEffectiveDatesEndpointInput.GetAll ratingEffectiveDatesEndPointInput = RatingEffectiveDatesEndpointInput.getAll();
RatingEffectiveDatesMap ratingeffectiveDatesMap = ratingController.retrieveRatingEffectiveDates(apiConnectionInfo, ratingEffectiveDatesEndPointInput);
assertNotNull(ratingeffectiveDatesMap.getOfficeToSpecDates());
Map<String, List<RatingSpecEffectiveDates>> effectiveDates = ratingeffectiveDatesMap.getOfficeToSpecDates();
assertFalse(effectiveDates.isEmpty());
List<RatingSpecEffectiveDates> lrlEffectiveDates = effectiveDates.get("LRL");
List<RatingSpecEffectiveDates> spkEffectiveDates = effectiveDates.get("SPK");
RatingSpecEffectiveDates baseProd = lrlEffectiveDates.get(0);
assertEquals("Milford.Stage;Flow.BASE.PRODUCTION", baseProd.getRatingSpecId());
List<Instant> baseProdEffectiveDates = baseProd.getEffectiveDates();
assertEquals(2, baseProdEffectiveDates.size());
assertEquals("2020-03-01T00:00:00Z", baseProdEffectiveDates.get(0).toString());
assertEquals("2021-03-01T00:00:00Z", baseProdEffectiveDates.get(1).toString());

RatingSpecEffectiveDates logUsgs = lrlEffectiveDates.get(1);
assertEquals("Milford.Stage;Flow.Logarithmic.USGS-NWIS", logUsgs.getRatingSpecId());
List<Instant> logUsgsEffectiveDates = logUsgs.getEffectiveDates();
assertEquals(2, logUsgsEffectiveDates.size());
assertEquals("2020-03-02T00:00:00Z", logUsgsEffectiveDates.get(0).toString());
assertEquals("2021-03-02T00:00:00Z", logUsgsEffectiveDates.get(1).toString());

RatingSpecEffectiveDates stj = spkEffectiveDates.get(0);
assertEquals("STJ-St_Joseph-Missouri.Stage;Flow.USGS-BASE.Production", stj.getRatingSpecId());
List<Instant> stjEffectiveDates = stj.getEffectiveDates();
assertEquals(1, stjEffectiveDates.size());
assertEquals("2022-01-01T00:00:00Z", stjEffectiveDates.get(0).toString());
}

@Test
void testDeleteRatingSet() throws IOException {
String collect = readJsonFile("radar/v2/xml/rating.xml");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package mil.army.usace.hec.cwms.data.api.client.controllers;

import java.time.ZoneId;
import java.time.ZonedDateTime;
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 static mil.army.usace.hec.cwms.data.api.client.controllers.RatingEffectiveDatesEndpointInput.END_QUERY_PARAMETER;
import static mil.army.usace.hec.cwms.data.api.client.controllers.RatingEffectiveDatesEndpointInput.OFFICE_MASK_QUERY_PARAMETER;
import static mil.army.usace.hec.cwms.data.api.client.controllers.RatingEffectiveDatesEndpointInput.RATING_ID_MASK_QUERY_PARAMETER;
import static mil.army.usace.hec.cwms.data.api.client.controllers.RatingEffectiveDatesEndpointInput.BEGIN_QUERY_PARAMETER;
import static mil.army.usace.hec.cwms.data.api.client.controllers.RatingEffectiveDatesEndpointInput.TIMEZONE_QUERY_PARAMETER;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

final class TestRatingEffectiveDatesEndpointInput {

@Test
void testGetAll() {
MockHttpRequestBuilder mockHttpRequestBuilder = new MockHttpRequestBuilder();
String ratingId = "BUFF.Stage;Flow.WCDS.Production";
RatingEffectiveDatesEndpointInput.GetAll input = RatingEffectiveDatesEndpointInput.getAll()
.officeMask("SWT")
.ratingIdMask(ratingId)
.zoneId(ZoneId.of("UTC"))
.begin(ZonedDateTime.of(2022, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")).toInstant())
.end(ZonedDateTime.of(2022, 2, 1, 0, 0, 0, 0, ZoneId.of("UTC")).toInstant());

input.addInputParameters(mockHttpRequestBuilder);
assertEquals("SWT", mockHttpRequestBuilder.getQueryParameter(OFFICE_MASK_QUERY_PARAMETER));

assertEquals(ratingId, mockHttpRequestBuilder.getQueryParameter(RATING_ID_MASK_QUERY_PARAMETER));
assertEquals("2022-01-01T00:00:00Z", mockHttpRequestBuilder.getQueryParameter(BEGIN_QUERY_PARAMETER));
assertEquals("2022-02-01T00:00:00Z", mockHttpRequestBuilder.getQueryParameter(END_QUERY_PARAMETER));
assertEquals("UTC", mockHttpRequestBuilder.getQueryParameter(TIMEZONE_QUERY_PARAMETER));
assertEquals(ACCEPT_HEADER_V2, mockHttpRequestBuilder.getQueryHeader(ACCEPT_QUERY_HEADER));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"office-to-spec-dates":
{
"LRL": [
{
"rating-spec-id": "Milford.Stage;Flow.BASE.PRODUCTION",
"effective-dates": [
"2020-03-01T00:00:00Z",
"2021-03-01T00:00:00Z"
]
},
{
"rating-spec-id": "Milford.Stage;Flow.Logarithmic.USGS-NWIS",
"effective-dates": [
"2020-03-02T00:00:00Z",
"2021-03-02T00:00:00Z"
]
}
],
"SPK": [
{
"rating-spec-id": "STJ-St_Joseph-Missouri.Stage;Flow.USGS-BASE.Production",
"effective-dates": [
"2022-01-01T00:00:00Z"
]
}
]
}
}
Loading
Loading