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

✨ [REST-API] Add support to query operations by status in GET /{scopeId}/devices/{deviceId}/operations #4121

Merged
merged 1 commit into from
Oct 30, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationListResult;
import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationQuery;
import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationRegistryService;
import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationStatus;
import org.eclipse.kapua.service.device.registry.Device;

@Path("{scopeId}/devices/{deviceId}/operations")
Expand Down Expand Up @@ -69,6 +70,7 @@ public DeviceManagementOperationListResult simpleQuery(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
@QueryParam("resource") String resource,
@QueryParam("status") DeviceManagementOperationStatus operationStatus,
@QueryParam("askTotalCount") boolean askTotalCount,
@QueryParam("sortParam") String sortParam,
@QueryParam("sortDir") @DefaultValue("ASCENDING") SortOrder sortDir,
Expand All @@ -83,6 +85,9 @@ public DeviceManagementOperationListResult simpleQuery(
if (!Strings.isNullOrEmpty(resource)) {
andPredicate.and(query.attributePredicate(DeviceManagementOperationAttributes.RESOURCE, resource));
}
if (operationStatus != null) {
andPredicate.and(query.attributePredicate(DeviceManagementOperationAttributes.STATUS, operationStatus));
}

if (!Strings.isNullOrEmpty(sortParam)) {
query.setSortCriteria(query.fieldSortCriteria(sortParam, sortDir));
Expand Down Expand Up @@ -115,12 +120,15 @@ public DeviceManagementOperationListResult query(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("deviceId") EntityId deviceId,
DeviceManagementOperationQuery query) throws KapuaException {
query.setScopeId(scopeId);

AndPredicate andPredicate = query.andPredicate();
Coduz marked this conversation as resolved.
Show resolved Hide resolved
andPredicate.and(query.attributePredicate(DeviceManagementOperationAttributes.DEVICE_ID, deviceId));
query.setPredicate(andPredicate);

if (query.getPredicate() != null) {
final AndPredicate andPredicate = query.andPredicate(
query.attributePredicate(DeviceManagementOperationAttributes.DEVICE_ID, deviceId),
query.getPredicate()
);
query.setPredicate(andPredicate);
} else {
query.setPredicate(query.attributePredicate(DeviceManagementOperationAttributes.DEVICE_ID, deviceId));
}
return deviceManagementOperationRegistryService.query(query);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ paths:
description: The resource of the DeviceManagementOperation in which to search results
schema:
type: string
- $ref: '../deviceOperation/deviceOperation.yaml#/components/parameters/status'
- $ref: '../openapi.yaml#/components/parameters/askTotalCount'
- $ref: '../openapi.yaml#/components/parameters/sortParam'
- name: sortDir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ components:
schema:
$ref: '../openapi.yaml#/components/schemas/kapuaId'
required: true
status:
name: status
in: query
description: The status of the Registry Operation on which to perform the operation
schema:
$ref: './deviceOperation.yaml#/components/schemas/operationStatus'
schemas:
deviceOperation:
allOf:
Expand Down
Loading