Skip to content

Commit b9dd092

Browse files
authored
bug fixes found testing REGI against SWT db export (#1527)
- fix openapi for location kind endpoint return type - fix issues where parameterized connection was getting the office id session set, but then a separate configuration was used for the jOOQ call (I tried to do an audit and catch as many errors as I could) - add null checks for outlet/turbine child location retrieval objects - fix null pointers on water contract effective/expiration dates - null check and ignore "CWMS" office ids for session variables - fix time series vert datum retrieval trying to convert units to "SI" or "EN"
1 parent 9d4268c commit b9dd092

18 files changed

Lines changed: 94 additions & 66 deletions

cwms-data-api/src/main/java/cwms/cda/api/LocationKindController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public LocationKindController(MetricRegistry metrics) {
8484
responses = {
8585
@OpenApiResponse(status = STATUS_200,
8686
content = {
87-
@OpenApiContent(isArray = true, type = Formats.JSONV2, from = Location.class),
87+
@OpenApiContent(isArray = true, type = Formats.JSONV1, from = CwmsIdLocationKind.class),
8888
})
8989
},
9090
description = "Returns CWMS Location Data. The Catalog end-point is also capable of "
@@ -103,9 +103,9 @@ public void handle(@NotNull Context ctx) {
103103
String kindRegexMask = ctx.queryParam(LOCATION_KIND_LIKE);
104104
String office = ctx.queryParam(OFFICE);
105105

106-
String formatParm = ctx.queryParamAsClass(Formats.JSONV2, String.class).getOrDefault("");
106+
String formatParm = ctx.queryParamAsClass(Formats.JSONV1, String.class).getOrDefault("");
107107
String formatHeader = ctx.header(Header.ACCEPT);
108-
ContentType contentType = Formats.parseHeaderAndQueryParm(formatHeader, formatParm, Location.class);
108+
ContentType contentType = Formats.parseHeaderAndQueryParm(formatHeader, formatParm, CwmsIdLocationKind.class);
109109

110110
String results;
111111

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,18 @@ public static int versionAsInteger(String version) {
102102
* Sets session office on specific connection.
103103
* @param c opened connection
104104
* @param object Data containing a valid CWMS office
105-
* @throws SQLException if the underlying database throws an exception
106105
*/
107-
protected void setOffice(Connection c, CwmsDTO object) throws SQLException {
108-
this.setOffice(c,object.getOfficeId());
106+
protected void setOffice(Connection c, CwmsDTO object) {
107+
setOffice(c,object.getOfficeId());
109108
}
110109

111-
protected void setOffice(Connection c, String office) throws SQLException {
112-
CWMS_ENV_PACKAGE.call_SET_SESSION_OFFICE_ID(DSL.using(c).configuration(), office);
110+
protected static void setOffice(Connection c, String office) {
111+
//null office id is invalid for the session office, the client may send null if looking for data across all offices
112+
//CWMS is not a valid session office id and maybe be parameterized from the client when
113+
//searching for CWMS-owned data.
114+
if(office != null && !"CWMS".equals(office)) {
115+
CWMS_ENV_PACKAGE.call_SET_SESSION_OFFICE_ID(DSL.using(c).configuration(), office);
116+
}
113117
}
114118

115119
public abstract Optional<T> getByUniqueName(String uniqueName, String office);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ public static DSLContext getDslContext(Connection connection, String officeId) {
176176
// This method should probably be called from within a connection{ } block and jOOQ
177177
// code within the block should use the returned DSLContext or the connection.
178178
DSLContext dsl = DSL.using(connection, SQLDialect.ORACLE18C);
179-
CWMS_ENV_PACKAGE.call_SET_SESSION_OFFICE_ID(dsl.configuration(), officeId);
180-
179+
setOffice(connection, officeId);
181180
return dsl;
182181
}
183182

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,15 @@ private boolean shouldFetchVerticalDatum(String parmPart) {
554554
private VerticalDatumInfo fetchVerticalDatumInfoSeparately(String locPart, String units, String office) {
555555

556556
return connectionResult(dsl, conn -> {
557+
String datumUnits = units;
558+
if ("SI".equalsIgnoreCase(datumUnits)) {
559+
datumUnits = "m";
560+
} else if ("EN".equalsIgnoreCase(datumUnits)) {
561+
datumUnits = "ft";
562+
}
557563
DSLContext dslContext = getDslContext(conn, office);
558564
String result = CWMS_LOC_PACKAGE.call_GET_VERTICAL_DATUM_INFO_F__2(dslContext.configuration(),
559-
locPart, units, office);
565+
locPart, datumUnits, office);
560566
return parseVerticalDatumInfo(result);
561567
});
562568
}

cwms-data-api/src/main/java/cwms/cda/data/dao/basinconnectivity/StreamDao.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public Stream getStream(String streamId, String unitSystem, String officeId) {
2828
Unit.KILOMETER.getValue();
2929

3030
return connectionResult(dsl, c -> {
31-
RETRIEVE_STREAM stream = CWMS_STREAM_PACKAGE.call_RETRIEVE_STREAM(dsl.configuration(), streamId, pStationUnit, officeId);
31+
var configuration = getDslContext(c, officeId).configuration();
32+
RETRIEVE_STREAM stream = CWMS_STREAM_PACKAGE.call_RETRIEVE_STREAM(configuration, streamId, pStationUnit, officeId);
3233
return new Stream.Builder(streamId, parseBool(stream.getP_STATIONING_STARTS_DS()),
3334
stream.getP_LENGTH(), officeId)
3435
.withDivertingStreamId(stream.getP_DIVERTS_FROM_STREAM())
@@ -62,7 +63,8 @@ private Set<Stream> getTributaries(String streamId, String unitSystem, String of
6263
return connectionResult(dsl, c -> {
6364
String pStationUnit = UnitSystem.EN.value().equals(unitSystem)
6465
? Unit.MILE.getValue() : Unit.KILOMETER.getValue();
65-
Result<Record> rs = CWMS_STREAM_PACKAGE.call_CAT_STREAMS(dsl.configuration(), null, pStationUnit, null, null,
66+
var configuration = getDslContext(c, officeId).configuration();
67+
Result<Record> rs = CWMS_STREAM_PACKAGE.call_CAT_STREAMS(configuration, null, pStationUnit, null, null,
6668
null, null, null, null, null, null, null,
6769
null, null, null, null, null, officeId);
6870
return buildStreamsFromResultSet(rs.intoResultSet(), streamId, unitSystem);

cwms-data-api/src/main/java/cwms/cda/data/dao/basinconnectivity/StreamLocationDao.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public Set<StreamLocation> getStreamLocations(String streamId, String unitSystem
3434
? Unit.SQUARE_MILES.getValue() : Unit.SQUARE_KILOMETERS.getValue();
3535

3636
return connectionResult(dsl, c -> {
37-
Result<Record> rs = CWMS_STREAM_PACKAGE.call_CAT_STREAM_LOCATIONS(dsl.configuration(), pStreamIdMaskIn,
37+
var configuration = getDslContext(c, officeId).configuration();
38+
Result<Record> rs = CWMS_STREAM_PACKAGE.call_CAT_STREAM_LOCATIONS(configuration, pStreamIdMaskIn,
3839
pLocationIdMaskIn, pStationUnitIn, pStageUnitIn, pAreaUnitIn, officeId);
3940
return buildStreamLocations(rs.intoResultSet());
4041
});

cwms-data-api/src/main/java/cwms/cda/data/dao/basinconnectivity/StreamReachDao.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public Set<StreamReach> getReachesOnStream(String streamId, String officeId) {
2222
String pStationUnitIn = Unit.KILOMETER.getValue();
2323

2424
return connectionResult(dsl, c -> {
25-
Result<Record> rs = CWMS_STREAM_PACKAGE.call_CAT_STREAM_REACHES(dsl.configuration(), streamId,
25+
var configuration = getDslContext(c, officeId).configuration();
26+
Result<Record> rs = CWMS_STREAM_PACKAGE.call_CAT_STREAM_REACHES(configuration, streamId,
2627
null, null, null, pStationUnitIn, officeId);
2728
return buildReachesFromResultSet(rs.intoResultSet());
2829
});

cwms-data-api/src/main/java/cwms/cda/data/dao/location/kind/LockDao.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,23 @@ public LockDao(DSLContext dsl) {
5555

5656
public List<Lock> retrieveLockCatalog(CwmsId projectId) {
5757
return connectionResult(dsl, c -> {
58-
setOffice(c, projectId.getOfficeId());
59-
Result<Record> catalogResults = CWMS_LOCK_PACKAGE.call_CAT_LOCK(dsl.configuration(),
58+
var configuration = getDslContext(c, projectId.getOfficeId()).configuration();
59+
Result<Record> catalogResults = CWMS_LOCK_PACKAGE.call_CAT_LOCK(configuration,
6060
projectId.getName(), projectId.getOfficeId());
6161
return catalogResults.stream().map(LockDao::catMap).collect(toList());
6262
});
6363
}
6464

6565
public Lock retrieveLock(CwmsId lockId, UnitSystem unitSystem) {
6666
return connectionResult(dsl, c -> {
67-
setOffice(c, lockId.getOfficeId());
67+
var configuration = getDslContext(c, lockId.getOfficeId()).configuration();
6868
LOCATION_REF_T locationRef = getLocationRef(CwmsId.buildCwmsId(lockId.getOfficeId(),
6969
lockId.getName()));
7070
Lock retVal;
7171
if (unitSystem.equals(UnitSystem.EN)) {
72-
retVal = unitConvertToEN(map(CWMS_LOCK_PACKAGE.call_RETRIEVE_LOCK(dsl.configuration(), locationRef)));
72+
retVal = unitConvertToEN(map(CWMS_LOCK_PACKAGE.call_RETRIEVE_LOCK(configuration, locationRef)));
7373
} else {
74-
retVal = map(CWMS_LOCK_PACKAGE.call_RETRIEVE_LOCK(dsl.configuration(), locationRef));
74+
retVal = map(CWMS_LOCK_PACKAGE.call_RETRIEVE_LOCK(configuration, locationRef));
7575
}
7676
if (retVal == null) {
7777
throw new NotFoundException("Lock not found: " + lockId);
@@ -228,44 +228,43 @@ static String mapToLockRef(String office, String locationName) {
228228

229229
Lock unitConvertToEN(Lock lock) {
230230
return connectionResult(dsl, c -> {
231-
setOffice(c, lock.getLocation().getOfficeId());
232-
233-
String length = CWMS_UTIL_PACKAGE.call_GET_DEFAULT_UNITS(dsl.configuration(), "Length", "EN");
234-
String volume = CWMS_UTIL_PACKAGE.call_GET_DEFAULT_UNITS(dsl.configuration(), "Volume", "EN");
231+
var configuration = getDslContext(c, lock.getLocation().getOfficeId()).configuration();
232+
String length = CWMS_UTIL_PACKAGE.call_GET_DEFAULT_UNITS(configuration, "Length", "EN");
233+
String volume = CWMS_UTIL_PACKAGE.call_GET_DEFAULT_UNITS(configuration, "Volume", "EN");
235234
return new Lock.Builder()
236235
.withElevationUnits(length)
237236
.withVolumeUnits(volume)
238237
.withLengthUnits(length)
239238
.withLocation(lock.getLocation())
240239
.withProjectId(lock.getProjectId())
241-
.withLockWidth(CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(dsl.configuration(), lock.getLockWidth(),
240+
.withLockWidth(CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(configuration, lock.getLockWidth(),
242241
lock.getLengthUnits(), length))
243-
.withLockLength(CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(dsl.configuration(), lock.getLockLength(),
242+
.withLockLength(CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(configuration, lock.getLockLength(),
244243
lock.getLengthUnits(), length))
245-
.withNormalLockLift(CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(dsl.configuration(), lock.getNormalLockLift(),
244+
.withNormalLockLift(CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(configuration, lock.getNormalLockLift(),
246245
lock.getLengthUnits(), length))
247-
.withVolumePerLockage(CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(dsl.configuration(),
246+
.withVolumePerLockage(CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(configuration,
248247
lock.getVolumePerLockage(), lock.getVolumeUnits(), volume))
249-
.withMinimumDraft(CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(dsl.configuration(), lock.getMinimumDraft(),
248+
.withMinimumDraft(CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(configuration, lock.getMinimumDraft(),
250249
lock.getElevationUnits(), length))
251-
.withHighWaterLowerPoolWarningLevel(CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(dsl.configuration(),
250+
.withHighWaterLowerPoolWarningLevel(CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(configuration,
252251
lock.getHighWaterLowerPoolWarningLevel(), lock.getElevationUnits(), length))
253-
.withHighWaterUpperPoolWarningLevel(CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(dsl.configuration(),
252+
.withHighWaterUpperPoolWarningLevel(CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(configuration,
254253
lock.getHighWaterUpperPoolWarningLevel(), lock.getElevationUnits(), length))
255254
.withChamberType(lock.getChamberType())
256255
.withHighWaterLowerPoolLocationLevel(new LockLocationLevelRef(lock.getHighWaterLowerPoolLocationLevel().getLevelLink(),
257-
CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(dsl.configuration(), lock.getHighWaterLowerPoolLocationLevel().getLevelValue(),
256+
CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(configuration, lock.getHighWaterLowerPoolLocationLevel().getLevelValue(),
258257
lock.getElevationUnits(), length)))
259258
.withHighWaterUpperPoolLocationLevel(new LockLocationLevelRef(lock.getHighWaterUpperPoolLocationLevel().getLevelLink(),
260-
CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(dsl.configuration(), lock.getHighWaterUpperPoolLocationLevel().getLevelValue(),
259+
CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(configuration, lock.getHighWaterUpperPoolLocationLevel().getLevelValue(),
261260
lock.getElevationUnits(), length)))
262261
.withLowWaterLowerPoolLocationLevel(new LockLocationLevelRef(lock.getLowWaterLowerPoolLocationLevel().getLevelLink(),
263-
CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(dsl.configuration(), lock.getLowWaterLowerPoolLocationLevel().getLevelValue(),
262+
CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(configuration, lock.getLowWaterLowerPoolLocationLevel().getLevelValue(),
264263
lock.getElevationUnits(), length)))
265264
.withLowWaterUpperPoolLocationLevel(new LockLocationLevelRef(lock.getLowWaterUpperPoolLocationLevel().getLevelLink(),
266-
CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(dsl.configuration(), lock.getLowWaterUpperPoolLocationLevel().getLevelValue(),
265+
CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(configuration, lock.getLowWaterUpperPoolLocationLevel().getLevelValue(),
267266
lock.getElevationUnits(), length)))
268-
.withMaximumLockLift(CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(dsl.configuration(), lock.getMaximumLockLift(),
267+
.withMaximumLockLift(CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(configuration, lock.getMaximumLockLift(),
269268
lock.getElevationUnits(), length))
270269
.build();
271270
});

cwms-data-api/src/main/java/cwms/cda/data/dao/location/kind/OutletDao.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,15 @@ public List<Outlet> retrieveOutletsForProject(String officeId, String projectId)
7676

7777
LocationGroupDao locGroupDao = new LocationGroupDao(dsl);
7878
List<LocationGroup> groups = locGroupDao.getLocationGroups(config, null, officeId,
79-
null, Outlet.RATING_LOC_GROUP_CATEGORY, projectId);
80-
81-
return CWMS_OUTLET_PACKAGE.call_RETRIEVE_OUTLETS(config, locRef)
82-
.stream()
83-
.map(struct -> mapToOutlet(struct, groups))
84-
.collect(Collectors.toList());
79+
null, Outlet.RATING_LOC_GROUP_CATEGORY, projectId);
80+
var outlets = CWMS_OUTLET_PACKAGE.call_RETRIEVE_OUTLETS(config, locRef);
81+
if(outlets == null)
82+
{
83+
return List.of();
84+
}
85+
return outlets.stream()
86+
.map(struct -> mapToOutlet(struct, groups))
87+
.collect(Collectors.toList());
8588
});
8689
}
8790

cwms-data-api/src/main/java/cwms/cda/data/dao/location/kind/TurbineDao.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ public TurbineDao(DSLContext dsl) {
6262
public List<Turbine> retrieveTurbines(String projectLocationId, String officeId) {
6363
return connectionResult(dsl, conn -> {
6464
LOCATION_REF_T locationRefT = getLocationRef(projectLocationId, officeId);
65-
return CWMS_TURBINE_PACKAGE.call_RETRIEVE_TURBINES(DSL.using(conn).configuration(), locationRefT)
66-
.stream()
65+
var configuration = DSL.using(conn).configuration();
66+
var projectStructureObjTs = CWMS_TURBINE_PACKAGE.call_RETRIEVE_TURBINES(configuration, locationRefT);
67+
if(projectStructureObjTs == null)
68+
{
69+
return List.of();
70+
}
71+
return projectStructureObjTs.stream()
6772
.map(TurbineDao::map)
6873
.collect(toList());
6974
});

0 commit comments

Comments
 (0)