Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
4456117
Add tests for time series with and without vertical datum information
rma-rripken Sep 30, 2025
f6734b8
Remove authorization header from get requests.
rma-rripken Oct 1, 2025
d647522
Call full form of create_location so that I can test with vertical_da…
rma-rripken Oct 1, 2025
a4f029f
Removing Authorization header from GET requests
rma-rripken Oct 1, 2025
d1b2b52
The vertical datum should be NGVD. Somehow many of these example fil…
rma-rripken Oct 9, 2025
b00d230
Work in-progress
rma-rripken Oct 10, 2025
3cb5837
Updating ts vertical datum test.
rma-rripken Oct 31, 2025
5943a9c
CDA-45 - adds conversion of datum. Adds unit test and integration test.
rma-bryson Nov 13, 2025
751543c
CDA-45 - Updated offsets upon conversion and updates vertical datum i…
rma-bryson Nov 14, 2025
45c50a2
CDA-45 - refactor of timeseries controller after rebase
rma-bryson Nov 14, 2025
08b0c5c
CDA-45 - Added back ConnectionRunnable that got removed during rebase
rma-bryson Nov 14, 2025
6b81f8e
CDA-45 - Improving method naming and refactoring code to be more clea…
rma-bryson Nov 17, 2025
f6fdb9b
CDA-45 - moved some non-ts-specific offset conversions and getter int…
rma-bryson Nov 17, 2025
d48b963
CDA-45 - Cleaning up code.
rma-bryson Dec 1, 2025
3325951
CDA-45 - fixed timeseries controller after rebase
rma-bryson Dec 1, 2025
47ea71d
CDA-45 - Added authorization heder to location IT to match develop
rma-bryson Dec 1, 2025
c4ee10e
CDA-45 - Updates test that failed with datum query param as we now su…
rma-bryson Dec 2, 2025
7bf8f21
CDA-45 - Removed unnecessary authorization header in GET test. remove…
rma-bryson Dec 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 87 additions & 10 deletions cwms-data-api/src/main/java/cwms/cda/api/TimeSeriesController.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,61 @@
package cwms.cda.api;

import static com.codahale.metrics.MetricRegistry.name;
import static cwms.cda.api.Controllers.*;
import static cwms.cda.api.Controllers.BEGIN;
import static cwms.cda.api.Controllers.CREATE;
import static cwms.cda.api.Controllers.CREATE_AS_LRTS;
import static cwms.cda.api.Controllers.CURSOR;
import static cwms.cda.api.Controllers.DATUM;
import static cwms.cda.api.Controllers.DELETE;
import static cwms.cda.api.Controllers.END;
import static cwms.cda.api.Controllers.END_TIME_INCLUSIVE;
import static cwms.cda.api.Controllers.FORMAT;
import static cwms.cda.api.Controllers.GET_ALL;
import static cwms.cda.api.Controllers.GET_ONE;
import static cwms.cda.api.Controllers.INCLUDE_ENTRY_DATE;
import static cwms.cda.api.Controllers.MAX_VERSION;
import static cwms.cda.api.Controllers.NAME;
import static cwms.cda.api.Controllers.NOT_SUPPORTED_YET;
import static cwms.cda.api.Controllers.OFFICE;
import static cwms.cda.api.Controllers.OVERRIDE_PROTECTION;
import static cwms.cda.api.Controllers.PAGE;
import static cwms.cda.api.Controllers.PAGE_SIZE;
import static cwms.cda.api.Controllers.RESULTS;
import static cwms.cda.api.Controllers.SIZE;
import static cwms.cda.api.Controllers.START_TIME_INCLUSIVE;
import static cwms.cda.api.Controllers.STATUS_200;
import static cwms.cda.api.Controllers.STATUS_400;
import static cwms.cda.api.Controllers.STATUS_404;
import static cwms.cda.api.Controllers.STATUS_501;
import static cwms.cda.api.Controllers.STORE_RULE;
import static cwms.cda.api.Controllers.TIMESERIES;
import static cwms.cda.api.Controllers.TIMEZONE;
import static cwms.cda.api.Controllers.TIME_FORMAT_DESC;
import static cwms.cda.api.Controllers.UNIT;
import static cwms.cda.api.Controllers.UNITS;
import static cwms.cda.api.Controllers.UPDATE;
import static cwms.cda.api.Controllers.VERSION;
import static cwms.cda.api.Controllers.VERSION_DATE;
import static cwms.cda.api.Controllers.addDeprecatedContentTypeWarning;
import static cwms.cda.api.Controllers.queryParamAsClass;
import static cwms.cda.api.Controllers.queryParamAsZdt;
import static cwms.cda.api.Controllers.requiredParam;
import static cwms.cda.api.Controllers.requiredZdt;

import com.codahale.metrics.Histogram;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import cwms.cda.api.enums.UnitSystem;
import cwms.cda.api.errors.CdaError;
import cwms.cda.api.errors.NotFoundException;
import cwms.cda.data.dao.JooqDao;
import cwms.cda.data.dao.StoreRule;
import cwms.cda.data.dao.TimeSeriesDao;
import cwms.cda.data.dao.TimeSeriesDaoImpl;
import cwms.cda.data.dao.TimeSeriesDeleteOptions;
import cwms.cda.data.dao.TimeSeriesRequestParameters;
import cwms.cda.data.dao.TimeSeriesVerticalDatumConverter;
import cwms.cda.data.dao.VerticalDatum;
import cwms.cda.data.dto.TimeSeries;
import cwms.cda.formatters.ContentType;
import cwms.cda.formatters.Formats;
Expand Down Expand Up @@ -118,6 +160,7 @@ public TimeSeriesController(MetricRegistry metrics) {

static {
JavalinValidation.register(StoreRule.class, StoreRule::getStoreRule);
JavalinValidation.register(VerticalDatum.class, VerticalDatum::getVerticalDatum);
}

private Timer.Context markAndTime(String subject) {
Expand Down Expand Up @@ -147,7 +190,16 @@ private Timer.Context markAndTime(String subject) {
@OpenApiParam(name = STORE_RULE, type = StoreRule.class, description = STORE_RULE_DESC),
@OpenApiParam(name = OVERRIDE_PROTECTION, type = Boolean.class, description = "A flag "
+ "to ignore the protected data quality when storing data. 'True' or 'False'"
+ ", default is " + TimeSeriesDaoImpl.OVERRIDE_PROTECTION)
+ ", default is " + TimeSeriesDaoImpl.OVERRIDE_PROTECTION),
@OpenApiParam(name = DATUM, type = VerticalDatum.class, description = "If the provided "
+ "time-series includes an explicit vertical-datum-info attribute "
+ "then it is assumed that the data is in the datum specified by the vertical-datum-info. "
+ "If the input timeseries does not include vertical-datum-info and "
+ "this parameter is not provided it is assumed that the data is in the as-stored "
+ "datum and no conversion is necessary. "
+ "If the input timeseries does not include vertical-datum-info and "
+ "this parameter is provided it is assumed that the data is in the Datum named by the argument "
+ "and should be converted to the as-stored datum before being saved.")
},
method = HttpMethod.POST,
path = "/timeseries",
Expand All @@ -162,12 +214,18 @@ public void create(@NotNull Context ctx) {
boolean overrideProtection = ctx.queryParamAsClass(OVERRIDE_PROTECTION, Boolean.class)
.getOrDefault(TimeSeriesDaoImpl.OVERRIDE_PROTECTION);

VerticalDatum vd = ctx.queryParamAsClass(DATUM, VerticalDatum.class)
.getOrDefault(null);

try (final Timer.Context ignored = markAndTime(CREATE)) {
DSLContext dsl = getDslContext(ctx);

TimeSeriesDao dao = getTimeSeriesDao(dsl);
TimeSeries timeSeries = deserializeTimeSeries(ctx);
dao.create(timeSeries, createAsLrts, storeRule, overrideProtection);

vd = TimeSeriesVerticalDatumConverter.getVerticalDatum(timeSeries).orElse(vd);

dao.create(timeSeries, createAsLrts, storeRule, overrideProtection, vd);
ctx.status(HttpServletResponse.SC_OK);
} catch (DataAccessException | IOException ex) {
CdaError re = new CdaError("Internal Error");
Expand Down Expand Up @@ -435,11 +493,6 @@ public void getAll(@NotNull Context ctx) {

if (version != null && version.equals("2")) {

if (datum != null) {
throw new IllegalArgumentException(String.format("Datum is not supported for:%s and %s",
Formats.JSONV2, Formats.XMLV2));
}

String office = requiredParam(ctx, OFFICE);
TimeSeriesRequestParameters requestParameters = new TimeSeriesRequestParameters.Builder()
.withNames(names)
Expand All @@ -453,6 +506,12 @@ public void getAll(@NotNull Context ctx) {
.build();
TimeSeries ts = dao.getTimeseries(cursor, pageSize, requestParameters);

if(datum != null) { //this will be null for non-elevation ts
// user has requested a specific vertical datum
VerticalDatum vd = VerticalDatum.valueOf(datum); // the users request
ts = TimeSeriesVerticalDatumConverter.convertToVerticalDatum(ts, vd);
}

results = Formats.format(contentType, ts);

ctx.status(HttpServletResponse.SC_OK);
Expand Down Expand Up @@ -482,6 +541,11 @@ public void getAll(@NotNull Context ctx) {
}
addDeprecatedContentTypeWarning(ctx, contentType);
requestResultSize.update(results.length());
} catch (NotFoundException e) {
CdaError re = new CdaError("Not found.");
logger.log(Level.WARNING, re.toString(), e);
ctx.status(HttpServletResponse.SC_NOT_FOUND);
ctx.json(re);
} catch (IllegalArgumentException ex) {
CdaError re = new CdaError("Invalid arguments supplied");
logger.log(Level.SEVERE, re.toString(), ex);
Expand Down Expand Up @@ -542,7 +606,16 @@ public void getOne(@NotNull Context ctx, @NotNull String id) {
@OpenApiParam(name = CREATE_AS_LRTS, type = Boolean.class, description = ""),
@OpenApiParam(name = STORE_RULE, type = StoreRule.class, description = STORE_RULE_DESC),
@OpenApiParam(name = OVERRIDE_PROTECTION, type = Boolean.class, description =
"A flag to ignore the protected data quality when storing data. \"'true' or 'false'\"")
"A flag to ignore the protected data quality when storing data. \"'true' or 'false'\""),
@OpenApiParam(name = DATUM, type = VerticalDatum.class, description = "If the provided "
+ "time-series includes an explicit vertical-datum-info attribute "
+ "then it is assumed that the data is in the datum specified by the vertical-datum-info. "
+ "If the input timeseries does not include vertical-datum-info and "
+ "this parameter is not provided it is assumed that the data is in the as-stored "
+ "datum and no conversion is necessary. "
+ "If the input timeseries does not include vertical-datum-info and "
+ "this parameter is provided it is assumed that the data is in the Datum named by the argument "
+ "and should be converted to the as-stored datum before being saved.")
},
method = HttpMethod.PATCH,
path = "/timeseries/{timeseries}",
Expand All @@ -563,7 +636,11 @@ public void update(@NotNull Context ctx, @NotNull String id) {
boolean overrideProtection = ctx.queryParamAsClass(OVERRIDE_PROTECTION, Boolean.class)
.getOrDefault(TimeSeriesDaoImpl.OVERRIDE_PROTECTION);

dao.store(timeSeries, createAsLrts, storeRule, overrideProtection);
VerticalDatum vd = ctx.queryParamAsClass(DATUM, VerticalDatum.class)
.getOrDefault(null);
vd = TimeSeriesVerticalDatumConverter.getVerticalDatum(timeSeries).orElse(vd);

dao.store(timeSeries, createAsLrts, storeRule, overrideProtection, vd);

ctx.status(HttpServletResponse.SC_OK);
} catch (DataAccessException | IOException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public interface TimeSeriesDao {
void create(TimeSeries input);

void create(TimeSeries input,
boolean createAsLrts, StoreRule replaceAll, boolean overrideProtection);
boolean createAsLrts, StoreRule replaceAll, boolean overrideProtection, VerticalDatum vd);

void store(TimeSeries timeSeries, Timestamp versionDate);

void store(TimeSeries timeSeries, boolean createAsLrts,
StoreRule replaceAll, boolean overrideProtection);
StoreRule replaceAll, boolean overrideProtection, VerticalDatum vd);

void delete(String officeId, String tsId, TimeSeriesDeleteOptions options);

Expand Down
Loading
Loading