Skip to content

Commit 9b53171

Browse files
authored
add support for all location level types and expiration date (#286)
* add support for all location level types and expiration date
1 parent 3ce1be5 commit 9b53171

14 files changed

Lines changed: 1536 additions & 396 deletions

File tree

cwms-data-api-client/src/test/java/mil/army/usace/hec/cwms/data/api/client/controllers/TestLevelController.java

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* MIT License
33
*
4-
* Copyright (c) 2024 Hydrologic Engineering Center
4+
* Copyright (c) 2025 Hydrologic Engineering Center
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -24,12 +24,11 @@
2424

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

27-
import mil.army.usace.hec.cwms.data.api.client.model.LocationLevel;
28-
import mil.army.usace.hec.cwms.data.api.client.model.LocationLevels;
29-
import mil.army.usace.hec.cwms.data.api.client.model.RadarObjectMapper;
30-
import mil.army.usace.hec.cwms.data.api.client.model.SpecifiedLevel;
31-
import mil.army.usace.hec.cwms.data.api.client.model.TimeSeries;
32-
import org.junit.jupiter.api.Test;
27+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
29+
import static org.junit.jupiter.api.Assertions.assertFalse;
30+
import static org.junit.jupiter.api.Assertions.assertNotNull;
31+
import static org.junit.jupiter.api.Assertions.assertTrue;
3332

3433
import java.io.IOException;
3534
import java.time.Instant;
@@ -38,8 +37,17 @@
3837
import java.util.List;
3938
import java.util.Optional;
4039
import java.util.Set;
41-
42-
import static org.junit.jupiter.api.Assertions.*;
40+
import mil.army.usace.hec.cwms.data.api.client.model.ConstantLocationLevel;
41+
import mil.army.usace.hec.cwms.data.api.client.model.LocationLevel;
42+
import mil.army.usace.hec.cwms.data.api.client.model.LocationLevelConstituent;
43+
import mil.army.usace.hec.cwms.data.api.client.model.LocationLevels;
44+
import mil.army.usace.hec.cwms.data.api.client.model.RadarObjectMapper;
45+
import mil.army.usace.hec.cwms.data.api.client.model.SeasonalLocationLevel;
46+
import mil.army.usace.hec.cwms.data.api.client.model.SpecifiedLevel;
47+
import mil.army.usace.hec.cwms.data.api.client.model.TimeSeries;
48+
import mil.army.usace.hec.cwms.data.api.client.model.TimeSeriesLocationLevel;
49+
import mil.army.usace.hec.cwms.data.api.client.model.VirtualLocationLevel;
50+
import org.junit.jupiter.api.Test;
4351

4452
class TestLevelController extends TestController {
4553

@@ -114,13 +122,51 @@ void testRetrieveLocationLevels() throws IOException {
114122
assertEquals("Top of Flood", level.get().getSpecifiedLevelId());
115123
assertEquals(LocationLevel.ParameterTypeIdEnum.INST, level.get().getParameterTypeId());
116124
assertEquals("Elev", level.get().getParameterId());
117-
assertEquals(321.564, level.get().getConstantValue());
125+
assertEquals(321.564, ((ConstantLocationLevel) level.get()).getConstantValue());
118126
assertEquals("m", level.get().getLevelUnitsId());
119127
ZonedDateTime effectiveDate = ZonedDateTime.of(1900, 1, 1, 5, 0, 0, 0, ZoneId.of("UTC"));
120128
assertEquals(effectiveDate.toInstant(), level.get().getLevelDate().toInstant());
121129
assertEquals("0", level.get().getDurationId());
122130
}
123131

132+
@Test
133+
void testRetrieveLocationLevelSubtypes() throws IOException {
134+
String resource = "radar/v2/json/location_levels.json";
135+
String collect = readJsonFile(resource);
136+
mockHttpServer.enqueue(collect);
137+
mockHttpServer.start();
138+
LocationLevelEndpointInput.GetAll input = LocationLevelEndpointInput.getAll()
139+
.officeId("LRL");
140+
LocationLevels locationLevels = new LevelController().retrieveLocationLevels(buildConnectionInfo(), input);
141+
assertTrue(locationLevels.getLevels().stream()
142+
.anyMatch(l -> l instanceof VirtualLocationLevel));
143+
assertTrue(locationLevels.getLevels().stream()
144+
.anyMatch(l -> l instanceof ConstantLocationLevel));
145+
assertTrue(locationLevels.getLevels().stream()
146+
.anyMatch(l -> l instanceof TimeSeriesLocationLevel));
147+
assertTrue(locationLevels.getLevels().stream()
148+
.anyMatch(l -> l instanceof SeasonalLocationLevel));
149+
}
150+
151+
@Test
152+
void testRetrieveVirtualLevel() throws IOException {
153+
String resource = "radar/v2/json/location_levels.json";
154+
String collect = readJsonFile(resource);
155+
mockHttpServer.enqueue(collect);
156+
mockHttpServer.start();
157+
LocationLevelEndpointInput.GetAll input = LocationLevelEndpointInput.getAll()
158+
.officeId("LRL");
159+
LocationLevels locationLevels = new LevelController().retrieveLocationLevels(buildConnectionInfo(), input);
160+
VirtualLocationLevel virtualLevel = (VirtualLocationLevel) locationLevels.getLevels().stream()
161+
.filter(l -> l instanceof VirtualLocationLevel)
162+
.findAny()
163+
.get();
164+
assertTrue(virtualLevel.getConstituents().stream()
165+
.anyMatch(l -> !(l instanceof LocationLevelConstituent)));
166+
assertTrue(virtualLevel.getConstituents().stream()
167+
.anyMatch(l -> l instanceof LocationLevelConstituent));
168+
}
169+
124170
@Test
125171
void testRetrieveLocationLevel() throws IOException {
126172
String resource = "radar/v2/json/location_level.json";
@@ -135,10 +181,12 @@ void testRetrieveLocationLevel() throws IOException {
135181
assertEquals("Bottom of Inlet", level.getSpecifiedLevelId());
136182
assertEquals(LocationLevel.ParameterTypeIdEnum.INST, level.getParameterTypeId());
137183
assertEquals("Elev", level.getParameterId());
138-
assertEquals(145.6944, level.getConstantValue());
184+
assertEquals(145.6944, ((ConstantLocationLevel) level).getConstantValue());
139185
assertEquals("m", level.getLevelUnitsId());
140186
assertEquals(instant, level.getLevelDate().toInstant());
141187
assertEquals("0", level.getDurationId());
188+
Instant expiration = Instant.parse("2900-01-01T06:00:00Z");
189+
assertEquals(expiration, level.getExpirationDate().toInstant());
142190
}
143191

144192
@Test
@@ -175,7 +223,7 @@ void testLevelAsTimeSeries() throws IOException {
175223
String collect = readJsonFile(resource);
176224
mockHttpServer.enqueue(collect);
177225
mockHttpServer.start();
178-
LocationLevel locationLevel = RadarObjectMapper.mapJsonToObject(collect, LocationLevel.class);
226+
LocationLevel locationLevel = RadarObjectMapper.mapJsonToObject(collect, TimeSeriesLocationLevel.class);
179227
Instant begin = Instant.parse("2023-06-01T07:00:00Z");
180228
Instant end = Instant.parse("2023-06-11T07:00:00Z");
181229
String unit = locationLevel.getLevelUnitsId();

cwms-data-api-client/src/test/resources/radar/v2/json/location_level.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"constant-value": 145.6944,
88
"level-units-id": "m",
99
"level-date": "1900-01-01T06:00:00Z",
10-
"duration-id": "0"
10+
"duration-id": "0",
11+
"expiration-date": "2900-01-01T06:00:00Z"
1112
}

cwms-data-api-client/src/test/resources/radar/v2/json/location_levels.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,54 @@
11021102
"level-units-id": "m3",
11031103
"level-date": "1900-01-01T05:00:00Z",
11041104
"duration-id": "0"
1105+
},
1106+
{
1107+
"office-id": "SPK",
1108+
"location-level-id": "virtual_level_value_2.Stor.Ave.1Day.Regulating",
1109+
"level-units-id": "ac-ft",
1110+
"level-date": "2023-06-01T00:00:00-07:00",
1111+
"expiration-date": 1685689200000,
1112+
"constituents": [
1113+
{
1114+
"type": "LOCATION_LEVEL",
1115+
"abbr": "L1",
1116+
"name": "level_get_all_loc3.Stage.Ave.1Day.Regulating",
1117+
"attribute-id": "Stage",
1118+
"attribute-value": 8.99
1119+
},
1120+
{
1121+
"type": "RATING",
1122+
"abbr": "R1",
1123+
"name": "LevelsControllerTestIT.Stage;Flow.COE.Production"
1124+
}
1125+
],
1126+
"constituent-connections": "L1=R1I1"
1127+
},
1128+
{
1129+
"seasonal-values": [
1130+
{
1131+
"value": 10,
1132+
"offset-minutes": 0,
1133+
"offset-months": 0
1134+
}
1135+
],
1136+
"level-units-id": "ft",
1137+
"level-date": "2008-12-03T10:15:30+01:00[UTC]",
1138+
"level-comment": "for testing purposes",
1139+
"interval-origin": "2008-12-03T10:15:30+01:00[UTC]",
1140+
"interval-months": 1,
1141+
"interpolate-string": "false",
1142+
"location-level-id": "LOC_TEST.Elev.Inst.0.Bottom of Inlet",
1143+
"office-id": "LRL"
1144+
},
1145+
{
1146+
"seasonal-time-series-id": "RYAN3.Stage.Inst.5Minutes.0.ZSTORE_TS_TEST630",
1147+
"level-units-id": "ft",
1148+
"level-date": "2008-12-03T10:15:30+01:00[UTC]",
1149+
"level-comment": "for testing purposes",
1150+
"interpolate-string": "false",
1151+
"location-level-id": "LOC_TEST.Elev.Inst.0.Bottom of Inlet",
1152+
"office-id": "LRL"
11051153
}
11061154
]
11071155
}

0 commit comments

Comments
 (0)