Skip to content

Commit

Permalink
Updated version date input handling
Browse files Browse the repository at this point in the history
  • Loading branch information
zack-rma committed Nov 4, 2024
1 parent d494dab commit 43ad339
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
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.queryParamAsInstant;
import static cwms.cda.api.Controllers.requiredInstant;
import static cwms.cda.api.Controllers.requiredParam;
import static cwms.cda.data.dao.JooqDao.getDslContext;
Expand Down Expand Up @@ -85,8 +86,9 @@ public TimeSeriesProfileInstanceController(MetricRegistry metrics) {
+ "the time zone of the values of the begin and end fields (unless "
+ "otherwise specified). If this field is not specified, the default time zone "
+ "of UTC shall be used."),
@OpenApiParam(name = VERSION_DATE, type = Instant.class, description = "The version date of the"
+ " time series profile instance. Default is the min or max version date, depending on the maxVersion"),
@OpenApiParam(name = VERSION_DATE, type = Instant.class, description = "The version date of the "
+ "time series profile instance. Accepts ISO8601 formats. 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_TIME_INCLUSIVE, type = Boolean.class, description = "The start inclusive of the"
Expand Down Expand Up @@ -149,9 +151,7 @@ public void handle(@NotNull Context ctx) {
.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.parse(ctx.queryParamAsClass(VERSION_DATE, String.class)
.getOrDefault(null));
Instant versionDate = queryParamAsInstant(ctx, VERSION_DATE);
boolean maxVersion = ctx.queryParamAsClass(MAX_VERSION, boolean.class)
.getOrDefault(false);
String page = ctx.queryParam(PAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public TimeSeriesProfileInstanceCreateController(MetricRegistry metrics) {
+ " time series profile instance. Default is REPLACE_ALL"),
@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.", required = true),
@OpenApiParam(name = VERSION_DATE, type = Instant.class, description = "The version date of the"
+ " time series profile instance. Accepts ISO8601 format.", 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public TimeSeriesProfileInstanceDeleteController(MetricRegistry metrics) {
+ "the time zone of the values of the begin and end fields. If this field is not specified, "
+ "the default time zone of UTC shall be used."),
@OpenApiParam(name = VERSION_DATE, type = Instant.class, description = "The version date of the"
+ " time series profile instance.", required = true),
+ " time series profile instance. Accepts ISO8601 format.", required = true),
@OpenApiParam(name = DATE, type = Instant.class, description = "The first date of the"
+ " time series profile instance.", required = true),
@OpenApiParam(name = OVERRIDE_PROTECTION, type = Boolean.class, description = "Override protection"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void storeTimeSeriesProfileInstance(TimeSeriesProfile timeSeriesProfile,
}

public void storeTimeSeriesProfileInstance(TimeSeriesProfileInstance timeseriesProfileInstance, String versionId,
Instant versionInstant, String storeRule, String overrideProtection) {
Instant versionDate, String storeRule, String overrideProtection) {
connection(dsl, conn -> {
setOffice(conn, timeseriesProfileInstance.getTimeSeriesProfile().getLocationId().getOfficeId());
Map<String, BigInteger> parameterIdToCode = new HashMap<>();
Expand Down Expand Up @@ -143,7 +143,7 @@ public void storeTimeSeriesProfileInstance(TimeSeriesProfileInstance timeseriesP
.getTimeSeriesProfile().getKeyParameter()));
tsProfileData.setUNITS(units);

Timestamp versionTimeStamp = Timestamp.from(versionInstant);
Timestamp versionTimeStamp = Timestamp.from(versionDate);

CWMS_TS_PROFILE_PACKAGE.call_STORE_TS_PROFILE_INSTANCE(using(conn).configuration(),
tsProfileData,
Expand Down Expand Up @@ -342,29 +342,46 @@ public TimeSeriesProfileInstance retrieveTimeSeriesProfileInstance(CwmsId locati
SelectHavingStep<Record1<Integer>> count = dsl.select(countDistinct(VIEW_TSV2.DATE_TIME))
.from(VIEW_TSV2)
.where(finalWhereCondition);
total = Objects.requireNonNull(count.fetchOne()).value1();
try {
total = count.fetchOne().value1();
} catch (NullPointerException e) {
throw new NotFoundException("No time series profile data found for the given parameters");
}
}

// get total number of parameters to for setting fetch size
int totalPars;
SelectHavingStep<Record1<Integer>> count = dsl.select(countDistinct(VIEW_TSV2.PARAMETER_ID))
.from(VIEW_TSV2)
.where(finalWhereCondition);
int totalPars = Objects.requireNonNull(count.fetchOne()).value1();
try {
totalPars = count.fetchOne().value1();
} catch (NullPointerException e) {
throw new NotFoundException("No time series profile data found for the given parameters");
}

// Get the max version date if needed
Timestamp maxVersionDate = null;
if (maxVersion) {
SelectConditionStep<Record1<Timestamp>> maxVer = dsl.select(max(VIEW_TSV2.VERSION_DATE))
.from(VIEW_TSV2)
.where(finalWhereCondition);
maxVersionDate = Objects.requireNonNull(maxVer.fetchOne()).value1();
try {
maxVersionDate = maxVer.fetchOne().value1();
} catch (NullPointerException e) {
throw new NotFoundException("No time series profile data found for the given parameters");
}
}
Timestamp minVersionDate = null;
if (!maxVersion && versionDate == null) {
SelectConditionStep<Record1<Timestamp>> minVer = dsl.select(min(VIEW_TSV2.VERSION_DATE))
.from(VIEW_TSV2)
.where(finalWhereCondition);
minVersionDate = Objects.requireNonNull(minVer.fetchOne()).value1();
try {
minVersionDate = minVer.fetchOne().value1();
} catch (NullPointerException e) {
throw new NotFoundException("No time series profile data found for the given parameters");
}
}

// generate and run query to get the time series profile data
Expand Down Expand Up @@ -682,9 +699,7 @@ private TimeSeriesProfileInstance map(String officeId, String location, String k
builder.withPageFirstDate(timeList.stream().min(Instant::compareTo).orElse(null));
builder.withPageLastDate(timeList.stream().max(Instant::compareTo).orElse(null));
builder.withVersionDate(versionDate);
return builder
.build();

return builder.build();
}

private static int findParameterIndex(List<ParameterColumnInfo> parameterColumnInfoList, long latestTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ public final class TimeSeriesProfileInstance extends CwmsDTOPaginated {
private final Map<Long, List<TimeSeriesData>> timeSeriesList;
private final String locationTimeZone;
private final String version;
@JsonFormat(shape = JsonFormat.Shape.STRING)
private final Instant versionDate;
@JsonFormat(shape = JsonFormat.Shape.STRING)
private final Instant firstDate;
@JsonFormat(shape = JsonFormat.Shape.STRING)
private final Instant lastDate;
@JsonFormat(shape = JsonFormat.Shape.STRING)
private final Instant pageFirstDate;
@JsonFormat(shape = JsonFormat.Shape.STRING)
private final Instant pageLastDate;

private TimeSeriesProfileInstance(Builder builder) {
Expand Down
Loading

0 comments on commit 43ad339

Please sign in to comment.