Skip to content

Commit

Permalink
Reverted RatingController, removed Timezone parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
zack-rma committed Dec 17, 2024
1 parent 04bf70b commit 51226e1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
32 changes: 16 additions & 16 deletions cwms-data-api/src/main/java/cwms/cda/api/RatingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 =
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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());
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 51226e1

Please sign in to comment.