/** * Deletes the ManagementOperationNotification specified by the "ManagementOperationNotificationId" path parameter. * * @param operationId The id of the Device in which to delete the ManagementOperation * @param managementOperationNotificationId The id of the ManagementOperationNotification to be deleted. * @return HTTP 200 if operation has completed successfully. * @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "ManagementOperationNotificationDelete", value = "Delete a ManagementOperationNotification", notes = "Deletes the ManagementOperationNotification specified by the \"ManagementOperationNotificationId\" path parameter.") @DELETE @Path("{managementOperationNotificationId}") public Response deleteManagementOperationNotification( @PathParam("scopeId") ScopeId scopeId, @ApiParam(value = "The device id to filter results.") @PathParam("deviceId") EntityId deviceId, @ApiParam(value = "The id of the Device in which to delete the ManagementOperation.", required = true) @PathParam("operationId") EntityId operationId, @ApiParam(value = "The id of the ManagementOperationNotification to be deleted", required = true) @PathParam("managementOperationNotificationId") EntityId managementOperationNotificationId) throws Exception { managementOperationNotificationService.delete(scopeId, managementOperationNotificationId); return returnOk(); } }
default void closeDeviceManagementOperation(KapuaId scopeId, KapuaId operationId, Date updateOn, OperationStatus finalStatus) throws KapuaException { DeviceManagementOperation deviceManagementOperation = null; short attempts = 0; short limit = 3; boolean failed = false; do { try { deviceManagementOperation = getDeviceManagementOperation(scopeId, operationId); deviceManagementOperation.setEndedOn(updateOn); deviceManagementOperation.setStatus(finalStatus); DEVICE_MANAGEMENT_OPERATION_REGISTRY_SERVICE.update(deviceManagementOperation); LOG.info("Update DeviceManagementOperation {} with status {}... SUCCEEDED!", operationId, finalStatus); break; } catch (Exception e) { failed = true; attempts++; if (attempts >= limit) { throw e; } else { LOG.warn("Update DeviceManagementOperation {} with status {}... FAILED! Retrying...", operationId, finalStatus); } } } while (failed); ManagementOperationNotificationQuery query = MANAGEMENT_OPERATION_NOTIFICATION_FACTORY.newQuery(scopeId); query.setPredicate(new AttributePredicateImpl<>(ManagementOperationNotificationAttributes.OPERATION_ID, deviceManagementOperation.getId())); ManagementOperationNotificationListResult notifications = MANAGEMENT_OPERATION_NOTIFICATION_REGISTRY_SERVICE.query(query); for (ManagementOperationNotification mon : notifications.getItems()) { MANAGEMENT_OPERATION_NOTIFICATION_REGISTRY_SERVICE.delete(mon.getScopeId(), mon.getId()); } }