Skip to content

Commit

Permalink
Updated endpoint naming, tests in response to Adam and Mike's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
zack-rma committed Oct 9, 2024
1 parent 3a15ae9 commit fd14485
Show file tree
Hide file tree
Showing 33 changed files with 882 additions and 1,007 deletions.
19 changes: 8 additions & 11 deletions cwms-data-api/src/main/java/cwms/cda/ApiServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,14 @@
import cwms.cda.api.project.ProjectPublishStatusUpdate;
import cwms.cda.api.project.RemoveAllLockRevokerRights;
import cwms.cda.api.project.UpdateLockRevokerRights;
import cwms.cda.api.timeseriesprofile.TimeSeriesProfileBase;
import cwms.cda.api.timeseriesprofile.TimeSeriesProfileCatalogController;
import cwms.cda.api.timeseriesprofile.TimeSeriesProfileController;
import cwms.cda.api.timeseriesprofile.TimeSeriesProfileCreateController;
import cwms.cda.api.timeseriesprofile.TimeSeriesProfileDeleteController;
import cwms.cda.api.timeseriesprofile.TimeSeriesProfileInstanceBase;
import cwms.cda.api.timeseriesprofile.TimeSeriesProfileInstanceCatalogController;
import cwms.cda.api.timeseriesprofile.TimeSeriesProfileInstanceController;
import cwms.cda.api.timeseriesprofile.TimeSeriesProfileInstanceCreateController;
import cwms.cda.api.timeseriesprofile.TimeSeriesProfileInstanceDeleteController;
import cwms.cda.api.timeseriesprofile.TimeSeriesProfileParserBase;
import cwms.cda.api.timeseriesprofile.TimeSeriesProfileParserCatalogController;
import cwms.cda.api.timeseriesprofile.TimeSeriesProfileParserController;
import cwms.cda.api.timeseriesprofile.TimeSeriesProfileParserCreateController;
Expand Down Expand Up @@ -494,31 +491,31 @@ protected void configureRoutes() {
addCacheControl(textBinaryValuePath, 1, TimeUnit.DAYS);

String timeSeriesProfilePath = "/timeseries/profile/";
get(format(timeSeriesProfilePath + "{%s}/{%s}", Controllers.LOCATION_ID, TimeSeriesProfileBase.PARAMETER_ID),
get(format(timeSeriesProfilePath + "{%s}/{%s}", Controllers.LOCATION_ID, Controllers.PARAMETER_ID),
new TimeSeriesProfileController(metrics));
delete(format(timeSeriesProfilePath + "/{%s}/{%s}", Controllers.LOCATION_ID,
TimeSeriesProfileBase.PARAMETER_ID), new TimeSeriesProfileDeleteController(metrics),
Controllers.PARAMETER_ID), new TimeSeriesProfileDeleteController(metrics),
requiredRoles);
get(format(timeSeriesProfilePath, Controllers.LOCATION_ID, TimeSeriesProfileBase.PARAMETER_ID),
get(format(timeSeriesProfilePath, Controllers.LOCATION_ID, Controllers.PARAMETER_ID),
new TimeSeriesProfileCatalogController(metrics));
post(timeSeriesProfilePath, new TimeSeriesProfileCreateController(metrics), requiredRoles);

String timeSeriesProfileParserPath = "/timeseries/profile-parser/";
get(format(timeSeriesProfileParserPath + "{%s}/{%s}/", Controllers.LOCATION_ID,
TimeSeriesProfileParserBase.PARAMETER_ID), new TimeSeriesProfileParserController(metrics));
Controllers.PARAMETER_ID), new TimeSeriesProfileParserController(metrics));
post(timeSeriesProfileParserPath, new TimeSeriesProfileParserCreateController(metrics), requiredRoles);
delete(format(timeSeriesProfileParserPath + "{%s}/{%s}/", Controllers.LOCATION_ID,
TimeSeriesProfileParserBase.PARAMETER_ID), new TimeSeriesProfileParserDeleteController(metrics),
Controllers.PARAMETER_ID), new TimeSeriesProfileParserDeleteController(metrics),
requiredRoles);
get(timeSeriesProfileParserPath, new TimeSeriesProfileParserCatalogController(metrics));

String timeSeriesProfileInstancePath = "/timeseries/profile-instance/";
get(format(timeSeriesProfileInstancePath + "{%s}/{%s}/{%s}/", Controllers.LOCATION_ID,
TimeSeriesProfileInstanceBase.PARAMETER_ID, Controllers.VERSION),
Controllers.PARAMETER_ID, Controllers.VERSION),
new TimeSeriesProfileInstanceController(metrics));
post(timeSeriesProfileInstancePath, new TimeSeriesProfileInstanceCreateController(metrics), requiredRoles);
delete(format(timeSeriesProfileInstancePath + "{%s}/{%s}/{%s}/", Controllers.LOCATION_ID,
TimeSeriesProfileInstanceBase.PARAMETER_ID, Controllers.VERSION),
Controllers.PARAMETER_ID, Controllers.VERSION),
new TimeSeriesProfileInstanceDeleteController(metrics), requiredRoles);
get(timeSeriesProfileInstancePath, new TimeSeriesProfileInstanceCatalogController(metrics));

Expand Down Expand Up @@ -850,7 +847,7 @@ private static String getAccessManagerName() {

@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
throws IOException {
totalRequests.mark();
try {
String office = officeFromContext(req.getContextPath());
Expand Down
6 changes: 6 additions & 0 deletions cwms-data-api/src/main/java/cwms/cda/api/Controllers.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ public final class Controllers {
public static final String LOCATIONS = "locations";
public static final String WATER_USER = "water-user";
public static final String CONTRACT_NAME = "contract-name";
public static final String PARAMETER_ID = "parameter-id";
public static final String PARAMETER_ID_MASK = "parameter-id-mask";
public static final String VERSION_MASK = "version-mask";
public static final String PROFILE_DATA = "profile-data";
public static final String PREVIOUS = "previous";
public static final String NEXT = "next";

public static final String LOCATION_ID = "location-id";
public static final String SOURCE_ENTITY = "source-entity";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@
import cwms.cda.data.dao.timeseriesprofile.TimeSeriesProfileDao;
import org.jooq.DSLContext;

public class TimeSeriesProfileBase {
public abstract class TimeSeriesProfileBase {
static final String TAG = "TimeSeries";
public static final String PARAMETER_ID = "parameter-id";
private MetricRegistry metrics;

TimeSeriesProfileDao getContractDao(DSLContext dsl) {
TimeSeriesProfileDao getProfileDao(DSLContext dsl) {
return new TimeSeriesProfileDao(dsl);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public TimeSeriesProfileCatalogController(MetricRegistry metrics) {
public void handle(@NotNull Context ctx) {
try (final Timer.Context ignored = markAndTime(GET_ALL)) {
DSLContext dsl = getDslContext(ctx);
TimeSeriesProfileDao tspDao = new TimeSeriesProfileDao(dsl);
TimeSeriesProfileDao tspDao = getProfileDao(dsl);
String officeMask = ctx.queryParamAsClass(OFFICE_MASK, String.class).getOrDefault("*");
String locationMask = ctx.queryParamAsClass(LOCATION_MASK, String.class).getOrDefault("*");
String parameterIdMask = ctx.queryParamAsClass(PARAMETER_ID_MASK, String.class).getOrDefault("*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static cwms.cda.api.Controllers.GET_ONE;
import static cwms.cda.api.Controllers.LOCATION_ID;
import static cwms.cda.api.Controllers.OFFICE;
import static cwms.cda.api.Controllers.PARAMETER_ID;
import static cwms.cda.api.Controllers.STATUS_200;
import static cwms.cda.api.Controllers.requiredParam;
import static cwms.cda.data.dao.JooqDao.getDslContext;
Expand Down Expand Up @@ -85,9 +86,9 @@ public void handle(@NotNull Context ctx) {
try (final Timer.Context ignored = markAndTime(GET_ONE)) {
DSLContext dsl = getDslContext(ctx);
String parameterId = ctx.pathParam(PARAMETER_ID);
TimeSeriesProfileDao tspDao = new TimeSeriesProfileDao(dsl);
TimeSeriesProfileDao tspDao = getProfileDao(dsl);
String office = requiredParam(ctx, OFFICE);
String locationId = requiredParam(ctx, LOCATION_ID);
String locationId = ctx.pathParam(LOCATION_ID);
TimeSeriesProfile returned = tspDao.retrieveTimeSeriesProfile(locationId, parameterId, office);
String acceptHeader = ctx.header(Header.ACCEPT);
ContentType contentType = Formats.parseHeader(acceptHeader, TimeSeriesProfile.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void handle(@NotNull Context ctx) {
TimeSeriesProfile timeSeriesProfile = Formats.parseContent(Formats.parseHeader(Formats.JSONV1,
TimeSeriesProfile.class), ctx.body(), TimeSeriesProfile.class);
boolean failIfExists = ctx.queryParamAsClass(FAIL_IF_EXISTS, boolean.class).getOrDefault(true);
TimeSeriesProfileDao tspDao = new TimeSeriesProfileDao(dsl);
TimeSeriesProfileDao tspDao = getProfileDao(dsl);
tspDao.storeTimeSeriesProfile(timeSeriesProfile, failIfExists);
ctx.status(HttpServletResponse.SC_CREATED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void handle(@NotNull Context ctx) {
String keyParameter = ctx.pathParam(PARAMETER_ID);
String office = requiredParam(ctx, OFFICE);
String locationId = ctx.pathParam(LOCATION_ID);
TimeSeriesProfileDao tspDao = new TimeSeriesProfileDao(dsl);
TimeSeriesProfileDao tspDao = getProfileDao(dsl);
tspDao.deleteTimeSeriesProfile(locationId, keyParameter, office);
ctx.status(HttpServletResponse.SC_NO_CONTENT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,11 @@
import cwms.cda.data.dao.timeseriesprofile.TimeSeriesProfileInstanceDao;
import org.jooq.DSLContext;

public class TimeSeriesProfileInstanceBase {
public abstract class TimeSeriesProfileInstanceBase {
static final String TAG = "TimeSeries";
public static final String PARAMETER_ID = "parameter-id";
public static final String PARAMETER_ID_MASK = "parameter-id-mask";
public static final String VERSION_MASK = "version-mask";
public static final String PROFILE_DATA = "profile-data";
public static final String START_INCLUSIVE = "start-inclusive";
public static final String END_INCLUSIVE = "end-inclusive";
public static final String PREVIOUS = "previous";
public static final String NEXT = "next";
private MetricRegistry metrics;

TimeSeriesProfileInstanceDao getContractDao(DSLContext dsl) {
TimeSeriesProfileInstanceDao getProfileInstanceDao(DSLContext dsl) {
return new TimeSeriesProfileInstanceDao(dsl);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public TimeSeriesProfileInstanceCatalogController(MetricRegistry metrics) {
public void handle(@NotNull Context ctx) {
try (final Timer.Context ignored = markAndTime(GET_ALL)) {
DSLContext dsl = getDslContext(ctx);
TimeSeriesProfileInstanceDao tspInstanceDao = new TimeSeriesProfileInstanceDao(dsl);
TimeSeriesProfileInstanceDao tspInstanceDao = getProfileInstanceDao(dsl);
String officeMask = ctx.queryParamAsClass(OFFICE_MASK, String.class).getOrDefault("*");
String locationMask = ctx.queryParamAsClass(LOCATION_MASK, String.class).getOrDefault("*");
String parameterIdMask = ctx.queryParamAsClass(PARAMETER_ID_MASK, String.class).getOrDefault("*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,26 @@

package cwms.cda.api.timeseriesprofile;

import static cwms.cda.api.Controllers.*;
import static cwms.cda.api.Controllers.END;
import static cwms.cda.api.Controllers.END_TIME_INCLUSIVE;
import static cwms.cda.api.Controllers.GET_ONE;
import static cwms.cda.api.Controllers.LOCATION_ID;
import static cwms.cda.api.Controllers.MAX_VERSION;
import static cwms.cda.api.Controllers.NEXT;
import static cwms.cda.api.Controllers.OFFICE;
import static cwms.cda.api.Controllers.PAGE;
import static cwms.cda.api.Controllers.PAGE_SIZE;
import static cwms.cda.api.Controllers.PARAMETER_ID;
import static cwms.cda.api.Controllers.PREVIOUS;
import static cwms.cda.api.Controllers.START;
import static cwms.cda.api.Controllers.START_TIME_INCLUSIVE;
import static cwms.cda.api.Controllers.STATUS_200;
import static cwms.cda.api.Controllers.TIMEZONE;
import static cwms.cda.api.Controllers.UNIT;
import static cwms.cda.api.Controllers.VERSION;
import static cwms.cda.api.Controllers.VERSION_DATE;
import static cwms.cda.api.Controllers.requiredInstant;
import static cwms.cda.api.Controllers.requiredParam;
import static cwms.cda.data.dao.JooqDao.getDslContext;

import com.codahale.metrics.MetricRegistry;
Expand Down Expand Up @@ -70,9 +89,9 @@ public TimeSeriesProfileInstanceController(MetricRegistry metrics) {
+ " time series profile instance. Default is the min or max version date, depending on the maxVersion"),
@OpenApiParam(name = UNIT, description = "The units of the"
+ " time series profile instance. Provided as a list separated by ','", required = true),
@OpenApiParam(name = START_INCLUSIVE, type = Boolean.class, description = "The start inclusive of the"
@OpenApiParam(name = START_TIME_INCLUSIVE, type = Boolean.class, description = "The start inclusive of the"
+ " time series profile instance. Default is true"),
@OpenApiParam(name = END_INCLUSIVE, type = Boolean.class, description = "The end inclusive of the"
@OpenApiParam(name = END_TIME_INCLUSIVE, type = Boolean.class, description = "The end inclusive of the"
+ " time series profile instance. Default is true"),
@OpenApiParam(name = PREVIOUS, type = boolean.class, description = "Whether to include the previous "
+ " time window of the time series profile instance. Default is false"),
Expand All @@ -99,7 +118,9 @@ public TimeSeriesProfileInstanceController(MetricRegistry metrics) {
+ " time series profile instance.", required = true),
},
method = HttpMethod.GET,
summary = "Get all time series profile instances",
summary = "Get all time series profile instances that match the provided masks. This endpoint will return a "
+ "list of time series profile instances without the associated data. Data for an instance can be "
+ "retrieved using the singular retrieval endpoint.",
tags = {TAG},
responses = {
@OpenApiResponse(status = STATUS_200,
Expand All @@ -115,34 +136,32 @@ public TimeSeriesProfileInstanceController(MetricRegistry metrics) {
public void handle(@NotNull Context ctx) {
try (final Timer.Context ignored = markAndTime(GET_ONE)) {
DSLContext dsl = getDslContext(ctx);
TimeSeriesProfileInstanceDao tspInstanceDao = new TimeSeriesProfileInstanceDao(dsl);
TimeSeriesProfileInstanceDao tspInstanceDao = getProfileInstanceDao(dsl);
String officeId = requiredParam(ctx, OFFICE);
String locationId = ctx.pathParam(LOCATION_ID);
String keyParameter = ctx.pathParam(PARAMETER_ID);
String version = ctx.pathParam(VERSION);
List<String> unit = Arrays.asList(requiredParam(ctx, UNIT).split(","));
Instant startTime = Instant.ofEpochMilli(Long.parseLong(ctx.queryParamAsClass(START, String.class)
.getOrDefault(String.valueOf(Instant.now().toEpochMilli()))));
Instant endTime = Instant.ofEpochMilli(Long.parseLong(ctx.queryParamAsClass(END, String.class)
.getOrDefault(String.valueOf(Instant.now().toEpochMilli()))));
Instant startTime = requiredInstant(ctx, START);
Instant endTime = requiredInstant(ctx, END);
String timeZone = ctx.queryParamAsClass(TIMEZONE, String.class).getOrDefault("UTC");
boolean startInclusive = ctx.queryParamAsClass(START_INCLUSIVE, boolean.class)
boolean startInclusive = ctx.queryParamAsClass(START_TIME_INCLUSIVE, boolean.class)
.getOrDefault(true);
boolean endInclusive = ctx.queryParamAsClass(END_INCLUSIVE, boolean.class)
boolean endInclusive = ctx.queryParamAsClass(END_TIME_INCLUSIVE, boolean.class)
.getOrDefault(true);
boolean previous = ctx.queryParamAsClass(PREVIOUS, boolean.class).getOrDefault(false);
boolean next = ctx.queryParamAsClass(NEXT, boolean.class).getOrDefault(false);
Instant versionDate = ctx.queryParamAsClass(VERSION_DATE, String.class).getOrDefault(null) == null
? null : Instant.ofEpochMilli(Long.parseLong(ctx.queryParamAsClass(VERSION_DATE, String.class)
.getOrDefault(null)));
? null : Instant.parse(ctx.queryParamAsClass(VERSION_DATE, String.class)
.getOrDefault(null));
boolean maxVersion = ctx.queryParamAsClass(MAX_VERSION, boolean.class)
.getOrDefault(false);
String page = ctx.queryParam(PAGE);
int pageSize = ctx.queryParamAsClass(PAGE_SIZE, Integer.class).getOrDefault(500);
CwmsId tspIdentifier = new CwmsId.Builder().withOfficeId(officeId).withName(locationId).build();
TimeSeriesProfileInstance returnedInstance = tspInstanceDao.retrieveTimeSeriesProfileInstance(tspIdentifier,
keyParameter, version, unit, startTime, endTime, timeZone, startInclusive, endInclusive,
previous, next, versionDate, maxVersion, page, pageSize);
CwmsId tspLocationIdentifier = new CwmsId.Builder().withOfficeId(officeId).withName(locationId).build();
TimeSeriesProfileInstance returnedInstance = tspInstanceDao.retrieveTimeSeriesProfileInstance(
tspLocationIdentifier, keyParameter, version, unit, startTime, endTime, timeZone, startInclusive,
endInclusive, previous, next, versionDate, maxVersion, page, pageSize);
String acceptHeader = ctx.header(Header.ACCEPT);
ContentType contentType = Formats.parseHeader(acceptHeader, TimeSeriesProfileInstance.class);
String result = Formats.format(contentType, returnedInstance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@

package cwms.cda.api.timeseriesprofile;

import static cwms.cda.api.Controllers.*;
import static cwms.cda.api.Controllers.CREATE;
import static cwms.cda.api.Controllers.METHOD;
import static cwms.cda.api.Controllers.OVERRIDE_PROTECTION;
import static cwms.cda.api.Controllers.PROFILE_DATA;
import static cwms.cda.api.Controllers.VERSION;
import static cwms.cda.api.Controllers.VERSION_DATE;
import static cwms.cda.api.Controllers.requiredInstant;
import static cwms.cda.api.Controllers.requiredParam;
import static cwms.cda.data.dao.JooqDao.getDslContext;

import com.codahale.metrics.MetricRegistry;
Expand Down Expand Up @@ -62,7 +68,7 @@ public TimeSeriesProfileInstanceCreateController(MetricRegistry metrics) {
@OpenApiParam(name = OVERRIDE_PROTECTION, type = Boolean.class, description = "Override protection"
+ " for the time series profile instance. Default is false"),
@OpenApiParam(name = VERSION_DATE, type = Long.class, description = "The version date of the"
+ " time series profile instance. Default is the current date and time"),
+ " time series profile instance.", required = true),
@OpenApiParam(name = PROFILE_DATA, required = true, description = "The profile data of the"
+ " time series profile instance"),
@OpenApiParam(name = VERSION, description = "The version of the"
Expand All @@ -82,13 +88,12 @@ public TimeSeriesProfileInstanceCreateController(MetricRegistry metrics) {
public void handle(@NotNull Context ctx) {
try (final Timer.Context ignored = markAndTime(CREATE)) {
DSLContext dsl = getDslContext(ctx);
TimeSeriesProfileInstanceDao tspInstanceDao = new TimeSeriesProfileInstanceDao(dsl);
TimeSeriesProfileInstanceDao tspInstanceDao = getProfileInstanceDao(dsl);
TimeSeriesProfile timeSeriesProfile = Formats.parseContent(Formats.parseHeader(Formats.JSONV1,
TimeSeriesProfile.class), ctx.body(), TimeSeriesProfile.class);
String profileData = requiredParam(ctx, PROFILE_DATA);
String versionId = requiredParam(ctx, VERSION);
Instant versionDate = Instant.ofEpochMilli(ctx.queryParamAsClass(VERSION_DATE, Long.class)
.getOrDefault(Instant.now().toEpochMilli()));
Instant versionDate = requiredInstant(ctx, VERSION_DATE);
StoreRule storeRule = ctx.queryParamAsClass(METHOD, StoreRule.class).getOrDefault(StoreRule.REPLACE_ALL);
boolean overrideProtection = ctx.queryParamAsClass(OVERRIDE_PROTECTION, boolean.class)
.getOrDefault(false);
Expand Down
Loading

0 comments on commit fd14485

Please sign in to comment.