Skip to content

Commit

Permalink
Issue 765 - Adjusted start date default to 1900
Browse files Browse the repository at this point in the history
  • Loading branch information
zack-rma committed Oct 8, 2024
1 parent 4d98150 commit 6d3479e
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import cwms.cda.api.enums.UnitSystem;
import cwms.cda.api.errors.CdaError;
import cwms.cda.data.dao.LocationLevelsDao;
import cwms.cda.data.dao.LocationLevelsDaoImpl;
import cwms.cda.data.dto.LocationLevel;
Expand Down Expand Up @@ -220,8 +219,8 @@ public void delete(@NotNull Context ctx, @NotNull String levelId) {
+ "specified or default units above the NGVD-29 datum."),
@OpenApiParam(name = BEGIN, description = "Specifies the start of the time "
+ "window for data to be included in the response. If this field is "
+ "not specified, any required time window begins 24 hours prior to "
+ "the specified or default end time."),
+ "not specified, any required time window begins 1/1/1900 at "
+ "the specified or default timezone."),
@OpenApiParam(name = END, description = "Specifies the end of the time "
+ "window for data to be included in the response. If this field is "
+ "not specified, any required time window ends at the current time"),
Expand Down Expand Up @@ -295,7 +294,7 @@ public void getAll(@NotNull Context ctx) {
if (begin != null) {
beginZdt = DateUtils.parseUserDate(begin, timezone);
} else {
beginZdt = endZdt.minusHours(24);
beginZdt = ZonedDateTime.of(1900, 1, 1, 0, 0, 0, 0, tz);
}

LocationLevels levels = levelsDao.getLocationLevels(cursor, pageSize, levelIdMask,
Expand Down
147 changes: 134 additions & 13 deletions cwms-data-api/src/test/java/cwms/cda/api/LevelsControllerTestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import org.jooq.DSLContext;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -44,6 +45,7 @@
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.NavigableMap;
import java.util.TreeMap;
Expand All @@ -59,6 +61,18 @@
public class LevelsControllerTestIT extends DataApiTestIT {

public static final String OFFICE = "SPK";
private final List<LocationLevel> levelList = new ArrayList<>();

@AfterEach
void cleanup() throws Exception {
CwmsDataApiSetupCallback.getDatabaseLink().connection(c -> {
DSLContext dsl = dslContext(c, OFFICE);
LocationLevelsDaoImpl dao = new LocationLevelsDaoImpl(dsl);
for (LocationLevel level : levelList) {
dao.deleteLocationLevel(level.getLocationLevelId(), level.getLevelDate(), level.getOfficeId(), false);
}
});
}

@Test
void test_location_level() throws Exception {
Expand All @@ -70,11 +84,12 @@ void test_location_level() throws Exception {
.withConstantValue(1.0)
.withLevelUnitsId("ac-ft")
.build();
CwmsDataApiSetupCallback.getDatabaseLink().connection(c -> {
DSLContext dsl = dslContext(c, OFFICE);
LocationLevelsDaoImpl dao = new LocationLevelsDaoImpl(dsl);
dao.storeLocationLevel(level);
});
levelList.add(level);
CwmsDataApiSetupCallback.getDatabaseLink().connection(c -> {
DSLContext dsl = dslContext(c, OFFICE);
LocationLevelsDaoImpl dao = new LocationLevelsDaoImpl(dsl);
dao.storeLocationLevel(level);
});

//Read level without unit
given()
Expand Down Expand Up @@ -116,7 +131,110 @@ void test_location_level() throws Exception {
.body("constant-value",equalTo(1.0F));
}

@Test
void test_retrieve_time_window() throws Exception {
createLocation("level_get_all_loc_1", true, OFFICE);
String levelId = "level_get_all_loc_1.Flow.Ave.1Day.Regulating";
ZonedDateTime time = ZonedDateTime.of(2023, 6, 1, 0, 0, 0, 0, ZoneId.of("America/Los_Angeles"));
CwmsDataApiSetupCallback.getDatabaseLink().connection(c -> {
LocationLevel level = new LocationLevel.Builder(levelId, time)
.withOfficeId(OFFICE)
.withConstantValue(1.0)
.withLevelUnitsId("cms")
.build();
levelList.add(level);
DSLContext dsl = dslContext(c, OFFICE);
LocationLevelsDaoImpl dao = new LocationLevelsDaoImpl(dsl);
dao.storeLocationLevel(level);
});

String locId2 = "level_get_all_loc_2";
String levelId2 = locId2 + ".Stor.Ave.1Day.Regulating";
createLocation(locId2, true, OFFICE);
CwmsDataApiSetupCallback.getDatabaseLink().connection(c -> {

LocationLevel level = new LocationLevel.Builder(levelId2, time)
.withOfficeId(OFFICE)
.withConstantValue(2.0)
.withLevelUnitsId("ac-ft")
.build();
levelList.add(level);
DSLContext dsl = dslContext(c, OFFICE);
LocationLevelsDaoImpl dao = new LocationLevelsDaoImpl(dsl);
dao.storeLocationLevel(level);
});

//Read level with begin
ExtractableResponse<Response> response = given()
.log().ifValidationFails(LogDetail.ALL, true)
.accept(Formats.JSONV2)
.contentType(Formats.JSONV2)
.queryParam(Controllers.OFFICE, OFFICE)
.queryParam(LEVEL_ID_MASK, "level_get_all_loc_*")
.queryParam(BEGIN, "2020-06-01T00:00:00Z")
.when()
.redirects().follow(true)
.redirects().max(3)
.get("/levels/")
.then()
.assertThat()
.log().ifValidationFails(LogDetail.ALL, true)
.statusCode(is(HttpServletResponse.SC_OK))
.extract();

assertThat(response.path("levels.size()"),is(2));
assertEquals(OFFICE, response.path("levels[0].office-id"));
assertEquals(levelId, response.path("levels[0].location-level-id"));
assertEquals("Regulating", response.path("levels[0].specified-level-id"));
assertEquals("Ave", response.path("levels[0].parameter-type-id"));
assertEquals("Flow", response.path("levels[0].parameter-id"));
assertEquals("cms", response.path("levels[0].level-units-id"));
assertEquals("2023-06-01T07:00:00Z", response.path("levels[0].level-date"));
assertEquals("1Day", response.path("levels[0].duration-id"));
assertEquals(OFFICE, response.path("levels[1].office-id"));
assertEquals(levelId2, response.path("levels[1].location-level-id"));
assertEquals("Regulating", response.path("levels[1].specified-level-id"));
assertEquals("Ave", response.path("levels[1].parameter-type-id"));
assertEquals("Stor", response.path("levels[1].parameter-id"));
assertEquals("m3", response.path("levels[1].level-units-id"));
assertEquals("2023-06-01T07:00:00Z", response.path("levels[1].level-date"));
assertEquals("1Day", response.path("levels[1].duration-id"));

//Read level without begin and end
response = given()
.log().ifValidationFails(LogDetail.ALL, true)
.accept(Formats.JSONV2)
.contentType(Formats.JSONV2)
.queryParam(Controllers.OFFICE, OFFICE)
.queryParam(LEVEL_ID_MASK, "level_get_all_loc_*")
.when()
.redirects().follow(true)
.redirects().max(3)
.get("/levels/")
.then()
.assertThat()
.log().ifValidationFails(LogDetail.ALL, true)
.statusCode(is(HttpServletResponse.SC_OK))
.extract();

assertThat(response.path("levels.size()"),is(2));
assertEquals(OFFICE, response.path("levels[0].office-id"));
assertEquals(levelId, response.path("levels[0].location-level-id"));
assertEquals("Regulating", response.path("levels[0].specified-level-id"));
assertEquals("Ave", response.path("levels[0].parameter-type-id"));
assertEquals("Flow", response.path("levels[0].parameter-id"));
assertEquals("cms", response.path("levels[0].level-units-id"));
assertEquals("2023-06-01T07:00:00Z", response.path("levels[0].level-date"));
assertEquals("1Day", response.path("levels[0].duration-id"));
assertEquals(OFFICE, response.path("levels[1].office-id"));
assertEquals(levelId2, response.path("levels[1].location-level-id"));
assertEquals("Regulating", response.path("levels[1].specified-level-id"));
assertEquals("Ave", response.path("levels[1].parameter-type-id"));
assertEquals("Stor", response.path("levels[1].parameter-id"));
assertEquals("m3", response.path("levels[1].level-units-id"));
assertEquals("2023-06-01T07:00:00Z", response.path("levels[1].level-date"));
assertEquals("1Day", response.path("levels[1].duration-id"));
}

@Test
void test_level_as_timeseries() throws Exception {
Expand All @@ -132,6 +250,7 @@ void test_level_as_timeseries() throws Exception {
.withConstantValue((double) i)
.withLevelUnitsId("cfs")
.build();
levelList.add(level);
levels.put(level.getLevelDate().toInstant(), level);
CwmsDataApiSetupCallback.getDatabaseLink().connection(c -> {
DSLContext dsl = dslContext(c, OFFICE);
Expand All @@ -147,7 +266,7 @@ void test_level_as_timeseries() throws Exception {
.accept(Formats.JSONV2)
.contentType(Formats.JSONV2)
.header("Authorization", user.toHeaderValue())
.queryParam("office", OFFICE)
.queryParam(Controllers.OFFICE, OFFICE)
.queryParam(BEGIN, time.toInstant().toString())
.queryParam(END, time.plusDays(effectiveDateCount).toInstant().toString())
.queryParam(INTERVAL, "1Hour")
Expand Down Expand Up @@ -194,6 +313,7 @@ void test_get_all_location_level() throws Exception {
.withConstantValue(1.0)
.withLevelUnitsId("ac-ft")
.build();
levelList.add(level);
DSLContext dsl = dslContext(c, OFFICE);
LocationLevelsDaoImpl dao = new LocationLevelsDaoImpl(dsl);
dao.storeLocationLevel(level);
Expand All @@ -209,6 +329,7 @@ void test_get_all_location_level() throws Exception {
.withConstantValue(2.0)
.withLevelUnitsId("ac-ft")
.build();
levelList.add(level);
DSLContext dsl = dslContext(c, OFFICE);
LocationLevelsDaoImpl dao = new LocationLevelsDaoImpl(dsl);
dao.storeLocationLevel(level);
Expand All @@ -224,7 +345,7 @@ void test_get_all_location_level() throws Exception {
.log().ifValidationFails(LogDetail.ALL, true)
.accept(Formats.JSONV2)
.contentType(Formats.JSONV2)
.queryParam("office", OFFICE)
.queryParam(Controllers.OFFICE, OFFICE)
.queryParam(LEVEL_ID_MASK, "level_get_all.*")
.queryParam(BEGIN, startStr)
.queryParam(END, endStr)
Expand Down Expand Up @@ -266,7 +387,7 @@ void test_get_all_location_level() throws Exception {
.log().ifValidationFails(LogDetail.ALL, true)
.accept(Formats.JSONV2)
.contentType(Formats.JSONV2)
.queryParam("office", OFFICE)
.queryParam(Controllers.OFFICE, OFFICE)
.queryParam(UNIT, "SI")
.queryParam(LEVEL_ID_MASK, "level_get_all.*")
.queryParam(BEGIN, startStr)
Expand Down Expand Up @@ -308,7 +429,7 @@ void test_get_all_location_level() throws Exception {
.log().ifValidationFails(LogDetail.ALL, true)
.accept(Formats.JSONV2)
.contentType(Formats.JSONV2)
.queryParam("office", OFFICE)
.queryParam(Controllers.OFFICE, OFFICE)
.queryParam(UNIT, "EN")
.queryParam(LEVEL_ID_MASK, "level_get_all.*")
.queryParam(BEGIN, startStr)
Expand Down Expand Up @@ -347,12 +468,12 @@ void test_get_all_location_level() throws Exception {

@ParameterizedTest
@EnumSource(GetAllTestNewAliases.class)
void test_get_all_aliases_new(GetAllTestNewAliases test) throws Exception
void test_get_all_aliases_new(GetAllTestNewAliases test)
{
given()
.log().ifValidationFails(LogDetail.ALL, true)
.accept(test._accept)
.queryParam("office", OFFICE)
.queryParam(Controllers.OFFICE, OFFICE)
.queryParam(LEVEL_ID_MASK, "level_get_all.*")
.when()
.redirects().follow(true)
Expand All @@ -367,12 +488,12 @@ void test_get_all_aliases_new(GetAllTestNewAliases test) throws Exception

@ParameterizedTest
@EnumSource(GetAllTestLegacy.class)
void test_get_all_aliases_legacy(GetAllTestLegacy test) throws Exception
void test_get_all_aliases_legacy(GetAllTestLegacy test)
{
given()
.log().ifValidationFails(LogDetail.ALL, true)
.queryParam(FORMAT, test._format)
.queryParam("office", OFFICE)
.queryParam(Controllers.OFFICE, OFFICE)
.queryParam(LEVEL_ID_MASK, "level_get_all.*")
.when()
.redirects()
Expand Down

0 comments on commit 6d3479e

Please sign in to comment.