Skip to content

Commit

Permalink
Merge pull request #626 from rma-rripken/bugfix/477-locations
Browse files Browse the repository at this point in the history
Bugfix/477 locations
  • Loading branch information
rma-rripken authored May 17, 2024
2 parents f0bbc22 + 99fa632 commit ab37863
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 138 deletions.
24 changes: 14 additions & 10 deletions cwms-data-api/src/main/java/cwms/cda/api/BasinController.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ private Timer.Context markAndTime(String subject) {

@OpenApi(
queryParams = {
@OpenApiParam(name = OFFICE, required = false, description = "Specifies the"
@OpenApiParam(name = OFFICE, description = "Specifies the"
+ " owning office of the basin whose data is to be included in the "
+ "response. If this field is not specified, matching basin "
+ "information from all offices shall be returned."),
@OpenApiParam(name = UNIT, required = false, description = "Specifies the "
@OpenApiParam(name = UNIT, description = "Specifies the "
+ "unit or unit system of the response. Valid values for the unit "
+ "field are:\r\n 1. EN. Specifies English unit system. Basin "
+ "field are: "
+ "\n* `EN` Specifies English unit system. Basin "
+ "values will be in the default English units for their parameters. "
+ "(This is default if no value is entered)\r\n2. SI. Specifies the"
+ "(This is default if no value is entered)"
+ "\n* `SI` Specifies the"
+ " SI unit system. Basin values will be in the default SI units for "
+ "their parameters."),
},
Expand Down Expand Up @@ -107,16 +109,18 @@ public void getAll(@NotNull Context ctx) {

@OpenApi(
queryParams = {
@OpenApiParam(name = OFFICE, required = false, description = "Specifies the"
@OpenApiParam(name = OFFICE, description = "Specifies the"
+ " owning office of the basin whose data is to be included in the "
+ "response. If this field is not specified, matching basin "
+ "information from all offices shall be returned."),
@OpenApiParam(name = UNIT, required = false, description = "Specifies the "
@OpenApiParam(name = UNIT, description = "Specifies the "
+ "unit or unit system of the response. Valid values for the unit "
+ "field are:\r\n 1. EN. Specifies English unit system. Basin "
+ "values will be in the default English units for their parameters. "
+ "(This is default if no value is entered)\r\n2. SI. Specifies the"
+ " SI unit system. Basin values will be in the default SI units for "
+ "field are:"
+ "\n* `EN` Specifies English unit system. Basin values will be in "
+ "the default English units for their parameters. "
+ "(This is default if no value is entered)"
+ "\n* `SI` Specifies the SI unit system. Basin values will be in "
+ "the default SI units for "
+ "their parameters."),
},
responses = {
Expand Down
36 changes: 18 additions & 18 deletions cwms-data-api/src/main/java/cwms/cda/api/LevelsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,12 @@
import cwms.cda.data.dto.LocationLevel;
import cwms.cda.data.dto.LocationLevels;
import cwms.cda.data.dto.SeasonalValueBean;
import cwms.cda.data.dto.TimeSeries;
import cwms.cda.formatters.ContentType;
import cwms.cda.formatters.Formats;
import cwms.cda.formatters.FormattingException;
import cwms.cda.helpers.DateUtils;
import hec.data.level.JDomLocationLevelRef;
import io.javalin.apibuilder.CrudHandler;
import io.javalin.core.util.Header;
import io.javalin.core.validation.Validator;
import io.javalin.http.Context;
import io.javalin.http.HttpCode;
import io.javalin.http.HttpResponseException;
Expand All @@ -62,8 +59,6 @@
import io.javalin.plugin.openapi.annotations.OpenApiParam;
import io.javalin.plugin.openapi.annotations.OpenApiRequestBody;
import io.javalin.plugin.openapi.annotations.OpenApiResponse;
import mil.army.usace.hec.metadata.Interval;
import mil.army.usace.hec.metadata.IntervalFactory;
import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;

Expand Down Expand Up @@ -194,18 +189,23 @@ public void delete(@NotNull Context ctx, @NotNull String levelId) {
+ " response. If this field is not specified, matching location level "
+ "information from all offices shall be returned."),
@OpenApiParam(name = UNIT, description = "Specifies the unit or unit system"
+ " of the response. Valid values for the unit field are:\r\n 1. EN. "
+ " Specifies English unit system. Location level values will be in"
+ " the default English units for their parameters.\r\n2. SI. "
+ " of the response. Valid values for the unit field are:"
+ "\n* `EN` "
+ "Specifies English unit system. Location level values will be in"
+ " the default English units for their parameters."
+ "\n* `SI` "
+ "Specifies the SI unit system. Location level values will be in "
+ "the default SI units for their parameters.\r\n3. Other. Any unit "
+ "returned in the response to the units URI request that is "
+ "the default SI units for their parameters."
+ "\n* `Other` "
+ "Any unit returned in the response to the units URI request that is "
+ "appropriate for the requested parameters."),
@OpenApiParam(name = DATUM, description = "Specifies the elevation datum of"
+ " the response. This field affects only elevation location levels. "
+ "Valid values for this field are:\r\n1. NAVD88. The elevation "
+ "Valid values for this field are:"
+ "\n* `NAVD88` The elevation "
+ "values will in the specified or default units above the NAVD-88 "
+ "datum.\r\n2. NGVD29. The elevation values will be in the "
+ "datum."
+ "\n* `NGVD29` The elevation values will be in the "
+ "specified or default units above the NGVD-29 datum."),
@OpenApiParam(name = BEGIN, description = "Specifies the start of the time "
+ "window for data to be included in the response. If this field is "
Expand All @@ -222,12 +222,12 @@ public void delete(@NotNull Context ctx, @NotNull String levelId) {
@OpenApiParam(name = FORMAT, description = "Specifies the encoding format "
+ "of the response. Requests specifying an Accept header:"
+ Formats.JSONV2 + " must not include this field. "
+ "Valid format field values for this URI are:\r\n"
+ "1. tab\r\n"
+ "2. csv\r\n"
+ "3. xml\r\n"
+ "4. wml2 (only if name field is specified)\r\n"
+ "5. json (default)\r\n"),
+ "Valid format field values for this URI are:"
+ "\n* `tab`"
+ "\n* `csv`"
+ "\n* `xml`"
+ "\n* `wml2` (only if name field is specified)"
+ "\n* `json` (default)"),
@OpenApiParam(name = PAGE, description = "This identifies where in the "
+ "request you are. This is an opaque value, and can be obtained from "
+ "the 'next-page' value in the response."),
Expand Down
63 changes: 43 additions & 20 deletions cwms-data-api/src/main/java/cwms/cda/api/LocationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import static cwms.cda.api.Controllers.STATUS_404;
import static cwms.cda.api.Controllers.UNIT;
import static cwms.cda.api.Controllers.UPDATE;
import static cwms.cda.api.Controllers.VERSION;
import static cwms.cda.data.dao.JooqDao.getDslContext;

import com.codahale.metrics.Histogram;
Expand Down Expand Up @@ -108,34 +109,45 @@ private Timer.Context markAndTime(String subject) {
@OpenApi(
queryParams = {
@OpenApiParam(name = NAMES, description = "Specifies the name(s) of the "
+ "location(s) whose data is to be included in the response"),
+ "location(s) whose data is to be included in the response. "
+ "When the `" + FORMAT + "` parameter is not provided and `" + Formats.JSONV2
+ "` is specified in the accept header, this parameter is a "
+ "Posix <a href=\"regexp.html\">regular expression</a> matching against the id"),
@OpenApiParam(name = OFFICE, description = "Specifies the owning office of "
+ "the location level(s) whose data is to be included in the response"
+ ". If this field is not specified, matching location level "
+ "information from all offices shall be returned."),
@OpenApiParam(name = UNIT, description = "Specifies the unit or unit system"
+ " of the response. Valid values for the unit field are:\r\n 1. EN. "
+ " Specifies English unit system. Location level values will be in"
+ " the default English units for their parameters.\r\n2. SI. "
+ "Specifies the SI unit system. Location level values will be in "
+ "the default SI units for their parameters.\r\n3. Other. Any unit "
+ " of the response. Valid values for the unit field are:"
+ "\n* `EN` Specifies English unit system. Location level values will be in"
+ " the default English units for their parameters."
+ "\n* `SI` Specifies the SI unit system. Location level values will be in "
+ "the default SI units for their parameters."
+ "\n* `Other` Any unit "
+ "returned in the response to the units URI request that is "
+ "appropriate for the requested parameters."),
@OpenApiParam(name = DATUM, description = "Specifies the elevation datum of"
+ " the response. This field affects only elevation location levels. "
+ "Valid values for this field are:\r\n1. NAVD88. The elevation "
+ " the response. This field affects only vertical datum. "
+ "Valid values for this field are:"
+ "\n* `NAVD88` The elevation "
+ "values will in the specified or default units above the NAVD-88 "
+ "datum.\r\n2. NGVD29. The elevation values will be in the "
+ "datum."
+ "\n* `NGVD29` The elevation values will be in the "
+ "specified or default units above the NGVD-29 datum."),
@OpenApiParam(name = FORMAT, description = "Specifies the encoding format "
+ "of the response. Valid values for the format field for this URI "
+ "are:\r\n1. tab\r\n2. csv\r\n3. xml\r\n4. wml2 (only if "
+ "name field is specified)\r\n5. json (default)\n" + "6. "
+ "geojson")
+ "are:\n"
+ "\n* `tab`"
+ "\n* `csv`"
+ "\n* `xml`"
+ "\n* `wml2` (only if name field is specified)"
+ "\n* `json` (default)\n"
+ "\n* `geojson`")
},
responses = {
@OpenApiResponse(status = STATUS_200,
content = {
@OpenApiContent(isArray = true, type = Formats.JSONV2, from = Location.class),
@OpenApiContent(type = Formats.JSON),
@OpenApiContent(type = Formats.TAB),
@OpenApiContent(type = Formats.CSV),
Expand All @@ -145,7 +157,8 @@ private Timer.Context markAndTime(String subject) {
@OpenApiContent(type = "")
})
},
description = "Returns CWMS Location Data",
description = "Returns CWMS Location Data. The Catalog end-point is also capable of "
+ "retrieving lists of locations and can filter on additional fields.",
tags = {"Locations"}
)
@Override
Expand All @@ -167,7 +180,15 @@ public void getAll(@NotNull Context ctx) {
ctx.contentType(contentType.toString());

final String results;
if (contentType.getType().equals(Formats.GEOJSON)) {

String version = contentType.getParameters().get(VERSION);
if (version != null && version.equals("2")) {
List<Location> locations = locationsDao.getLocations(names, units, datum, office);
ObjectMapper om = getObjectMapperForFormat(contentType.getType());
results = om.writeValueAsString(locations);
ctx.result(results);
requestResultSize.update(results.length());
} else if (contentType.getType().equals(Formats.GEOJSON)) {
FeatureCollection collection = locationsDao.buildFeatureCollection(names, units,
office);
ctx.json(collection);
Expand Down Expand Up @@ -217,11 +238,12 @@ private String getFormatFromContent(ContentType contentType) {
+ "included in the response. If this field is not specified, matching"
+ " location level information from all offices shall be returned."),
@OpenApiParam(name = UNIT, description = "Specifies the unit or unit system"
+ " of the response. Valid values for the unit field are:\r\n 1. EN. "
+ " Specifies English unit system. Location values will be in the "
+ "default English units for their parameters.\r\n2. SI. Specifies "
+ "the SI unit system. Location values will be in the default SI "
+ "units for their parameters.\r\n3. Other. Any unit returned in the "
+ " of the response. Valid values for the unit field are: "
+ "\n* `EN` Specifies English unit system. Location values will be in the "
+ "default English units for their parameters."
+ "\n* `SI` Specifies the SI unit system. Location values will be in the "
+ "default SI units for their parameters."
+ "\n* `Other` Any unit returned in the "
+ "response to the units URI request that is appropriate for the "
+ "requested parameters.")
},
Expand Down Expand Up @@ -401,7 +423,8 @@ public void delete(@NotNull Context ctx, @NotNull String locationId) {
} catch (DataAccessException ex) {
SQLException cause = ex.getCause(SQLException.class);
if (cause != null && cause.getErrorCode() == 20031) {
throw new DeleteConflictException("Unable to delete requested location: " + locationId + " for office: " + office, cause);
throw new DeleteConflictException("Unable to delete requested location: "
+ locationId + " for office: " + office, cause);
}
throw ex;
}
Expand Down
Loading

0 comments on commit ab37863

Please sign in to comment.