/** * Queries the results with the given {@link DeviceManagementOperationQuery} parameter. * * @param scopeId The {@link ScopeId} in which to search results. * @param deviceId The id of the {@link Device} in which to search results * @param query The {@link DeviceManagementOperationQuery} to use to filter results. * @return The {@link DeviceManagementOperationListResult} of all the result matching the given {@link DeviceManagementOperationQuery} parameter. * @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "deviceManagementOperationQuery", value = "Queries the DeviceManagementOperations", notes = "Queries the DeviceManagementOperations with the given DeviceManagementOperations parameter returning all matching DeviceManagementOperations", response = DeviceManagementOperationListResult.class) @POST @Path("_query") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public DeviceManagementOperationListResult query( @ApiParam(value = "The ScopeId in which to search results.", required = true, defaultValue = DEFAULT_SCOPE_ID) @PathParam("scopeId") ScopeId scopeId, @ApiParam(value = "The id of the Device in which to search results") @PathParam("deviceId") EntityId deviceId, @ApiParam(value = "The DeviceManagementOperationQuery to use to filter results.", required = true) DeviceManagementOperationQuery query) throws Exception { query.setScopeId(scopeId); AndPredicateImpl andPredicate = new AndPredicateImpl(); andPredicate.and(new AttributePredicateImpl<>(DeviceManagementOperationAttributes.DEVICE_ID, deviceId)); query.setPredicate(andPredicate); return deviceManagementOperationRegistryService.query(query); }
query.setLimit(1); DeviceManagementOperationListResult results = deviceManagementOperationRegistryService.query(query);
default DeviceManagementOperation getDeviceManagementOperation(KapuaId scopeId, KapuaId operationId) throws KapuaException { DeviceManagementOperationQuery query = DEVICE_MANAGEMENT_OPERATION_FACTORY.newQuery(scopeId); query.setPredicate(new AttributePredicateImpl<>(DeviceManagementOperationAttributes.OPERATION_ID, operationId)); DeviceManagementOperationListResult operations = DEVICE_MANAGEMENT_OPERATION_REGISTRY_SERVICE.query(query); DeviceManagementOperation deviceManagementOperation = operations.getFirstItem(); if (deviceManagementOperation == null) { throw new KapuaEntityNotFoundException(DeviceManagementOperation.TYPE, operationId); } return deviceManagementOperation; } }
protected void closeManagementOperation(KapuaId scopeId, KapuaId deviceId, KapuaId operationId, KapuaResponseMessage<?, ?> responseMessageMessage) throws KapuaException { DeviceManagementOperationQuery query = DEVICE_MANAGEMENT_OPERATION_FACTORY.newQuery(scopeId); query.setPredicate( new AndPredicateImpl( new AttributePredicateImpl<>(DeviceManagementOperationAttributes.DEVICE_ID, deviceId), new AttributePredicateImpl<>(DeviceManagementOperationAttributes.OPERATION_ID, operationId) ) ); DeviceManagementOperation deviceManagementOperation = DEVICE_MANAGEMENT_OPERATION_REGISTRY_SERVICE.query(query).getFirstItem(); if (deviceManagementOperation == null) { throw new KapuaEntityNotFoundException(DeviceManagementOperation.TYPE, operationId); } deviceManagementOperation.setStatus(responseMessageMessage.getResponseCode().isAccepted() ? OperationStatus.COMPLETED : OperationStatus.FAILED); deviceManagementOperation.setEndedOn(responseMessageMessage.getReceivedOn()); KapuaSecurityUtils.doPrivileged(() -> DEVICE_MANAGEMENT_OPERATION_REGISTRY_SERVICE.update(deviceManagementOperation)); }