Skip to content

Commit

Permalink
Merge pull request #687 from RyanM-RMA/bugfix/content_type_add_deprec…
Browse files Browse the repository at this point in the history
…ated

Bugfix/content type add deprecated
  • Loading branch information
RyanM-RMA authored Jun 7, 2024
2 parents d245ba4 + d80c03c commit c6070b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 18 additions & 1 deletion cwms-data-api/src/main/java/cwms/cda/api/Controllers.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@
import cwms.cda.api.enums.VersionType;
import cwms.cda.api.errors.RequiredQueryParameterException;
import cwms.cda.data.dao.JooqDao;
import cwms.cda.formatters.ContentType;
import cwms.cda.formatters.Formats;
import cwms.cda.helpers.DateUtils;
import io.javalin.core.validation.JavalinValidation;
import io.javalin.core.validation.Validator;
import io.javalin.http.Context;
import java.time.Instant;
import java.time.ZonedDateTime;
import org.jetbrains.annotations.Nullable;

import static com.codahale.metrics.MetricRegistry.name;

public final class Controllers {
Expand Down Expand Up @@ -168,6 +171,10 @@ public final class Controllers {
public static final String EXCLUDE_EMPTY = "exclude-empty";
public static final String DEFAULT_VALUE = "default-value";

private static final String DEPRECATED_HEADER = "CWMS-DATA-Format-Deprecated";
private static final String DEPRECATED_TAB = "2024-11-01 TAB is not used often.";
private static final String DEPRECATED_CSV = "2024-11-01 CSV is not used often.";


static {
JavalinValidation.register(JooqDao.DeleteMethod.class, Controllers::getDeleteMethod);
Expand Down Expand Up @@ -355,5 +362,15 @@ public static Instant requiredInstant(Context ctx, String param) {
return retval;
}


static void addDeprecatedContentTypeWarning(Context ctx, ContentType type)
{
if (type.getType().equalsIgnoreCase(Formats.TAB))
{
ctx.res.addHeader(DEPRECATED_HEADER, DEPRECATED_TAB);
}
else if (type.getType().equalsIgnoreCase(Formats.CSV))
{
ctx.res.addHeader(DEPRECATED_HEADER, DEPRECATED_CSV);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public void getAll(Context ctx) {

String result = Formats.format(contentType, offices, Office.class);

Controllers.addDeprecatedContentTypeWarning(ctx, contentType);

ctx.result(result).contentType(contentType.toString());
requestResultSize.update(result.length());

Expand Down Expand Up @@ -154,6 +156,7 @@ public void getOne(Context ctx, String officeId) {
String formatHeader = ctx.header(Header.ACCEPT);
ContentType contentType = Formats.parseHeaderAndQueryParm(formatHeader, formatParm, Office.class);
String result = Formats.format(contentType, office.get());
Controllers.addDeprecatedContentTypeWarning(ctx, contentType);
ctx.result(result).contentType(contentType.toString());

requestResultSize.update(result.length());
Expand Down

0 comments on commit c6070b3

Please sign in to comment.