Skip to content

Commit

Permalink
CWMSVue 594 - Added location office parameter to LocationGroup getAll (
Browse files Browse the repository at this point in the history
…#954)

Added location office parameter to LocationGroup getAll
  • Loading branch information
zack-rma authored Nov 20, 2024
1 parent 4de9156 commit 1d0cddb
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

public class LocationGroupController implements CrudHandler {
public static final Logger logger = Logger.getLogger(LocationGroupController.class.getName());
private static final String LOCATION_OFFICE_ID = "location-office-id";

public static final String TAG = "Location Groups";
private final MetricRegistry metrics;
Expand All @@ -76,9 +77,10 @@ private Timer.Context markAndTime(String subject) {
return Controllers.markAndTime(metrics, getClass().getName(), subject);
}

@OpenApi(queryParams = {
@OpenApi(
queryParams = {
@OpenApiParam(name = OFFICE, description = "Specifies the owning office of the "
+ "location group(s) whose data is to be included in the response. If this "
+ "location group whose data is to be included in the response. If this "
+ "field is not specified, matching location groups information from all "
+ "offices shall be returned."),
@OpenApiParam(name = INCLUDE_ASSIGNED, type = Boolean.class, description = "Include"
Expand All @@ -87,7 +89,9 @@ private Timer.Context markAndTime(String subject) {
+ "matching against the location category id"),
@OpenApiParam(name = CATEGORY_OFFICE_ID, required = true, description = "Specifies the "
+ "owning office of the category the location group belongs to "
+ "whose data is to be included in the response.")
+ "whose data is to be included in the response."),
@OpenApiParam(name = LOCATION_OFFICE_ID, required = true, description = "Specifies the "
+ "owning office of the location assigned to the location group whose data is to be included in the response."),
},
responses = {
@OpenApiResponse(status = STATUS_200,
Expand All @@ -96,7 +100,8 @@ private Timer.Context markAndTime(String subject) {
@OpenApiContent(isArray = true, from = CsvV1LocationGroup.class, type = Formats.CSV)
})
},
description = "Returns CWMS Location Groups Data", tags = {TAG})
description = "Returns CWMS Location Groups Data", tags = {TAG}
)
@Override
public void getAll(@NotNull Context ctx) {

Expand All @@ -106,6 +111,7 @@ public void getAll(@NotNull Context ctx) {

String groupOfficeId = requiredParam(ctx, OFFICE);
String categoryOfficeId = requiredParam(ctx, CATEGORY_OFFICE_ID);
String locationOfficeId = ctx.queryParam(LOCATION_OFFICE_ID);

boolean includeAssigned = queryParamAsClass(ctx, new String[]{INCLUDE_ASSIGNED},
Boolean.class, false, metrics, name(LocationGroupController.class.getName(),
Expand All @@ -114,7 +120,7 @@ Boolean.class, false, metrics, name(LocationGroupController.class.getName(),
String locCategoryLike = queryParamAsClass(ctx, new String[]{LOCATION_CATEGORY_LIKE},
String.class, null, metrics, name(LocationGroupController.class.getName(), GET_ALL));

List<LocationGroup> grps = cdm.getLocationGroups(groupOfficeId, categoryOfficeId,
List<LocationGroup> grps = cdm.getLocationGroups(locationOfficeId, groupOfficeId, categoryOfficeId,
includeAssigned, locCategoryLike);

if (!grps.isEmpty()) {
Expand Down Expand Up @@ -163,14 +169,15 @@ Boolean.class, false, metrics, name(LocationGroupController.class.getName(),
@OpenApiContent(type = Formats.GEOJSON)
})
},
description = "Retrieves requested Location Group", tags = {TAG})
description = "Retrieves requested Location Group", tags = {TAG}
)
@Override
public void getOne(@NotNull Context ctx, @NotNull String groupId) {

try (final Timer.Context ignored = markAndTime(GET_ONE)) {
DSLContext dsl = getDslContext(ctx);
LocationGroupDao cdm = new LocationGroupDao(dsl);
String office = requiredParam(ctx, OFFICE);
String locationOfficeId = requiredParam(ctx, OFFICE);
String categoryId = requiredParam(ctx, CATEGORY_ID);

// Not marked as required to maintain backwards compatibility with existing clients
Expand All @@ -182,13 +189,13 @@ public void getOne(@NotNull Context ctx, @NotNull String groupId) {
ContentType contentType;
if (formatHeader != null && formatHeader.contains(Formats.GEOJSON)) {
contentType = new ContentType(Formats.GEOJSON);
FeatureCollection fc = cdm.buildFeatureCollectionForLocationGroup(office,
FeatureCollection fc = cdm.buildFeatureCollectionForLocationGroup(locationOfficeId,
groupOfficeId, categoryOfficeId, categoryId, groupId, "EN");
ObjectMapper mapper = ctx.appAttribute("ObjectMapper");
result = mapper.writeValueAsString(fc);
} else {
contentType = Formats.parseHeader(formatHeader, LocationGroup.class);
Optional<LocationGroup> grp = cdm.getLocationGroup(office, categoryId, groupId);
Optional<LocationGroup> grp = cdm.getLocationGroup(locationOfficeId, categoryId, groupId);
if (grp.isPresent()) {
result = Formats.format(contentType, grp.get());
} else {
Expand Down Expand Up @@ -300,9 +307,8 @@ public void update(@NotNull Context ctx, @NotNull String oldGroupId) {
+ "location category of the location group to be deleted"),
@OpenApiParam(name = OFFICE, required = true, description = "Specifies the "
+ "owning office of the location group to be deleted"),
@OpenApiParam(name = CASCADE_DELETE, type = Boolean.class,
description = "Specifies whether to specifies whether to unassign any "
+ "location assignments. Default: false"),
@OpenApiParam(name = CASCADE_DELETE, type = Boolean.class, description = "Specifies whether "
+ "to unassign any location assignments. Default: false"),
},
method = HttpMethod.DELETE,
tags = {TAG}
Expand Down
Loading

0 comments on commit 1d0cddb

Please sign in to comment.