Skip to content

Commit

Permalink
CWMSVue 594: Updated TS office ID handling and conditioning (#968)
Browse files Browse the repository at this point in the history
Fixed TS office ID handling and DB query conditioning.
  • Loading branch information
zack-rma authored Dec 7, 2024
1 parent 93b41e5 commit 56b85ce
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ private Timer.Context markAndTime(String subject) {
@OpenApi(
queryParams = {
@OpenApiParam(name = OFFICE, description = "Specifies the owning office of the "
+ "timeseries group(s) whose data is to be included in the response. If this "
+ "field is not specified, matching timeseries groups information from all "
+ "offices shall be returned."),
+ "timeseries assigned to the group(s) whose data is to be included in the response. If this "
+ "field is not specified, group information for all assigned TS offices shall be returned."),
@OpenApiParam(name = INCLUDE_ASSIGNED, type = Boolean.class, description = "Include"
+ " the assigned timeseries in the returned timeseries groups. (default: true)"),
@OpenApiParam(name = TIMESERIES_CATEGORY_LIKE, description = "Posix <a href=\"regexp.html\">regular expression</a> "
Expand All @@ -124,7 +123,7 @@ public void getAll(@NotNull Context ctx) {
DSLContext dsl = getDslContext(ctx);

TimeSeriesGroupDao dao = new TimeSeriesGroupDao(dsl);
String office = ctx.queryParam(OFFICE);
String tsOffice = ctx.queryParam(OFFICE);
String groupOffice = ctx.queryParam(GROUP_OFFICE_ID);
String categoryOffice = ctx.queryParam(CATEGORY_OFFICE_ID);

Expand All @@ -136,7 +135,7 @@ Boolean.class, true, metrics, name(TimeSeriesGroupController.class.getName(),
String tsGroupLike = queryParamAsClass(ctx, new String[]{TIMESERIES_GROUP_LIKE},
String.class, null, metrics, name(TimeSeriesGroupController.class.getName(), GET_ALL));

List<TimeSeriesGroup> grps = dao.getTimeSeriesGroups(office, groupOffice, categoryOffice,
List<TimeSeriesGroup> grps = dao.getTimeSeriesGroups(tsOffice, groupOffice, categoryOffice,
includeAssigned, tsCategoryLike, tsGroupLike);
if (grps.isEmpty()) {
CdaError re = new CdaError("No data found for The provided office");
Expand Down Expand Up @@ -164,8 +163,9 @@ Boolean.class, true, metrics, name(TimeSeriesGroupController.class.getName(),
},
queryParams = {
@OpenApiParam(name = OFFICE, required = true, description = "Specifies the "
+ "owning office of the timeseries group whose data is to be included"
+ " in the response."),
+ "owning office of the timeseries assigned to the group whose data is to be included"
+ " in the response. This will limit the assigned timeseries returned to only those"
+ " assigned to the specified office."),
@OpenApiParam(name = CATEGORY_OFFICE_ID, description = "Specifies the owning office of the "
+ "timeseries group category", required = true),
@OpenApiParam(name = GROUP_OFFICE_ID, description = "Specifies the owning office of the "
Expand All @@ -186,7 +186,7 @@ public void getOne(@NotNull Context ctx, @NotNull String groupId) {
DSLContext dsl = getDslContext(ctx);

TimeSeriesGroupDao dao = new TimeSeriesGroupDao(dsl);
String office = ctx.queryParam(OFFICE);
String tsOffice = ctx.queryParam(OFFICE);
String categoryId = ctx.queryParam(CATEGORY_ID);

// Not marked as required to maintain backwards compatibility with existing clients
Expand All @@ -197,7 +197,7 @@ public void getOne(@NotNull Context ctx, @NotNull String groupId) {
ContentType contentType = Formats.parseHeader(formatHeader, TimeSeriesGroup.class);

TimeSeriesGroup group = null;
List<TimeSeriesGroup> timeSeriesGroups = dao.getTimeSeriesGroups(office, groupOffice, categoryOffice,
List<TimeSeriesGroup> timeSeriesGroups = dao.getTimeSeriesGroups(tsOffice, groupOffice, categoryOffice,
categoryId, groupId);
if (timeSeriesGroups != null && !timeSeriesGroups.isEmpty()) {
if (timeSeriesGroups.size() == 1) {
Expand All @@ -208,7 +208,7 @@ public void getOne(@NotNull Context ctx, @NotNull String groupId) {
"Multiple TimeSeriesGroups returned from getTimeSeriesGroups "
+ "for:%s category:%s groupId:%s At most one match was "
+ "expected. Found:%s",
office, categoryId, groupId, timeSeriesGroups);
groupOffice, categoryId, groupId, timeSeriesGroups);
throw new IllegalArgumentException(message);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,19 @@ public List<TimeSeriesGroup> getTimeSeriesGroups() {
return getTimeSeriesGroups(null, null, null);
}

public List<TimeSeriesGroup> getTimeSeriesGroups(String officeId, String groupOfficeId, String categoryOfficeId) {
public List<TimeSeriesGroup> getTimeSeriesGroups(String tsOfficeId, String groupOfficeId, String categoryOfficeId) {
Condition whereCond = DSL.noCondition();
if (officeId != null) {
whereCond = AV_TS_CAT_GRP.AV_TS_CAT_GRP.GRP_DB_OFFICE_ID.eq(officeId);
if (tsOfficeId != null) {
whereCond = AV_TS_CAT_GRP.AV_TS_CAT_GRP.GRP_DB_OFFICE_ID.eq(tsOfficeId);
}

return getTimeSeriesGroupsWhere(whereCond, groupOfficeId, categoryOfficeId);
return getTimeSeriesGroupsWhere(whereCond, tsOfficeId, groupOfficeId, categoryOfficeId);
}

public List<TimeSeriesGroup> getTimeSeriesGroups(String officeId, String groupOfficeId, String categoryOfficeId,
public List<TimeSeriesGroup> getTimeSeriesGroups(String tsOfficeId, String groupOfficeId, String categoryOfficeId,
boolean includeAssigned, String tsCategoryLike, String tsGroupLike) {

Condition whereCond = DSL.noCondition();
if (officeId != null) {
whereCond = whereCond.and(AV_TS_CAT_GRP.AV_TS_CAT_GRP.GRP_DB_OFFICE_ID.eq(officeId));
}

if (tsCategoryLike != null) {
whereCond = whereCond.and(JooqDao.caseInsensitiveLikeRegex(AV_TS_CAT_GRP.AV_TS_CAT_GRP.TS_CATEGORY_ID,
Expand All @@ -89,22 +86,22 @@ public List<TimeSeriesGroup> getTimeSeriesGroups(String officeId, String groupOf
}

if (includeAssigned) {
return getTimeSeriesGroupsWhere(whereCond, groupOfficeId, categoryOfficeId);
return getTimeSeriesGroupsWhere(whereCond, tsOfficeId, groupOfficeId, categoryOfficeId);
} else {
return getTimeSeriesGroupsWithoutAssigned(whereCond);
}

}


public List<TimeSeriesGroup> getTimeSeriesGroups(String officeId, String groupOfficeId, String categoryOfficeId,
public List<TimeSeriesGroup> getTimeSeriesGroups(String tsOfficeId, String groupOfficeId, String categoryOfficeId,
String categoryId, String groupId) {
return getTimeSeriesGroupsWhere(buildWhereCondition(groupOfficeId, categoryId, groupId), officeId,
return getTimeSeriesGroupsWhere(buildWhereCondition(categoryId, groupId), tsOfficeId, groupOfficeId,
categoryOfficeId);
}

@NotNull
private List<TimeSeriesGroup> getTimeSeriesGroupsWhere(Condition whereCond, String groupOfficeId,
private List<TimeSeriesGroup> getTimeSeriesGroupsWhere(Condition whereCond, String tsOfficeId, String groupOfficeId,
String categoryOfficeId) {
AV_TS_CAT_GRP catGrp = AV_TS_CAT_GRP.AV_TS_CAT_GRP;
AV_TS_GRP_ASSGN grpAssgn = AV_TS_GRP_ASSGN.AV_TS_GRP_ASSGN;
Expand All @@ -125,15 +122,20 @@ private List<TimeSeriesGroup> getTimeSeriesGroupsWhere(Condition whereCond, Stri
whereCondGrpCat = whereCondGrpCat.and(catGrp.GRP_DB_OFFICE_ID.eq(groupOfficeId.toUpperCase()));
}

Condition joinCond = catGrp.TS_CATEGORY_ID.eq(grpAssgn.CATEGORY_ID)
.and(catGrp.TS_GROUP_ID.eq(grpAssgn.GROUP_ID));
if (tsOfficeId != null) {
joinCond = joinCond.and(grpAssgn.DB_OFFICE_ID.eq(tsOfficeId));
}

SelectSeekStep1<?, BigDecimal> query = dsl.select(catGrp.CAT_DB_OFFICE_ID,
catGrp.TS_CATEGORY_ID, catGrp.TS_CATEGORY_DESC, catGrp.GRP_DB_OFFICE_ID,
catGrp.TS_GROUP_ID, catGrp.TS_GROUP_DESC, catGrp.SHARED_TS_ALIAS_ID,
catGrp.SHARED_REF_TS_ID, grpAssgn.CATEGORY_ID, grpAssgn.DB_OFFICE_ID,
grpAssgn.GROUP_ID, grpAssgn.TS_ID, grpAssgn.TS_CODE, grpAssgn.ATTRIBUTE,
grpAssgn.ALIAS_ID, grpAssgn.REF_TS_ID, grpAssgn.CATEGORY_OFFICE_ID, grpAssgn.GROUP_OFFICE_ID)
.from(catGrp).leftJoin(grpAssgn)
.on(catGrp.TS_CATEGORY_ID.eq(grpAssgn.CATEGORY_ID)
.and(catGrp.TS_GROUP_ID.eq(grpAssgn.GROUP_ID)))
.on(joinCond)
.where(whereCond)
.and(whereCondGrpCat)
.orderBy(grpAssgn.ATTRIBUTE);
Expand Down Expand Up @@ -224,17 +226,10 @@ private TimeSeriesCategory buildTimeSeriesCategory(Record queryRecord) {
}


private Condition buildWhereCondition(String groupOfficeId, String categoryId, String groupId) {
private Condition buildWhereCondition(String categoryId, String groupId) {
AV_TS_CAT_GRP atcg = AV_TS_CAT_GRP.AV_TS_CAT_GRP;
Condition whereCondition = DSL.noCondition();

if (groupOfficeId != null && !groupOfficeId.isEmpty()) {
//We do not need to filter on the category office id since category ids
//are unique unlike group ids.
//We also don't want to filter on assigned time series' offices since that could leave
//incomplete groups. If that is ever needed, it should be a separate context variable.
whereCondition = whereCondition.and(atcg.GRP_DB_OFFICE_ID.eq(groupOfficeId));
}

if (categoryId != null && !categoryId.isEmpty()) {
whereCondition = whereCondition.and(atcg.TS_CATEGORY_ID.eq(categoryId));
Expand Down
Loading

0 comments on commit 56b85ce

Please sign in to comment.