Skip to content

Commit 44a43e7

Browse files
committed
Updated constituent handling, tests in progress
1 parent 6ebe7e0 commit 44a43e7

File tree

6 files changed

+192
-31
lines changed

6 files changed

+192
-31
lines changed

cwms-data-api/src/main/java/cwms/cda/data/dao/LocationLevelsDaoImpl.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ public void storeVirtualLocationLevel(VirtualLocationLevel locationLevel) {
330330
Timestamp date = Timestamp.from(locationLevel.getLevelDate().toInstant());
331331
Timestamp expirationDate = Timestamp.from(locationLevel.getExpirationDate().toInstant());
332332
STR_TAB_TAB_T constituentTab = new STR_TAB_TAB_T();
333-
for (String constituent : locationLevel.getConstituents()) {
334-
constituentTab.add(new STR_TAB_T(constituent));
333+
for (VirtualLocationLevel.Constituent constituent : locationLevel.getConstituents()) {
334+
constituentTab.add(new STR_TAB_T(constituent.getConstituentList()));
335335
}
336336
connection(dsl, c -> {
337337
String officeId = locationLevel.getOfficeId();
@@ -527,10 +527,23 @@ public VirtualLocationLevel retrieveVirtualLocationLevel(String locationLevelNam
527527
Timestamp pEffectiveDate = level.getLEVEL_DATE();
528528
ZonedDateTime realEffectiveDate = ZonedDateTime.ofInstant(pEffectiveDate.toInstant(), effectiveDate.getZone());
529529
ZonedDateTime expirationDate = ZonedDateTime.ofInstant(level.getEXPIRATION_DATE().toInstant(), effectiveDate.getZone());
530-
List<String> constituents = new ArrayList<>();
530+
List<VirtualLocationLevel.Constituent> constituents = new ArrayList<>();
531531
STR_TAB_TAB_T constituentTab = level.getCONSTITUENTS();
532532
if (constituentTab != null) {
533-
constituentTab.forEach(constituent -> constituents.add(constituent.get(0)));
533+
constituentTab.forEach(constituent -> {
534+
VirtualLocationLevel.Constituent.Builder constituentBuilder = new VirtualLocationLevel.Constituent.Builder(constituent.get(0), constituent.get(1), constituent.get(2));
535+
if (constituent.get(3) != null) {
536+
constituentBuilder.withAttributeId(constituent.get(3));
537+
}
538+
if (constituent.get(4) != null) {
539+
constituentBuilder.withAttributeValue(Double.valueOf(constituent.get(4)));
540+
}
541+
if (constituent.get(5) != null) {
542+
constituentBuilder.withAttributeUnits(constituent.get(5));
543+
}
544+
545+
constituents.add(constituentBuilder.build());
546+
});
534547
}
535548
return new VirtualLocationLevel.Builder(locationLevelName, realEffectiveDate)
536549
.withConstituents(constituents)

cwms-data-api/src/main/java/cwms/cda/data/dto/VirtualLocationLevel.java

Lines changed: 127 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@
5858
@FormattableWith(contentType = Formats.JSONV2, formatter = JsonV2.class, aliases = {Formats.DEFAULT, Formats.JSON})
5959
@FormattableWith(contentType = Formats.JSONV1, formatter = JsonV1.class)
6060
@FormattableWith(contentType = Formats.XMLV2, formatter = XMLv2.class, aliases = {Formats.XML})
61-
public class VirtualLocationLevel extends LocationLevel {
61+
public final class VirtualLocationLevel extends LocationLevel {
6262
private final ZonedDateTime expirationDate;
6363

64-
private final List<String> constituents;
64+
private final List<Constituent> constituents;
6565

6666
private final String constituentConnections;
6767

@@ -77,7 +77,7 @@ public ZonedDateTime getExpirationDate()
7777
return expirationDate;
7878
}
7979

80-
public List<String> getConstituents()
80+
public List<Constituent> getConstituents()
8181
{
8282
return constituents;
8383
}
@@ -89,10 +89,10 @@ public String getConstituentConnections()
8989

9090
@JsonPOJOBuilder
9191
@JsonNaming(PropertyNamingStrategies.KebabCaseStrategy.class)
92-
public static class Builder extends LocationLevel.Builder
92+
public static final class Builder extends LocationLevel.Builder
9393
{
9494
private ZonedDateTime expirationDate;
95-
private List<String> constituents;
95+
private List<Constituent> constituents;
9696
private String constituentConnections;
9797

9898
@JsonCreator
@@ -106,7 +106,7 @@ public Builder withExpirationDate(ZonedDateTime expirationDate) {
106106
return this;
107107
}
108108

109-
public Builder withConstituents(List<String> constituents) {
109+
public Builder withConstituents(List<Constituent> constituents) {
110110
this.constituents = constituents;
111111
return this;
112112
}
@@ -308,4 +308,125 @@ public VirtualLocationLevel build()
308308
return new VirtualLocationLevel(this);
309309
}
310310
}
311+
312+
@JsonPOJOBuilder
313+
@JsonNaming(PropertyNamingStrategies.KebabCaseStrategy.class)
314+
@JsonDeserialize(builder = Constituent.Builder.class)
315+
@FormattableWith(contentType = Formats.JSONV2, formatter = JsonV2.class, aliases = {Formats.DEFAULT, Formats.JSON})
316+
public static final class Constituent
317+
{
318+
private final String abbr;
319+
private final String type;
320+
private final String name;
321+
private final String attributeId;
322+
private final Double attributeValue;
323+
private final String attributeUnits;
324+
325+
private Constituent(Builder builder)
326+
{
327+
this.abbr = builder.abbr;
328+
this.type = builder.type;
329+
this.name = builder.name;
330+
this.attributeId = builder.attributeId;
331+
this.attributeValue = builder.attributeValue;
332+
this.attributeUnits = builder.attributeUnits;
333+
}
334+
335+
public String getAbbr()
336+
{
337+
return abbr;
338+
}
339+
340+
public String getType()
341+
{
342+
return type;
343+
}
344+
345+
public String getName()
346+
{
347+
return name;
348+
}
349+
350+
public String getAttributeId()
351+
{
352+
return attributeId;
353+
}
354+
355+
public Double getAttributeValue()
356+
{
357+
return attributeValue;
358+
}
359+
360+
public String getAttributeUnits()
361+
{
362+
return attributeUnits;
363+
}
364+
365+
public List<String> getConstituentList()
366+
{
367+
List<String> retVal = new ArrayList<>();
368+
retVal.add(abbr);
369+
retVal.add(type);
370+
retVal.add(name);
371+
if(attributeId != null)
372+
{
373+
retVal.add(attributeId);
374+
}
375+
if(attributeValue != null)
376+
{
377+
retVal.add(attributeValue.toString());
378+
}
379+
if(attributeUnits != null)
380+
{
381+
retVal.add(attributeUnits);
382+
}
383+
return retVal;
384+
}
385+
386+
@JsonPOJOBuilder
387+
@JsonNaming(PropertyNamingStrategies.KebabCaseStrategy.class)
388+
@JsonInclude(JsonInclude.Include.NON_NULL)
389+
public static final class Builder
390+
{
391+
private final String abbr;
392+
private final String type;
393+
private final String name;
394+
private String attributeId;
395+
private Double attributeValue;
396+
private String attributeUnits;
397+
398+
@JsonCreator
399+
public Builder(@JsonProperty(value = "abbr", required = true) String abbr,
400+
@JsonProperty(value = "type", required = true) String type,
401+
@JsonProperty(value = "name", required = true) String name)
402+
{
403+
this.abbr = abbr;
404+
this.type = type;
405+
this.name = name;
406+
}
407+
408+
public Builder withAttributeId(String constituentAttributeId)
409+
{
410+
this.attributeId = constituentAttributeId;
411+
return this;
412+
}
413+
414+
public Builder withAttributeValue(Double constituentAttributeValue)
415+
{
416+
this.attributeValue = constituentAttributeValue;
417+
return this;
418+
}
419+
420+
public Builder withAttributeUnits(String constituentAttributeUnits)
421+
{
422+
this.attributeUnits = constituentAttributeUnits;
423+
return this;
424+
}
425+
426+
public Constituent build()
427+
{
428+
return new Constituent(this);
429+
}
430+
}
431+
}
311432
}

cwms-data-api/src/test/java/cwms/cda/api/LevelsControllerTestIT.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import cwms.cda.data.dao.LocationLevelsDaoImpl;
2828
import cwms.cda.data.dto.LocationLevel;
29-
import cwms.cda.data.dto.SeasonalValueBean;
3029
import cwms.cda.data.dto.TimeSeries;
3130
import cwms.cda.formatters.Formats;
3231
import fixtures.CwmsDataApiSetupCallback;
@@ -43,7 +42,6 @@
4342
import org.junit.jupiter.params.provider.EnumSource;
4443

4544
import javax.servlet.http.HttpServletResponse;
46-
import java.math.BigInteger;
4745
import java.time.Instant;
4846
import java.time.ZoneId;
4947
import java.time.ZonedDateTime;
@@ -743,14 +741,6 @@ void testStoreRetrieveVirtualLevels() throws Exception
743741
createLocation("virtual_level_value", true, OFFICE);
744742
String levelId = "virtual_level_value.Stor.Ave.1Day.Regulating";
745743
ZonedDateTime time = ZonedDateTime.of(2023, 6, 1, 0, 0, 0, 0, ZoneId.of("America/Los_Angeles"));
746-
List<String> constituents = new ArrayList<>();
747-
constituents.add("level_get_all_loc1.Stor.Ave.1Day.Regulating");
748-
LocationLevel level = new LocationLevel.Builder(levelId, time)
749-
.withOfficeId(OFFICE)
750-
.withConstantValue(1.0)
751-
.withLevelUnitsId("ac-ft")
752-
.withSeasonalValue(new SeasonalValueBean.Builder().withValue(12.0).withOffsetMinutes(BigInteger.ONE).build())
753-
.build();
754744
String levelJson = readResourceFile("cwms/cda/api/virtuallevels/virtual_level_1.json");
755745

756746
// Store the virtual level
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
{
22
"office-id" : "SPK",
33
"location-level-id" : "virtual_level_value.Stor.Ave.1Day.Regulating",
4-
"constant-value" : 1.0,
4+
"constant-value" : 10.0,
55
"level-units-id" : "ac-ft",
66
"level-date" : "2023-06-01T00:00:00-07:00",
77
"expiration-date" : 1685689200000,
8-
"constituents" : [ "level_get_all_loc1.Stor.Ave.1Day.Regulating" ]
8+
"constituents" : [
9+
{
10+
"abbr": "LOC1",
11+
"type": "LOCATION_LEVEL",
12+
"name": "level_get_all_loc1"
13+
},
14+
{
15+
"abbr": "LOC2",
16+
"type": "LOCATION_LEVEL",
17+
"name": "level_get_all_loc2"
18+
}
19+
],
20+
"constituent-connections": "virt=LOC1,virt=LOC2"
921
}
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
{
22
"office-id" : "SPK",
33
"location-level-id" : "virtual_level_value_1.Stor.Ave.1Day.Regulating",
4-
"constant-value" : 1.0,
54
"level-units-id" : "ac-ft",
65
"level-date" : "2023-06-01T00:00:00-07:00",
76
"expiration-date" : 1685689200000,
8-
"constituents" : [ "virtual_level_value.Stor.Ave.1Day.Regulating" ],
9-
"seasonal-values": [
10-
11-
]
7+
"constituents" : [
8+
{
9+
"abbr": "virt_lev2",
10+
"type": "virtual_level",
11+
"name": "virtual_level_value.Stor.Ave.1Day.Regulating"
12+
}
13+
],
14+
"seasonal-values" : [ {
15+
"value" : 12.0,
16+
"offset-minutes" : 1
17+
} ],
18+
"constituent-connections": "virtual_level_value.Stor.Ave.1Day.Regulating"
1219
}
Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
{
22
"office-id" : "SPK",
33
"location-level-id" : "virtual_level_value_2.Stor.Ave.1Day.Regulating",
4-
"constant-value" : 1.0,
54
"level-units-id" : "ac-ft",
65
"level-date" : "2023-06-01T00:00:00-07:00",
76
"expiration-date" : 1685689200000,
8-
"constituents" : [ "virtual_level_value_1.Stor.Ave.1Day.Regulating" ],
9-
"seasonal-values": [
10-
7+
"constituents" : [
8+
{
9+
"abbr": "virt_lev1",
10+
"type": "virtual_level",
11+
"name": "level_get_all_loc1.Stor.Ave.1Day.Regulating"
12+
},
13+
{
14+
"abbr": "virt_lev2",
15+
"type": "virtual_level",
16+
"name": "virtual_level_value_1.Stor.Ave.1Day.Regulating"
17+
}
18+
],
19+
"constituent-connections": "virtual_level_value.Stor.Ave.1Day.Regulating",
20+
"seasonal-values" : [
21+
{
22+
"value" : 12.0,
23+
"offset-minutes" : 1
24+
},
25+
{
26+
"value" : 24.0,
27+
"offset-minutes" : 2
28+
}
1129
]
1230
}

0 commit comments

Comments
 (0)