Skip to content

Commit 8ffecfa

Browse files
EnovotnyEric Novotny
andauthored
bugfix/1675-locations-endpoint-returning-empty-list (#1702)
The getLocations() method was always returning an empty list when no datum parameter was provided. The code created an empty finalizedResults list and only populated it when datum was not null, then always returned finalizedResults. Instead, return the fetched results directly when datum is null/blank, and only perform datum conversion when necessary. --------- Co-authored-by: Eric Novotny <nov00002@umn.edu>
1 parent 5cf708a commit 8ffecfa

3 files changed

Lines changed: 35 additions & 7 deletions

File tree

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,14 @@ public List<Location> getLocations(String nameRegex, String unitSystem, String d
142142
.fetchSize(DEFAULT_SMALL_FETCH_SIZE)
143143
.fetch(this::buildLocation);
144144

145+
if (datum == null || datum.isBlank()) {
146+
return results;
147+
}
148+
145149
List<Location> finalizedResults = new ArrayList<>();
146-
if (datum != null && !datum.isBlank()) {
147-
for(Location loc : results) {
148-
loc = convertLocationToVerticalDatum(dslContext, loc, datum, officeId);
149-
finalizedResults.add(loc);
150-
}
150+
for(Location loc : results) {
151+
loc = convertLocationToVerticalDatum(dslContext, loc, datum, officeId);
152+
finalizedResults.add(loc);
151153
}
152154
return finalizedResults;
153155
});

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,32 @@ void test_get_all_locations_legacy_types(GetAllLegacyTest test)
819819
.contentType(is(test._expectedContentType));
820820
}
821821

822+
@Test
823+
void test_get_all_locations_without_datum_returns_results() throws Exception {
824+
String locationName = "TestLocNoDatum";
825+
KeyUser user = KeyUser.SPK_NORMAL;
826+
String officeId = user.getOperatingOffice();
827+
828+
createLocation(locationName, true, officeId, 38.5757, -121.4789, "WGS84", "UTC", "SITE");
829+
830+
given()
831+
.log().ifValidationFails(LogDetail.ALL, true)
832+
.accept(Formats.JSONV2)
833+
.queryParam(OFFICE, officeId)
834+
.queryParam(NAMES, locationName)
835+
.when()
836+
.redirects().follow(true)
837+
.redirects().max(3)
838+
.get("/locations/")
839+
.then()
840+
.log().ifValidationFails(LogDetail.ALL, true)
841+
.assertThat()
842+
.statusCode(is(HttpServletResponse.SC_OK))
843+
.body("size()", is(1))
844+
.body("[0].name", equalTo(locationName))
845+
;
846+
}
847+
822848
enum GetAllLegacyTest
823849
{
824850
JSON(Formats.JSON_LEGACY, Formats.JSON),

cwms-data-api/src/test/resources/cwms/cda/data/timeseries.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,11 @@ LRL,Mississinewa.Temp-Air.Max.1Day.1Day.lrldlb-raw,T,Mississinewa,null,null,m,nu
275275
LRL,Mississinewa.Temp-Air.Max.1Day.1Day.lrldlb-raw,T,Mississinewa,Corps Reservoir,712.0,ft,NGVD29,40.7166667,-85.9580556,NAD27,MississinewaLake,MississinewaLake,null,US/Eastern,Miami,IN
276276
LRL,Mississinewa.Temp-Air.Max.1Day.1Day.lrldlb-raw,T,Mississinewa,Corps Reservoir,217.01760000000002,m,NGVD29,40.7166667,-85.9580556,NAD27,MississinewaLake,MississinewaLake,null,US/Eastern,Miami,IN
277277
LRL,Monroe.Temp-Water.Inst.0.0.lrldlb-rev,T,Monroe,null,null,m,null,39.007222222222,-86.513333333333,null,MONROE LAKE NEAR HARRODSBURG,MONROE LAKE NEAR HARRODSBURG,MONROE LAKE NEAR HARRODSBURG,UTC,Monroe,IN
278-
LRL,Monroe.Temp-Water.Inst.0.0.lrldlb-rev,T,Monroe,null,null,m,null,null,null,null,Monroe,null,null,null,Unknown County or County N/A,00
278+
LRL,Monroe.Temp-Water.Inst.0.0.lrldlb-rev,T,Monroe,null,null,m,null,null,null,null,Monroe,null,null,null,Unknown County or County N/A,IN
279279
LRL,Monroe.Temp-Water.Inst.0.0.lrldlb-rev,T,Monroe,Corps Reservoir,538.0,ft,NGVD29,39.0075,-86.5125,NAD27,Monroe Lake,MonroeLake,null,US/Eastern,Monroe,IN
280280
LRL,Monroe.Temp-Water.Inst.0.0.lrldlb-rev,T,Monroe,null,null,ft,null,41.94,-83.44,null,Monroe Weather Station,null,null,US/Eastern,Monroe,MI
281281
LRL,Monroe.Temp-Water.Inst.0.0.lrldlb-rev,T,Monroe,null,null,ft,null,39.007222222222,-86.513333333333,null,MONROE LAKE NEAR HARRODSBURG,MONROE LAKE NEAR HARRODSBURG,MONROE LAKE NEAR HARRODSBURG,UTC,Monroe,IN
282-
LRL,Monroe.Temp-Water.Inst.0.0.lrldlb-rev,T,Monroe,null,null,ft,null,null,null,null,Monroe,null,null,null,Unknown County or County N/A,00
282+
LRL,Monroe.Temp-Water.Inst.0.0.lrldlb-rev,T,Monroe,null,null,ft,null,null,null,null,Monroe,null,null,null,Unknown County or County N/A,IN
283283
LRL,Monroe.Temp-Water.Inst.0.0.lrldlb-rev,T,Monroe,Corps Reservoir,163.9824,m,NGVD29,39.0075,-86.5125,NAD27,Monroe Lake,MonroeLake,null,US/Eastern,Monroe,IN
284284
LRL,Monroe.Temp-Water.Inst.0.0.lrldlb-rev,T,Monroe,null,null,m,null,41.94,-83.44,null,Monroe Weather Station,null,null,US/Eastern,Monroe,MI
285285
LRL,MtCarmel.Precip.Inst.1Hour.0.LRGS-raw,T,MtCarmel,null,112.46510400000001,m,NAVD88,38.3983333,-87.75638889,NAD83,"WABASH RIVER AT MT. CARMEL, IL","WABASH RIVER AT MT. CARMEL, IL",null,US/Central,Wabash,IL

0 commit comments

Comments
 (0)