Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CWMSVue 594: Updated TS office ID handling and conditioning #968

Merged
merged 3 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public List<TimeSeriesGroup> getTimeSeriesGroups(String officeId, String groupOf
whereCond = AV_TS_CAT_GRP.AV_TS_CAT_GRP.GRP_DB_OFFICE_ID.eq(officeId);
}

return getTimeSeriesGroupsWhere(whereCond, groupOfficeId, categoryOfficeId);
return getTimeSeriesGroupsWhere(whereCond, officeId, groupOfficeId, categoryOfficeId);
adamkorynta marked this conversation as resolved.
Show resolved Hide resolved
}

public List<TimeSeriesGroup> getTimeSeriesGroups(String officeId, String groupOfficeId, String categoryOfficeId,
Expand All @@ -89,7 +89,7 @@ public List<TimeSeriesGroup> getTimeSeriesGroups(String officeId, String groupOf
}

if (includeAssigned) {
return getTimeSeriesGroupsWhere(whereCond, groupOfficeId, categoryOfficeId);
return getTimeSeriesGroupsWhere(whereCond, officeId, groupOfficeId, categoryOfficeId);
} else {
return getTimeSeriesGroupsWithoutAssigned(whereCond);
}
Expand All @@ -99,12 +99,12 @@ public List<TimeSeriesGroup> getTimeSeriesGroups(String officeId, String groupOf

public List<TimeSeriesGroup> getTimeSeriesGroups(String officeId, String groupOfficeId, String categoryOfficeId,
String categoryId, String groupId) {
return getTimeSeriesGroupsWhere(buildWhereCondition(groupOfficeId, categoryId, groupId), officeId,
return getTimeSeriesGroupsWhere(buildWhereCondition(categoryId, groupId), officeId, 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 +125,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 +229,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
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ void test_group_CWMS() {
given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept("application/json")
.queryParam("office", CWMS_OFFICE)
.queryParam(CATEGORY_OFFICE_ID, CWMS_OFFICE)
.queryParam(GROUP_OFFICE_ID, CWMS_OFFICE)
.when()
.get("/timeseries/group")
.then()
Expand Down Expand Up @@ -396,21 +397,7 @@ void test_create_read_delete_agency_aliases_same_name() throws Exception {
.assertThat()
.statusCode(is(HttpServletResponse.SC_CREATED));
//Create Group 2
groupXml = Formats.format(contentType, group2);
given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept(Formats.JSON)
.contentType(Formats.JSON)
.body(groupXml)
.header("Authorization", user.toHeaderValue())
.when()
.redirects().follow(true)
.redirects().max(3)
.post("/timeseries/group")
.then()
.log().ifValidationFails(LogDetail.ALL,true)
.assertThat()
.statusCode((is(HttpServletResponse.SC_CREATED)));
loadSqlDataFromResource("cwms/cda/data/sql/create_test_group2.sql");
// Read
given()
.log().ifValidationFails(LogDetail.ALL,true)
Expand Down Expand Up @@ -505,22 +492,7 @@ void test_create_read_delete_agency_aliases_same_name() throws Exception {
.assertThat()
.statusCode(is(HttpServletResponse.SC_NO_CONTENT));
//Delete Group
given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept(Formats.JSON)
.contentType(Formats.JSON)
.header("Authorization", user.toHeaderValue())
.queryParam(OFFICE, officeId2)
.queryParam(CATEGORY_ID, cat.getId())
.queryParam(CASCADE_DELETE, "true")
.when()
.redirects().follow(true)
.redirects().max(3)
.delete("/timeseries/group/" + group2.getId())
.then()
.log().ifValidationFails(LogDetail.ALL,true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_NO_CONTENT));
loadSqlDataFromResource("cwms/cda/data/sql/delete_test_group2.sql");

//Read Empty
given()
Expand Down Expand Up @@ -604,7 +576,7 @@ void test_create_read_delete_same_names_different_offices() throws Exception {
.accept(Formats.JSON)
.contentType(Formats.JSON)
.body(categoryXml)
.header("Authorization", user.toHeaderValue())
.header("Authorization", user2.toHeaderValue())
.queryParam(OFFICE, officeId2)
.when()
.redirects().follow(true)
Expand All @@ -631,21 +603,7 @@ void test_create_read_delete_same_names_different_offices() throws Exception {
.assertThat()
.statusCode(is(HttpServletResponse.SC_CREATED));
//Create Group 2
groupXml = Formats.format(contentType, group2);
given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept(Formats.JSON)
.contentType(Formats.JSON)
.body(groupXml)
.header("Authorization", user.toHeaderValue())
.when()
.redirects().follow(true)
.redirects().max(3)
.post("/timeseries/group")
.then()
.log().ifValidationFails(LogDetail.ALL,true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_CREATED));
loadSqlDataFromResource("cwms/cda/data/sql/create_test_group.sql");
//Read
given()
.log().ifValidationFails(LogDetail.ALL,true)
Expand Down Expand Up @@ -704,22 +662,7 @@ void test_create_read_delete_same_names_different_offices() throws Exception {
.assertThat()
.statusCode(is(HttpServletResponse.SC_NO_CONTENT));
//Delete Group
given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept(Formats.JSON)
.contentType(Formats.JSON)
.header("Authorization", user.toHeaderValue())
.queryParam(OFFICE, officeId2)
.queryParam(CATEGORY_ID, cat2.getId())
.queryParam(CASCADE_DELETE, "true")
.when()
.redirects().follow(true)
.redirects().max(3)
.delete("/timeseries/group/" + group2.getId())
.then()
.log().ifValidationFails(LogDetail.ALL,true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_NO_CONTENT));
loadSqlDataFromResource("cwms/cda/data/sql/delete_test_group.sql");

//Read Empty
given()
Expand Down Expand Up @@ -1154,7 +1097,7 @@ void test_patch_permissions_CWMS() throws Exception {
.log().ifValidationFails(LogDetail.ALL, true)
.accept(Formats.JSONV1)
.contentType(Formats.JSONV1)
.queryParam(OFFICE, CWMS_OFFICE)
.queryParam(OFFICE, officeId)
.queryParam(GROUP_OFFICE_ID, CWMS_OFFICE)
.queryParam(CATEGORY_OFFICE_ID, CWMS_OFFICE)
.when()
Expand Down Expand Up @@ -1267,7 +1210,7 @@ void test_patch_permissions_CWMS_with_replacement() throws Exception {
.log().ifValidationFails(LogDetail.ALL, true)
.accept(Formats.JSONV1)
.contentType(Formats.JSONV1)
.queryParam(OFFICE, CWMS_OFFICE)
.queryParam(OFFICE, officeId)
.queryParam(GROUP_OFFICE_ID, CWMS_OFFICE)
.queryParam(CATEGORY_OFFICE_ID, CWMS_OFFICE)
.when()
Expand Down Expand Up @@ -1372,7 +1315,7 @@ void test_patch_district_permission() throws Exception {
.accept(Formats.JSONV1)
.contentType(Formats.JSONV1)
.header("Authorization", user.toHeaderValue())
.queryParam(OFFICE, CWMS_OFFICE)
.queryParam(OFFICE, officeId)
.queryParam(GROUP_OFFICE_ID, CWMS_OFFICE)
.queryParam(CATEGORY_OFFICE_ID, CWMS_OFFICE)
.when()
Expand All @@ -1387,4 +1330,135 @@ void test_patch_district_permission() throws Exception {
.body("assigned-time-series.size()", equalTo(1))
.body("assigned-time-series[0].timeseries-id", equalTo(tsId));
}

@Test
void testRetrieveOfficeParams() throws Exception {
String officeId = user.getOperatingOffice();
String timeSeriesId = "Alder Springs.Precip-Cumulative.Inst.15Minutes.0.raw-cda";
createLocation(timeSeriesId.split("\\.")[0],true,officeId);
TimeSeriesCategory cat = new TimeSeriesCategory(CWMS_OFFICE, "Default", "Default");
TimeSeriesGroup group = new TimeSeriesGroup(cat, officeId, "test_create_read_delete", "IntegrationTesting",
"sharedTsAliasId", timeSeriesId);
List<AssignedTimeSeries> assignedTimeSeries = group.getAssignedTimeSeries();

BigDecimal tsCode = getTsCode(officeId, timeSeriesId);
assignedTimeSeries.add(new AssignedTimeSeries(officeId,timeSeriesId, tsCode, "AliasId", timeSeriesId, 1));
ContentType contentType = Formats.parseHeader(Formats.JSON, TimeSeriesCategory.class);
String groupXml = Formats.format(contentType, group);
//Create Group
given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept(Formats.JSON)
.contentType(Formats.JSON)
.body(groupXml)
.header("Authorization", user.toHeaderValue())
.queryParam(FAIL_IF_EXISTS, false)
.when()
.redirects().follow(true)
.redirects().max(3)
.post("/timeseries/group")
.then()
.log().ifValidationFails(LogDetail.ALL,true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_CREATED));
//Read with specified office
given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept(Formats.JSON)
.contentType(Formats.JSON)
.queryParam(OFFICE, officeId)
.queryParam(CATEGORY_OFFICE_ID, CWMS_OFFICE)
.queryParam(GROUP_OFFICE_ID, officeId)
.queryParam(CATEGORY_ID, group.getTimeSeriesCategory().getId())
.when()
.redirects().follow(true)
.redirects().max(3)
.get("/timeseries/group/" + group.getId())
.then()
.log().ifValidationFails(LogDetail.ALL,true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_OK))
.body("office-id", equalTo(group.getOfficeId()))
.body("id", equalTo(group.getId()))
.body("description", equalTo(group.getDescription()))
.body("assigned-time-series[0].timeseries-id", equalTo(timeSeriesId))
.body("assigned-time-series[0].alias-id", equalTo("AliasId"))
.body("assigned-time-series[0].ref-ts-id", equalTo(timeSeriesId));

//Read without specified office
given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept(Formats.JSON)
.contentType(Formats.JSON)
.queryParam(CATEGORY_OFFICE_ID, CWMS_OFFICE)
.queryParam(GROUP_OFFICE_ID, officeId)
.queryParam(CATEGORY_ID, group.getTimeSeriesCategory().getId())
.when()
.redirects().follow(true)
.redirects().max(3)
.get("/timeseries/group/" + group.getId())
.then()
.log().ifValidationFails(LogDetail.ALL,true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_OK))
.body("office-id", equalTo(group.getOfficeId()))
.body("id", equalTo(group.getId()))
.body("description", equalTo(group.getDescription()))
.body("assigned-time-series[0].timeseries-id", equalTo(timeSeriesId))
.body("assigned-time-series[0].alias-id", equalTo("AliasId"))
.body("assigned-time-series[0].ref-ts-id", equalTo(timeSeriesId));
//Clear Assigned TS
group.getAssignedTimeSeries().clear();
groupXml = Formats.format(contentType, group);
given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept(Formats.JSON)
.contentType(Formats.JSON)
.body(groupXml)
.header("Authorization", user.toHeaderValue())
.queryParam(CATEGORY_ID, group.getTimeSeriesCategory().getId())
.queryParam(REPLACE_ASSIGNED_TS, "true")
.queryParam(OFFICE, group.getOfficeId())
.when()
.redirects().follow(true)
.redirects().max(3)
.patch("/timeseries/group/"+ group.getId())
.then()
.log().ifValidationFails(LogDetail.ALL,true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_OK));
//Delete Group
given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept(Formats.JSON)
.contentType(Formats.JSON)
.header("Authorization", user.toHeaderValue())
.queryParam(OFFICE, officeId)
.queryParam(CATEGORY_ID, cat.getId())
.when()
.redirects().follow(true)
.redirects().max(3)
.delete("/timeseries/group/" + group.getId())
.then()
.log().ifValidationFails(LogDetail.ALL,true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_NO_CONTENT));

//Read Empty
given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept(Formats.JSON)
.contentType(Formats.JSON)
.queryParam(OFFICE, officeId)
.queryParam(GROUP_OFFICE_ID, officeId)
.queryParam(CATEGORY_OFFICE_ID, officeId)
.when()
.redirects().follow(true)
.redirects().max(3)
.get("/timeseries/group/" + group.getId())
.then()
.assertThat()
.log().ifValidationFails(LogDetail.ALL,true)
.statusCode(is(HttpServletResponse.SC_NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
begin
-- create a group at CWMS in the mew category
cwms_ts.store_ts_group('TestCategory2',
'test_create_read_delete',
'IntegrationTesting','F','T',
'sharedTsAliasId',
'Alder Springs.Precip-Cumulative.Inst.15Minutes.0.raw-cda',
'SWT');

end;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
begin

-- create a group at CWMS in the mew category
cwms_ts.store_ts_group('Agency Aliases',
'test_create_read_delete',
'IntegrationTesting','F','T',
'sharedTsAliasId',
'Alder Springs.Precip-Cumulative.Inst.15Minutes.0.raw-cda',
'SWT');

end;
Loading
Loading