From 51226e1bdfffd531b1080a8da893b15b75dc62bc Mon Sep 17 00:00:00 2001 From: zack-rma Date: Tue, 17 Dec 2024 12:28:59 -0800 Subject: [PATCH] Reverted RatingController, removed Timezone parameter --- .../java/cwms/cda/api/RatingController.java | 32 +++++++++---------- .../cwms/cda/api/RatingLatestController.java | 11 ++----- .../java/cwms/cda/data/dao/RatingSetDao.java | 3 +- 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/cwms-data-api/src/main/java/cwms/cda/api/RatingController.java b/cwms-data-api/src/main/java/cwms/cda/api/RatingController.java index 8add051e2..edc330ced 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/RatingController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/RatingController.java @@ -296,16 +296,19 @@ public void getAll(@NotNull Context ctx) { ContentType contentType = Formats.parseHeaderAndQueryParm(header, format, RatingAliasMarker.class); - if (format.isEmpty()) { + if (format.isEmpty()) + { //Use the full content type here (i.e. application/json;version=2) ctx.contentType(contentType.toString()); - } else { + } + else + { //Legacy content type only includes the basic type (i.e. application/json) ctx.contentType(contentType.getType()); } - //At the moment, we still use the legacy formatting here, since we don't have a newer API for - // serializing/deserializing a collection of rating sets - unlike getOne. + //At the moment, we still use the legacy formatting here, since we don't have a newer API for serializing/deserializing + //a collection of rating sets - unlike getOne. String legacyFormat = Formats.getLegacyTypeFromContentType(contentType); String results = ratingDao.retrieveRatings(legacyFormat, names, unit, datum, office, start, end, timezone); @@ -319,8 +322,7 @@ public void getAll(@NotNull Context ctx) { @OpenApi( pathParams = { - @OpenApiParam(name = RATING_ID, required = true, description = "The rating-id of the effective " - + "dates to be retrieve. "), + @OpenApiParam(name = RATING_ID, required = true, description = "The rating-id of the effective dates to be retrieve. "), }, queryParams = { @OpenApiParam(name = OFFICE, required = true, description = @@ -352,7 +354,7 @@ public void getAll(@NotNull Context ctx) { public void getOne(@NotNull Context ctx, @NotNull String rating) { try (final Timer.Context ignored = markAndTime(GET_ONE)) { - + String officeId = ctx.queryParam(OFFICE); String timezone = ctx.queryParamAsClass(TIMEZONE, String.class).getOrDefault("UTC"); Instant beginInstant = null; @@ -367,8 +369,6 @@ public void getOne(@NotNull Context ctx, @NotNull String rating) { endInstant = DateUtils.parseUserDate(end, timezone).toInstant(); } - String officeId = ctx.queryParam(OFFICE); - RatingSet.DatabaseLoadMethod method = ctx.queryParamAsClass(METHOD, RatingSet.DatabaseLoadMethod.class) .getOrDefault(RatingSet.DatabaseLoadMethod.EAGER); @@ -381,8 +381,9 @@ public void getOne(@NotNull Context ctx, @NotNull String rating) { } } + @Nullable - protected String getRatingSetString(Context ctx, RatingSet.DatabaseLoadMethod method, + private String getRatingSetString(Context ctx, RatingSet.DatabaseLoadMethod method, String officeId, String rating, Instant begin, Instant end) { String retval = null; @@ -397,9 +398,7 @@ protected String getRatingSetString(Context ctx, RatingSet.DatabaseLoadMethod me if (isJson || isXml) { ctx.contentType(contentType.toString()); try { - RatingSet ratingSet = null; - ratingSet = getRatingSet(ctx, method, officeId, rating, begin, end); - + RatingSet ratingSet = getRatingSet(ctx, method, officeId, rating, begin, end); if (ratingSet != null) { if (isJson) { retval = JsonRatingUtils.toJson(ratingSet); @@ -425,7 +424,8 @@ protected String getRatingSetString(Context ctx, RatingSet.DatabaseLoadMethod me } else { CdaError re = new CdaError("Currently supporting only: " + Formats.JSONV2 + " and " + Formats.XMLV2); - logger.log(Level.WARNING, String.format("Provided accept header not recognized: %s", acceptHeader), re); + logger.log(Level.WARNING, "Provided accept header not recognized:" + + acceptHeader, re); ctx.status(HttpServletResponse.SC_NOT_IMPLEMENTED); ctx.json(CdaError.notImplemented()); } @@ -436,8 +436,8 @@ protected String getRatingSetString(Context ctx, RatingSet.DatabaseLoadMethod me } private RatingSet getRatingSet(Context ctx, RatingSet.DatabaseLoadMethod method, - String officeId, String rating, Instant begin, - Instant end) throws IOException, RatingException { + String officeId, String rating, Instant begin, + Instant end) throws IOException, RatingException { RatingSet ratingSet; try (final Timer.Context ignored = markAndTime("getRatingSet")) { DSLContext dsl = getDslContext(ctx); diff --git a/cwms-data-api/src/main/java/cwms/cda/api/RatingLatestController.java b/cwms-data-api/src/main/java/cwms/cda/api/RatingLatestController.java index 31e5ffe9f..a3c97b8f7 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/RatingLatestController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/RatingLatestController.java @@ -31,7 +31,6 @@ import static cwms.cda.api.Controllers.OFFICE; import static cwms.cda.api.Controllers.RATING_ID; import static cwms.cda.api.Controllers.STATUS_200; -import static cwms.cda.api.Controllers.TIMEZONE; import static cwms.cda.data.dao.JooqDao.getDslContext; import com.codahale.metrics.MetricRegistry; @@ -51,8 +50,6 @@ import io.javalin.plugin.openapi.annotations.OpenApiParam; import io.javalin.plugin.openapi.annotations.OpenApiResponse; -import java.io.IOException; - import org.jetbrains.annotations.NotNull; import org.jooq.DSLContext; @@ -83,11 +80,6 @@ protected RatingDao getRatingDao(DSLContext dsl) { @OpenApiParam(name = OFFICE, required = true, description = "Specifies the owning office of the ratingset to be included in the " + "response."), - @OpenApiParam(name = TIMEZONE, description = "Specifies " - + "the time zone of the values of the begin and end fields (unless " - + "otherwise specified), as well as the time zone of any times in the" - + " response. If this field is not specified, the default time zone " - + "of UTC shall be used."), @OpenApiParam(name = METHOD, description = "Specifies " + "the retrieval method used. If no method is provided EAGER will be used.", type = RatingSet.DatabaseLoadMethod.class), @@ -128,7 +120,8 @@ public void handle(@NotNull Context ctx) throws Exception { } private String getLatestRatingSet(Context ctx, RatingSet.DatabaseLoadMethod method, - String officeId, String rating, ContentType contentType) throws IOException, RatingException { + String officeId, String rating, ContentType contentType) + throws RatingException { String ratingSet = null; try (final Timer.Context ignored = markAndTime("getLatestRatingSet")) { DSLContext dsl = getDslContext(ctx); diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingSetDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingSetDao.java index 35b57a42c..e0a306a7e 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingSetDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingSetDao.java @@ -90,8 +90,7 @@ private static String extractOfficeId(String ratingSet) throws JsonProcessingExc } @Override - public String retrieveLatestXML(String officeId, - String specificationId) { + public String retrieveLatestXML(String officeId, String specificationId) { return connectionResult(dsl, c -> { DSLContext context = getDslContext(c, officeId); return CWMS_RATING_PACKAGE.call_RETRIEVE_EFF_RATINGS_XML_F(context.configuration(), specificationId,