Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 12 additions & 1 deletion cwms-data-api/src/main/java/cwms/cda/api/CatalogController.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class CatalogController implements CrudHandler {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String TAG = "Catalog";
public static final boolean INCLUDE_EXTENTS_DEFAULT = true;
public static final boolean INCLUDE_VERSIONS_DEFAULT = true;
public static final boolean EXCLUDE_EMPTY_DEFAULT = true;

private final MetricRegistry metrics;
Expand Down Expand Up @@ -133,6 +134,13 @@ public void getAll(Context ctx) {
+ "extents. Only valid for TIMESERIES. Note: This parameter is "
+ "unsupported when dataset is Locations."
+ "Default is " + INCLUDE_EXTENTS_DEFAULT + "."),
@OpenApiParam(name = INCLUDE_VERSIONS, type = Boolean.class,
description = "Whether the returned catalog entries should include timeseries "
+ "versions in the extents block. "
+ "Only used when include-extents is enabled, otherwise it is ignored. "
+ "Only valid for TIMESERIES. Note: This parameter is "
+ "unsupported when dataset is Locations."
+ "Default is " + INCLUDE_VERSIONS_DEFAULT + "."),
@OpenApiParam(name = EXCLUDE_EMPTY, type = Boolean.class,
description = "Specifies "
+ "whether Timeseries that have empty extents "
Expand Down Expand Up @@ -245,6 +253,8 @@ public void getOne(@NotNull Context ctx, @NotNull String dataSet) {

boolean includeExtents = ctx.queryParamAsClass(INCLUDE_EXTENTS, Boolean.class)
.getOrDefault(INCLUDE_EXTENTS_DEFAULT);
boolean includeVersions = ctx.queryParamAsClass(INCLUDE_VERSIONS, Boolean.class)
.getOrDefault(INCLUDE_VERSIONS_DEFAULT);
boolean excludeExtents = ctx.queryParamAsClass(EXCLUDE_EMPTY, Boolean.class)
.getOrDefault(EXCLUDE_EMPTY_DEFAULT);

Expand All @@ -257,6 +267,7 @@ public void getOne(@NotNull Context ctx, @NotNull String dataSet) {
.withTsGroupLike(tsGroupLike)
.withBoundingOfficeLike(boundingOfficeLike)
.withIncludeExtents(includeExtents)
.withIncludeVersions(includeVersions)
.withExcludeEmpty(excludeExtents)
.withLocationKind(locationKind)
.withLocationType(locationType)
Expand All @@ -268,7 +279,7 @@ public void getOne(@NotNull Context ctx, @NotNull String dataSet) {
} else if (LOCATIONS.equalsIgnoreCase(valDataSet)) {

warnAboutNotSupported(ctx, new String[]{TIMESERIES_CATEGORY_LIKE,
TIMESERIES_GROUP_LIKE, EXCLUDE_EMPTY, INCLUDE_EXTENTS});
TIMESERIES_GROUP_LIKE, EXCLUDE_EMPTY, INCLUDE_EXTENTS, INCLUDE_VERSIONS});

CatalogRequestParameters parameters = new CatalogRequestParameters.Builder()
.withUnitSystem(unitSystem)
Expand Down
1 change: 1 addition & 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 @@ -217,6 +217,7 @@ public final class Controllers {
public static final String DESIGNATOR = "designator";
public static final String DESIGNATOR_MASK = "designator-mask";
public static final String INCLUDE_EXTENTS = "include-extents";
public static final String INCLUDE_VERSIONS = "include-versions";
public static final String EXCLUDE_EMPTY = "exclude-empty";
public static final String DEFAULT_VALUE = "default-value";
public static final String CATEGORY = "category";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class CatalogRequestParameters {
private final String tsGroupLike;
private final String boundingOfficeLike;
private final boolean includeExtents;
private final boolean includeVersions;
private final boolean excludeEmpty;
private final String locationKind;
private final String locationType;
Expand All @@ -34,6 +35,7 @@ private CatalogRequestParameters(Builder builder) {
this.tsGroupLike = builder.tsGroupLike;
this.boundingOfficeLike = builder.boundingOfficeLike;
this.includeExtents = builder.includeExtents;
this.includeVersions = builder.includeVersions;
this.excludeEmpty = builder.excludeEmpty;
this.locationKind = builder.locationKind;
this.locationType = builder.locationType;
Expand All @@ -54,6 +56,10 @@ public boolean isIncludeExtents() {
return includeExtents;
}

public boolean isIncludeVersions() {
return includeVersions;
}

public String getLocCatLike() {
return locCatLike;
}
Expand Down Expand Up @@ -112,6 +118,7 @@ public static class Builder {
String tsGroupLike;
String boundingOfficeLike;
boolean includeExtents = false;
boolean includeVersions = false;
private boolean excludeEmpty = true;
String locationKind;
String locationType;
Expand Down Expand Up @@ -168,6 +175,11 @@ public Builder withIncludeExtents(boolean includeExtents) {
return this;
}

public Builder withIncludeVersions(boolean includeVersions) {
this.includeVersions = includeVersions;
return this;
}

public Builder withExcludeEmpty(boolean excludeExtents) {
this.excludeEmpty = excludeExtents;
return this;
Expand Down Expand Up @@ -210,6 +222,7 @@ public static Builder from(CatalogRequestParameters params) {
.withTsGroupLike(params.tsGroupLike)
.withBoundingOfficeLike(params.boundingOfficeLike)
.withIncludeExtents(params.includeExtents)
.withIncludeVersions(params.includeVersions)
.withExcludeEmpty(params.excludeEmpty)
.withLocationKind(params.locationKind)
.withLocationType(params.locationType)
Expand Down
63 changes: 50 additions & 13 deletions cwms-data-api/src/main/java/cwms/cda/data/dao/LocationsDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,19 +241,56 @@ public Location getLocation(String locationName, String unitSystem, String offic

Location retVal;
if (includeAliases) {
List<Record> locs = dslContext.select(asterisk())
.from(AV_LOC2.AV_LOC2)
.leftJoin(AV_LOC_ALIAS)
.on(AV_LOC2.AV_LOC2.BASE_LOCATION_ID.eq(AV_LOC_ALIAS.BASE_LOCATION_ID).and(
AV_LOC2.AV_LOC2.LOCATION_CODE.eq(AV_LOC_ALIAS.LOCATION_CODE.cast(Long.class))))
.where(AV_LOC2.AV_LOC2.DB_OFFICE_ID.eq(officeId.toUpperCase())
.and(AV_LOC2.AV_LOC2.UNIT_SYSTEM.equalIgnoreCase(unitSystem)
.and(AV_LOC2.AV_LOC2.LOCATION_ID.equalIgnoreCase(locationName))))
.fetch();
if (locs.isEmpty()) {
throw new NotFoundException("Location not found for office:" + officeId + " and unit "
+ "system:" + unitSystem + " and id:" + locationName);
}
List<Record> locs = dslContext.select(
AV_LOC2.AV_LOC2.LOCATION_CODE,
AV_LOC2.AV_LOC2.BASE_LOCATION_CODE,
AV_LOC2.AV_LOC2.DB_OFFICE_ID,
AV_LOC2.AV_LOC2.BASE_LOCATION_ID,
AV_LOC2.AV_LOC2.SUB_LOCATION_ID,
AV_LOC2.AV_LOC2.LOCATION_ID,
AV_LOC2.AV_LOC2.LOCATION_TYPE,
AV_LOC2.AV_LOC2.UNIT_SYSTEM,
AV_LOC2.AV_LOC2.ELEVATION,
AV_LOC2.AV_LOC2.UNIT_ID,
AV_LOC2.AV_LOC2.VERTICAL_DATUM,
AV_LOC2.AV_LOC2.LONGITUDE,
AV_LOC2.AV_LOC2.LATITUDE,
AV_LOC2.AV_LOC2.HORIZONTAL_DATUM,
AV_LOC2.AV_LOC2.TIME_ZONE_NAME,
AV_LOC2.AV_LOC2.COUNTY_NAME,
AV_LOC2.AV_LOC2.STATE_INITIAL,
AV_LOC2.AV_LOC2.PUBLIC_NAME,
AV_LOC2.AV_LOC2.LONG_NAME,
AV_LOC2.AV_LOC2.DESCRIPTION,
AV_LOC2.AV_LOC2.BASE_LOC_ACTIVE_FLAG,
AV_LOC2.AV_LOC2.LOC_ACTIVE_FLAG,
AV_LOC2.AV_LOC2.LOCATION_KIND_ID,
AV_LOC2.AV_LOC2.MAP_LABEL,
AV_LOC2.AV_LOC2.PUBLISHED_LATITUDE,
AV_LOC2.AV_LOC2.PUBLISHED_LONGITUDE,
AV_LOC2.AV_LOC2.BOUNDING_OFFICE_ID,
AV_LOC2.AV_LOC2.NATION_ID,
AV_LOC2.AV_LOC2.NEAREST_CITY,
AV_LOC2.AV_LOC2.ACTIVE_FLAG,
AV_LOC2.AV_LOC2.ALIASED_ITEM,
AV_LOC2.AV_LOC2.LOC_ALIAS_CATEGORY,
AV_LOC2.AV_LOC2.LOC_ALIAS_GROUP,
AV_LOC2.AV_LOC2.DB_OFFICE_CODE,
AV_LOC_ALIAS.CATEGORY_ID,
AV_LOC_ALIAS.GROUP_ID,
AV_LOC_ALIAS.ALIAS_ID)
.from(AV_LOC2.AV_LOC2)
.leftJoin(AV_LOC_ALIAS)
.on(AV_LOC2.AV_LOC2.BASE_LOCATION_ID.eq(AV_LOC_ALIAS.BASE_LOCATION_ID).and(
AV_LOC2.AV_LOC2.LOCATION_CODE.eq(AV_LOC_ALIAS.LOCATION_CODE.cast(Long.class))))
.where(AV_LOC2.AV_LOC2.DB_OFFICE_ID.eq(officeId.toUpperCase())
.and(AV_LOC2.AV_LOC2.UNIT_SYSTEM.equalIgnoreCase(unitSystem)
.and(AV_LOC2.AV_LOC2.LOCATION_ID.equalIgnoreCase(locationName))))
.fetch();
if (locs.isEmpty()) {
throw new NotFoundException("Location not found for office:" + officeId + " and unit "
+ "system:" + unitSystem + " and id:" + locationName);
}
retVal = buildLocation(null, locs, true);
} else {
Record loc = dslContext.select(AV_LOC.asterisk())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.jooq.impl.DSL.select;
import static org.jooq.impl.DSL.selectDistinct;

import org.jooq.SelectOnConditionStep;
import usace.cwms.db.jooq.codegen.tables.AV_CWMS_TS_ID;
import static org.jooq.impl.DSL.table;
import static usace.cwms.db.jooq.codegen.tables.AV_CWMS_TS_ID2.AV_CWMS_TS_ID2;
Expand Down Expand Up @@ -676,6 +677,7 @@ public Catalog getTimeSeriesCatalog(String page, int pageSize, CatalogRequestPar
.withTsGroupLike(catPage.getTsGroupLike())
.withBoundingOfficeLike(catPage.getBoundingOfficeLike())
.withIncludeExtents(catPage.isIncludeExtents())
.withIncludeExtents(catPage.isIncludeVersions())
.withExcludeEmpty(catPage.isExcludeEmpty())
.build();
}
Expand All @@ -690,7 +692,7 @@ public Catalog getTimeSeriesCatalog(String page, int pageSize, CatalogRequestPar
List<Condition> pagingConditions = buildPagingConditions(cwmsTsIdFields, cursorOffice, cursorTsId);
CommonTableExpression<?> limiter = buildWithClause(cwmsTsIdFields, params, whereConditions, pagingConditions, pageSize, false);
Field<BigDecimal> limiterCode = limiter.field(cwmsTsIdFields.getTsCode());
SelectJoinStep<?> tmpQuery = dsl.with(limiter)
SelectOnConditionStep<?> tmpQuery = dsl.with(limiter)
.select(pageEntryFields)
.from(limiter)
.join(table).on(limiterCode.eq(cwmsTsIdFields.getTsCode()));
Expand All @@ -700,9 +702,11 @@ public Catalog getTimeSeriesCatalog(String page, int pageSize, CatalogRequestPar
tmpQuery = tmpQuery.leftOuterJoin(AV_TS_EXTENTS_UTC)
.on(limiterCode
.eq(AV_TS_EXTENTS_UTC.TS_CODE.coerce(limiterCode)));
if(!params.isIncludeVersions()) {
tmpQuery = tmpQuery.and(AV_TS_EXTENTS_UTC.VERSION_TIME.isNull());
}
}
final SelectSeekStep2<?, String, String> overallQuery = tmpQuery
.orderBy(cwmsTsIdFields.getDbOfficeId(),
final SelectSeekStep2<?, String, String> overallQuery = tmpQuery.orderBy(cwmsTsIdFields.getDbOfficeId(),
cwmsTsIdFields.getCwmsTsId());
logger.atFine().log("%s", lazy(() -> overallQuery.getSQL(ParamType.INLINED)));
Result<?> result = overallQuery.fetch();
Expand All @@ -721,7 +725,8 @@ public Catalog getTimeSeriesCatalog(String page, int pageSize, CatalogRequestPar
.cwmsTsId(row.get(cwmsTsIdFields.getCwmsTsId()))
.units(row.get(cwmsTsIdFields.getUnitId()))
.interval(row.get(cwmsTsIdFields.getIntervalId()))
.intervalOffset(row.get(cwmsTsIdFields.getIntervalUtcOffset()));
.intervalOffset(row.get(cwmsTsIdFields.getIntervalUtcOffset()))
.versioned(parseBool(row.get(cwmsTsIdFields.getVerionFlag())));

builder.timeZone(row.get("TIME_ZONE_ID", String.class));

Expand Down Expand Up @@ -849,6 +854,7 @@ private void updateAliasMapping(Map<String, Set<TimeSeriesAlias>> tsCodeAliasMap
retVal.add(cwmsTsIdFields.getIntervalId());
retVal.add(cwmsTsIdFields.getIntervalUtcOffset());
retVal.add(cwmsTsIdFields.getTimeZoneId());
retVal.add(cwmsTsIdFields.getVerionFlag());
if(cwmsTsIdFields.includesAliases()) {
retVal.add(AV_CWMS_TS_ID2.ALIASED_ITEM);
retVal.add(AV_CWMS_TS_ID2.TS_CODE);
Expand Down Expand Up @@ -985,7 +991,6 @@ private Collection<? extends Condition> buildExtentsConditions(CatalogRequestPar
AV_TS_EXTENTS_UTC.LAST_UPDATE.isNotNull())
);
}

return retval;
}

Expand Down Expand Up @@ -1727,6 +1732,7 @@ private interface FieldMapping {
Field<String> getIntervalId();
Field<BigDecimal> getIntervalUtcOffset();
Field<String> getTimeZoneId();
Field<String> getVerionFlag();
boolean includesAliases();
}

Expand Down Expand Up @@ -1775,6 +1781,11 @@ public Field<String> getTimeZoneId() {
public boolean includesAliases() {
return false;
}

@Override
public Field<String> getVerionFlag() {
return AV_CWMS_TS_ID.AV_CWMS_TS_ID.VERSION_FLAG;
}
}

private static class CwmsTsId2FieldMapping implements FieldMapping {
Expand Down Expand Up @@ -1822,6 +1833,11 @@ public Field<String> getTimeZoneId() {
public boolean includesAliases() {
return true;
}

@Override
public Field<String> getVerionFlag() {
return AV_CWMS_TS_ID2.VERSION_FLAG;
}
}


Expand Down
16 changes: 12 additions & 4 deletions cwms-data-api/src/main/java/cwms/cda/data/dto/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ public static class CatalogPage {
private final String tsGroupLike;
private final String boundingOfficeLike;
private final boolean includeExtents;
private final boolean includeVersions;
private final boolean excludeEmpty;
private int total;
private int pageSize;

public CatalogPage(String page) {
String[] parts = CwmsDTOPaginated.decodeCursor(page, CwmsDTOPaginated.delimiter);

if (parts.length != 12) {
if (parts.length != 13) {
throw new IllegalArgumentException("Invalid Catalog Page Provided, please verify "
+ "you are using a page variable from the catalog endpoint");
}
Expand All @@ -98,9 +99,10 @@ public CatalogPage(String page) {
tsGroupLike = nullOrVal(parts[6]);
boundingOfficeLike = nullOrVal(parts[7]);
includeExtents = Boolean.parseBoolean(parts[8]);
excludeEmpty = Boolean.parseBoolean(parts[9]);
total = Integer.parseInt(parts[10]);
pageSize = Integer.parseInt(parts[11]);
includeVersions = Boolean.parseBoolean(parts[9]);
excludeEmpty = Boolean.parseBoolean(parts[10]);
total = Integer.parseInt(parts[11]);
pageSize = Integer.parseInt(parts[12]);
}


Expand All @@ -118,6 +120,7 @@ public CatalogPage(String curElement, CatalogRequestParameters params) {
this.tsGroupLike = params.getTsGroupLike();
this.boundingOfficeLike = params.getBoundingOfficeLike();
this.includeExtents = params.isIncludeExtents();
this.includeVersions = params.isIncludeVersions();
this.excludeEmpty = params.isExcludeEmpty();
}

Expand Down Expand Up @@ -177,6 +180,10 @@ public boolean isIncludeExtents() {
return includeExtents;
}

public boolean isIncludeVersions() {
return includeVersions;
}

public boolean isExcludeEmpty() {
return excludeEmpty;
}
Expand All @@ -193,6 +200,7 @@ public String toString() {
+ CwmsDTOPaginated.delimiter + tsGroupLike
+ CwmsDTOPaginated.delimiter + boundingOfficeLike
+ CwmsDTOPaginated.delimiter + includeExtents
+ CwmsDTOPaginated.delimiter + includeVersions
+ CwmsDTOPaginated.delimiter + excludeEmpty
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class TimeseriesCatalogEntry extends CatalogEntry {
@JacksonXmlProperty(localName = "alias")
private Collection<TimeSeriesAlias> aliases;

private boolean versioned = false;

public String getName() {
return this.name;
}
Expand All @@ -60,6 +62,10 @@ public Collection<TimeSeriesAlias> getAliases() {
return aliases;
}

public boolean isVersioned() {
return versioned;
}

private TimeseriesCatalogEntry() {
super(null);
}
Expand All @@ -73,6 +79,7 @@ private TimeseriesCatalogEntry(Builder builder) {
this.timeZone = builder.timeZone;
this.extents = builder.extents;
this.aliases = builder.aliases;
this.versioned = builder.versioned;
}

public String getUnits() {
Expand Down Expand Up @@ -100,6 +107,7 @@ public static class Builder {
private ZonedDateTime latestTime;
private List<TimeSeriesExtents> extents = null;
private Collection<TimeSeriesAlias> aliases = null;
private boolean versioned = false;

public Builder officeId(final String office) {
this.office = office;
Expand Down Expand Up @@ -162,6 +170,11 @@ public Builder withAliases(final Collection<TimeSeriesAlias> aliases) {
return this;
}

public Builder versioned(boolean versioned) {
this.versioned = versioned;
return this;
}

public TimeseriesCatalogEntry build() {
return new TimeseriesCatalogEntry(this);
}
Expand Down
Loading
Loading