Skip to content

Commit

Permalink
Updated based on Adam's feedback. Added error when attempting to stor…
Browse files Browse the repository at this point in the history
…e values with data entry date
  • Loading branch information
zack-rma committed Dec 19, 2024
1 parent 9ce5604 commit b7bfbf3
Show file tree
Hide file tree
Showing 5 changed files with 408 additions and 347 deletions.
34 changes: 19 additions & 15 deletions cwms-data-api/src/main/java/cwms/cda/api/TimeSeriesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ private Timer.Context markAndTime(String subject) {

@OpenApi(
description = "Used to create and save time-series data. Data to be stored must have "
+ "time stamps in UTC represented as epoch milliseconds ",
+ "time stamps in UTC represented as epoch milliseconds. If data entry date is included in the "
+ "request, it will be dropped. ",
requestBody = @OpenApiRequestBody(
content = {
@OpenApiContent(from = TimeSeries.class, type = Formats.JSONV2),
Expand Down Expand Up @@ -162,10 +163,8 @@ public void create(@NotNull Context ctx) {
DSLContext dsl = getDslContext(ctx);

TimeSeriesDao dao = getTimeSeriesDao(dsl);
TimeSeries timeSeries = deserializeTimeSeries(ctx);
if (timeSeries instanceof TimeSeriesWithDataEntryDate) {
throw new IllegalArgumentException("Data Entry Date is not allowed in the request when storing data");
}
TimeSeriesWithDataEntryDate timeSeries = deserializeTimeSeries(ctx);
checkForEntryDate(timeSeries);
dao.create(timeSeries, createAsLrts, storeRule, overrideProtection);
ctx.status(HttpServletResponse.SC_OK);
} catch (DataAccessException ex) {
Expand Down Expand Up @@ -348,8 +347,8 @@ public void delete(@NotNull Context ctx, @NotNull String timeseries) {
+ "\n* `json` (default)"),
@OpenApiParam(name = INCLUDE_ENTRY_DATE, type = Boolean.class, description = "Specifies "
+ "whether to include the data entry date of each value in the response. Including the data entry "
+ "date will increase the size of the array containing each data value from three to four."
+ " Default is false."),
+ "date will increase the size of the array containing each data value from three to four, "
+ "changing the format of the response. Default is false."),
@OpenApiParam(name = PAGE, description = "This end point can return large amounts "
+ "of data as a series of pages. This parameter is used to describes the "
+ "current location in the response stream. This is an opaque "
Expand Down Expand Up @@ -532,11 +531,8 @@ public void update(@NotNull Context ctx, @NotNull String id) {
DSLContext dsl = getDslContext(ctx);

TimeSeriesDao dao = getTimeSeriesDao(dsl);
TimeSeries timeSeries = deserializeTimeSeries(ctx);
if (timeSeries instanceof TimeSeriesWithDataEntryDate) {
throw new IllegalArgumentException("Data Entry Date is not allowed in the request when storing data");
}

TimeSeriesWithDataEntryDate timeSeries = deserializeTimeSeries(ctx);
checkForEntryDate(timeSeries);
boolean createAsLrts = ctx.queryParamAsClass(CREATE_AS_LRTS, Boolean.class)
.getOrDefault(false);
StoreRule storeRule = ctx.queryParamAsClass(STORE_RULE, StoreRule.class)
Expand All @@ -554,10 +550,18 @@ public void update(@NotNull Context ctx, @NotNull String id) {
}
}

private TimeSeries deserializeTimeSeries(Context ctx) {
private TimeSeriesWithDataEntryDate deserializeTimeSeries(Context ctx) {
String contentTypeHeader = ctx.req.getContentType();
ContentType contentType = Formats.parseHeader(contentTypeHeader, TimeSeries.class);
return Formats.parseContent(contentType, ctx.bodyAsInputStream(), TimeSeries.class);
ContentType contentType = Formats.parseHeader(contentTypeHeader, TimeSeriesWithDataEntryDate.class);
return Formats.parseContent(contentType, ctx.bodyAsInputStream(), TimeSeriesWithDataEntryDate.class);
}

private void checkForEntryDate(TimeSeriesWithDataEntryDate timeSeries) {
for (TimeSeries.Record rec : timeSeries.getValues()) {
if (((TimeSeriesWithDataEntryDate.Record) rec).getDataEntryDate() != null) {
throw new IllegalArgumentException("Data Entry Date is not allowed in the request when storing data");
}
}
}

/**
Expand Down
5 changes: 3 additions & 2 deletions cwms-data-api/src/main/java/cwms/cda/data/dto/TimeSeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ public VersionType getDateVersionType() {
description = "The columns of the time-series data array returned, this property is used to describe "
+ "the data structure of the records array. Contains [name, ordinal, datatype]. "
+ "Name corresponds to the variable described by the data, "
+ "ordinal is the order of the column in the list returned (starting at index 1), "
+ "ordinal is the order of the column in the data value array returned (starts at index 1), "
+ "and datatype is the class name of the data type for the variable. Since the records array "
+ "can be of variable length, the column index value is used to identify the data in the array.",
+ "can be of variable length, the column index value is used to identify the position of the "
+ "data in the array.",
accessMode = AccessMode.READ_ONLY)
public List<Column> getValueColumnsJSON() {
return getColumnDescriptor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public TimeSeriesWithDataEntryDate(TimeSeries timeSeries) {
valuesWithEntryDate = new ArrayList<>();
}

public TimeSeriesWithDataEntryDate(String page, int pageSize, Integer total, String name, String officeId, ZonedDateTime begin,
ZonedDateTime end, String units, Duration interval, VerticalDatumInfo info, Long intervalOffset,
String timeZone, ZonedDateTime versionDate, VersionType dateVersionType) {
public TimeSeriesWithDataEntryDate(String page, int pageSize, Integer total, String name, String officeId,
ZonedDateTime begin, ZonedDateTime end, String units, Duration interval, VerticalDatumInfo info,
Long intervalOffset, String timeZone, ZonedDateTime versionDate, VersionType dateVersionType) {
super(page, pageSize, total, name, officeId, begin, end, units, interval, info, intervalOffset,
timeZone, versionDate, dateVersionType);
valuesWithEntryDate = new ArrayList<>();
Expand All @@ -93,6 +93,7 @@ public void addValue(Timestamp dateTime, Double value, int qualityCode, Timestam
}
}

@JsonProperty(value = "value-columns")
@Override
public List<Column> getValueColumnsJSON() {
return getColumnDescriptorWithEntryDate();
Expand Down
Loading

0 comments on commit b7bfbf3

Please sign in to comment.