diff --git a/cwms-data-api/src/main/java/cwms/cda/api/Controllers.java b/cwms-data-api/src/main/java/cwms/cda/api/Controllers.java index 5d4b3abfb..060e476a8 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/Controllers.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/Controllers.java @@ -31,6 +31,8 @@ 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; @@ -38,6 +40,7 @@ import java.time.Instant; import java.time.ZonedDateTime; import org.jetbrains.annotations.Nullable; + import static com.codahale.metrics.MetricRegistry.name; public final class Controllers { @@ -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); @@ -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); + } + } } diff --git a/cwms-data-api/src/main/java/cwms/cda/api/OfficeController.java b/cwms-data-api/src/main/java/cwms/cda/api/OfficeController.java index 53b242928..ac60a0232 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/OfficeController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/OfficeController.java @@ -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()); @@ -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());