Skip to content

Commit

Permalink
Merge branch 'USACE:develop' into feature/cto-137-project-sub-location
Browse files Browse the repository at this point in the history
  • Loading branch information
rma-rripken authored Aug 7, 2024
2 parents de5206a + 8b7069a commit fac0bf2
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 224 deletions.
11 changes: 2 additions & 9 deletions cwms-data-api/src/main/java/cwms/cda/api/LevelsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,11 @@ public void create(@NotNull Context ctx) {
String formatHeader = reqContentType != null ? reqContentType : Formats.JSONV2;
ContentType contentType = Formats.parseHeader(formatHeader);
LocationLevel level = Formats.parseContent(contentType, ctx.body(), LocationLevel.class);
ZonedDateTime unmarshalledDateTime = level.getLevelDate(); //getUnmarshalledDateTime

ZoneId timezoneId = unmarshalledDateTime.getZone();
if (timezoneId == null) {
timezoneId = ZoneId.systemDefault();
}
level = new LocationLevel.Builder(level).withLevelDate(unmarshalledDateTime).build();
level.validate();

DSLContext dsl = getDslContext(ctx);
LocationLevelsDao levelsDao = getLevelsDao(dsl);
levelsDao.storeLocationLevel(level, timezoneId);
levelsDao.storeLocationLevel(level);
ctx.status(HttpServletResponse.SC_OK).json("Created Location Level");
}
}
Expand Down Expand Up @@ -446,7 +439,7 @@ public void update(@NotNull Context ctx, @NotNull String oldLevelId) {
levelFromBody);
updatedLocationLevel = new LocationLevel.Builder(updatedLocationLevel)
.withLevelDate(unmarshalledDateTime).build();
levelsDao.storeLocationLevel(updatedLocationLevel, unmarshalledDateTime.getZone());
levelsDao.storeLocationLevel(updatedLocationLevel);
ctx.status(HttpServletResponse.SC_OK).json("Updated Location Level");
}
} catch (JsonProcessingException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.javalin.apibuilder.CrudHandler;
import io.javalin.http.Context;
import io.javalin.plugin.openapi.annotations.OpenApi;
import io.javalin.plugin.openapi.annotations.OpenApiContent;
import io.javalin.plugin.openapi.annotations.OpenApiParam;
import io.javalin.plugin.openapi.annotations.OpenApiResponse;

Expand Down Expand Up @@ -78,7 +79,10 @@ public void delete(Context ctx, String id) {
+ " used."),
},
responses = {
@OpenApiResponse(status = STATUS_200)
@OpenApiResponse(status = STATUS_200, content = {
@OpenApiContent(isArray = true, from = Parameter.class, type = Formats.JSONV2),
@OpenApiContent(isArray = true, from = Parameter.class, type = Formats.JSON)
}),
},
tags = {"Parameters"}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.javalin.apibuilder.CrudHandler;
import io.javalin.http.Context;
import io.javalin.plugin.openapi.annotations.OpenApi;
import io.javalin.plugin.openapi.annotations.OpenApiContent;
import io.javalin.plugin.openapi.annotations.OpenApiParam;
import io.javalin.plugin.openapi.annotations.OpenApiResponse;

Expand Down Expand Up @@ -74,7 +75,10 @@ public void delete(Context ctx, String id) {
+ "\n* `json` (default)")
},
responses = {
@OpenApiResponse(status = STATUS_200),
@OpenApiResponse(status = STATUS_200, content = {
@OpenApiContent(from = TimeZoneIds.class, type = Formats.JSONV2),
@OpenApiContent(from = TimeZoneIds.class, type = Formats.JSON)
}),
@OpenApiResponse(status = STATUS_501, description = "The format requested is not "
+ "implemented")
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface LocationLevelsDao {
void deleteLocationLevel(String locationLevelName, ZonedDateTime date, String officeId,
Boolean cascadeDelete);

void storeLocationLevel(LocationLevel level, ZoneId zoneId);
void storeLocationLevel(LocationLevel level);

void renameLocationLevel(String oldLocationLevelName, String newLocationLevelName, String officeId);

Expand Down
225 changes: 81 additions & 144 deletions cwms-data-api/src/main/java/cwms/cda/data/dao/LocationLevelsDaoImpl.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ private Condition buildWhereCondition(String groupOfficeId, String categoryId, S


public void delete(String categoryId, String groupId, String office) {
dsl.connection(c ->
connection(dsl, c ->
CWMS_TS_PACKAGE.call_DELETE_TS_GROUP(
getDslContext(c,office).configuration(), categoryId, groupId, office
)
);
}

public void create(TimeSeriesGroup group, boolean failIfExists) {
dsl.connection(c-> {
connection(dsl, c-> {
Configuration configuration = getDslContext(c,group.getOfficeId()).configuration();
String categoryId = group.getTimeSeriesCategory().getId();
CWMS_TS_PACKAGE.call_STORE_TS_GROUP(configuration, categoryId,
Expand All @@ -273,7 +273,7 @@ private void assignTs(Configuration configuration,TimeSeriesGroup group) {
}

public void assignTs(TimeSeriesGroup group) {
dsl.connection(c->assignTs(getDslContext(c,group.getOfficeId()).configuration(),group));
connection(dsl, c->assignTs(getDslContext(c,group.getOfficeId()).configuration(),group));
}

private static TS_ALIAS_T convertToTsAliasType(AssignedTimeSeries assignedTimeSeries) {
Expand All @@ -283,7 +283,7 @@ private static TS_ALIAS_T convertToTsAliasType(AssignedTimeSeries assignedTimeSe
}

public void renameTimeSeriesGroup(String oldGroupId, TimeSeriesGroup group) {
dsl.connection(c->
connection(dsl, c->
CWMS_TS_PACKAGE.call_RENAME_TS_GROUP(
getDslContext(c,group.getOfficeId()).configuration(),
group.getTimeSeriesCategory().getId(), oldGroupId, group.getId(),
Expand All @@ -292,7 +292,7 @@ public void renameTimeSeriesGroup(String oldGroupId, TimeSeriesGroup group) {
}

public void unassignAllTs(TimeSeriesGroup group) {
dsl.connection(c ->
connection(dsl, c ->
CWMS_TS_PACKAGE.call_UNASSIGN_TS_GROUP(
getDslContext(c,group.getOfficeId()).configuration(),
group.getTimeSeriesCategory().getId(), group.getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void test_location_level() throws Exception {
CwmsDataApiSetupCallback.getDatabaseLink().connection(c -> {
DSLContext dsl = dslContext(c, OFFICE);
LocationLevelsDaoImpl dao = new LocationLevelsDaoImpl(dsl);
dao.storeLocationLevel(level, level.getLevelDate().getZone());
dao.storeLocationLevel(level);
});

//Read level without unit
Expand Down Expand Up @@ -136,7 +136,7 @@ void test_level_as_timeseries() throws Exception {
CwmsDataApiSetupCallback.getDatabaseLink().connection(c -> {
DSLContext dsl = dslContext(c, OFFICE);
LocationLevelsDaoImpl dao = new LocationLevelsDaoImpl(dsl);
dao.storeLocationLevel(level, level.getLevelDate().getZone());
dao.storeLocationLevel(level);
});
}

Expand Down Expand Up @@ -196,7 +196,7 @@ void test_get_all_location_level() throws Exception {
.build();
DSLContext dsl = dslContext(c, OFFICE);
LocationLevelsDaoImpl dao = new LocationLevelsDaoImpl(dsl);
dao.storeLocationLevel(level, level.getLevelDate().getZone());
dao.storeLocationLevel(level);
});

String locId2 = "level_get_all_loc2";
Expand All @@ -211,7 +211,7 @@ void test_get_all_location_level() throws Exception {
.build();
DSLContext dsl = dslContext(c, OFFICE);
LocationLevelsDaoImpl dao = new LocationLevelsDaoImpl(dsl);
dao.storeLocationLevel(level, level.getLevelDate().getZone());
dao.storeLocationLevel(level);
});

String startStr = "2023-06-01T00:00:00Z";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void testStore() throws Exception
location = buildTestLocation("TEST_LOC");
locationsDao.storeLocation(location);
LocationLevelsDao levelsDao = new LocationLevelsDaoImpl(getDslContext(getConnection(), OFFICE_ID));
levelsDao.storeLocationLevel(levelToStore, ZoneId.of("UTC"));
levelsDao.storeLocationLevel(levelToStore);
LocationLevel retrievedLevel = levelsDao.retrieveLocationLevel(levelToStore.getLocationLevelId(), UnitSystem.EN.getValue(), levelToStore.getLevelDate(), "LRL");
assertNotNull(retrievedLevel);
assertEquals(levelToStore.getLocationLevelId(), retrievedLevel.getLocationLevelId());
Expand All @@ -91,7 +91,7 @@ void testDeleteLocationLevel() throws Exception
LocationsDao locationsDao = new LocationsDaoImpl(getDslContext(getConnection(), OFFICE_ID));
Location location = buildTestLocation("TEST_LOC5");
locationsDao.storeLocation(location);
levelsDao.storeLocationLevel(levelToStore, ZoneId.of("UTC"));
levelsDao.storeLocationLevel(levelToStore);
LocationLevel retrievedLevel = levelsDao.retrieveLocationLevel(levelToStore.getLocationLevelId(), UnitSystem.EN.getValue(), levelToStore.getLevelDate(), OFFICE_ID);
assertNotNull(retrievedLevel);
levelsDao.deleteLocationLevel(levelToStore.getLocationLevelId(), levelToStore.getLevelDate(), OFFICE_ID, true);
Expand All @@ -109,7 +109,7 @@ void testUpdate() throws Exception
Location location = buildTestLocation("TEST_LOC6");
try {
locationsDao.storeLocation(location);
levelsDao.storeLocationLevel(levelToStore, ZoneId.of("UTC"));
levelsDao.storeLocationLevel(levelToStore);
String body = getRenamedExampleJSON();
String format = Formats.JSON;

Expand All @@ -123,7 +123,7 @@ void testUpdate() throws Exception
{
levelsDao.renameLocationLevel(levelToStore.getLocationLevelId(), updatedLocationLevel.getLocationLevelId(), OFFICE_ID);
} else {
levelsDao.storeLocationLevel(updatedLocationLevel, updatedLocationLevel.getLevelDate().getZone());
levelsDao.storeLocationLevel(updatedLocationLevel);
}
LocationLevel retrievedLevel = levelsDao.retrieveLocationLevel(updatedLocationLevel.getLocationLevelId(), UnitSystem.EN.getValue(), updatedLocationLevel.getLevelDate(), OFFICE_ID);
assertNotNull(retrievedLevel);
Expand All @@ -136,61 +136,6 @@ void testUpdate() throws Exception
}
}


@Test
void testIfcToDto(){
usace.cwms.db.dao.ifc.level.SeasonalValueBean ifcBean =
new usace.cwms.db.dao.ifc.level.SeasonalValueBean();
double value = 23.0;
ifcBean.setValue(value);

// just value
SeasonalValueBean dtoBean = LocationLevelsDaoImpl.buildSeasonalValue(ifcBean);
assertEquals(value, dtoBean.getValue());
assertNull(dtoBean.getOffsetMonths());
assertNull(dtoBean.getOffsetMinutes());

// just minutes
ifcBean.setOffsetMinutes(BigInteger.valueOf(22));
dtoBean = LocationLevelsDaoImpl.buildSeasonalValue(ifcBean);
assertNull(dtoBean.getOffsetMonths());
assertEquals(22, dtoBean.getOffsetMinutes().intValue());


// just months
ifcBean.setOffsetMinutes(null);
ifcBean.setOffsetMonths(Integer.valueOf(7).byteValue());
dtoBean = LocationLevelsDaoImpl.buildSeasonalValue(ifcBean);
assertNull(dtoBean.getOffsetMinutes());
assertEquals(7, dtoBean.getOffsetMonths());
}

@Test
void testDtoToIfc() {
// Now go the other way
SeasonalValueBean.Builder builder = new SeasonalValueBean.Builder(23.0);

// just value
usace.cwms.db.dao.ifc.level.SeasonalValueBean ifcBean = LocationLevelsDaoImpl.buildSeasonalValue(builder.build());
assertEquals(23.0, ifcBean.getValue());
assertNull(ifcBean.getOffsetMonths());
assertNull(ifcBean.getOffsetMinutes());

// just minutes
builder.withOffsetMinutes(BigInteger.valueOf(22));
ifcBean = LocationLevelsDaoImpl.buildSeasonalValue(builder.build());
assertEquals(23.0, ifcBean.getValue());
assertNull(ifcBean.getOffsetMonths());
assertEquals(22, ifcBean.getOffsetMinutes().intValue());

// just months
builder.withOffsetMinutes(null).withOffsetMonths(Integer.valueOf(7).byteValue());
ifcBean = LocationLevelsDaoImpl.buildSeasonalValue(builder.build());
assertEquals(23.0, ifcBean.getValue());
assertNull(ifcBean.getOffsetMinutes());
assertEquals(7, ifcBean.getOffsetMonths().intValue());
}

private LocationLevel deserializeLocationLevel(String body, String format, String office) throws IOException
{
ObjectMapper om = getObjectMapperForFormat(format);
Expand Down
Loading

0 comments on commit fac0bf2

Please sign in to comment.