/** * Creates a new job instance * * @return */ public ManagementOperationNotification newDeviceManagementOperation() { return factory.newEntity(null); }
/** * Creates a new job creator instance * * @return */ public ManagementOperationNotificationCreator newDeviceManagementOperationCreator() { return factory.newCreator(null); }
/** * Creates a new job list result instance * * @return */ public ManagementOperationNotificationListResult newDeviceManagementOperationListResult() { return factory.newListResult(); }
/** * Creates and return new DeviceManagementOperationNotification * * @param em * @param managementOperationNotificationCreator * @return * @throws KapuaException */ public static ManagementOperationNotification create(EntityManager em, ManagementOperationNotificationCreator managementOperationNotificationCreator) throws KapuaException { // // Create DeviceManagementOperationNotification ManagementOperationNotificationImpl managementOperationNotification = new ManagementOperationNotificationImpl(managementOperationNotificationCreator.getScopeId()); managementOperationNotification.setOperationId(managementOperationNotificationCreator.getOperationId()); managementOperationNotification.setSentOn(managementOperationNotificationCreator.getSentOn()); managementOperationNotification.setStatus(managementOperationNotificationCreator.getStatus()); managementOperationNotification.setResource(managementOperationNotificationCreator.getResource()); managementOperationNotification.setProgress(managementOperationNotificationCreator.getProgress()); return ServiceDAO.create(em, managementOperationNotification); }
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()); } }
@ApiParam(value = "The id of the requested Device", required = true) @PathParam("operationId") EntityId operationId, @ApiParam(value = "The id of the requested ManagementOperationNotification", required = true) @PathParam("managementOperationNotificationId") EntityId managementOperationNotificationId) throws Exception { ManagementOperationNotificationQuery query = managementOperationNotificationFactory.newQuery(scopeId); andPredicate.and(new AttributePredicateImpl<>(ManagementOperationNotificationAttributes.ENTITY_ID, managementOperationNotificationId)); query.setPredicate(andPredicate); query.setOffset(0); query.setLimit(1); ManagementOperationNotificationListResult results = managementOperationNotificationService.query(query); if (!results.isEmpty()) { return results.getFirstItem(); } else { throw new KapuaEntityNotFoundException(ManagementOperationNotification.TYPE, managementOperationNotificationId);
default void addManagementNotification(KapuaId scopeId, KapuaId operationId, Date updateOn, OperationStatus operationStatus, String resource, Integer progress) throws KapuaException { DeviceManagementOperation deviceManagementOperation = getDeviceManagementOperation(scopeId, operationId); ManagementOperationNotificationCreator managementOperationNotificationCreator = MANAGEMENT_OPERATION_NOTIFICATION_FACTORY.newCreator(scopeId); managementOperationNotificationCreator.setOperationId(deviceManagementOperation.getId()); managementOperationNotificationCreator.setSentOn(updateOn); managementOperationNotificationCreator.setStatus(operationStatus); managementOperationNotificationCreator.setResource(resource); managementOperationNotificationCreator.setProgress(progress); MANAGEMENT_OPERATION_NOTIFICATION_REGISTRY_SERVICE.create(managementOperationNotificationCreator); }
/** * Gets the {@link ManagementOperationNotification} list in the scope. * * @param scopeId The {@link ScopeId} in which to search results. * @param operationId The id of the {@link Device} in which to search results * @param resource The resource of the {@link ManagementOperationNotification} in which to search results * @param offset The result set offset. * @param limit The result set limit. * @return The {@link ManagementOperationNotificationListResult} of all the ManagementOperationNotifications associated to the current selected scope. * @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "ManagementOperationNotificationSimpleQuery", value = "Gets the ManagementOperationNotification list in the scope", notes = "Returns the list of all the ManagementOperationNotifications associated to the current selected scope.", response = ManagementOperationNotificationListResult.class) @GET @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ManagementOperationNotificationListResult simpleQuery( @ApiParam(value = "The ScopeId in which to search results.", required = true, defaultValue = DEFAULT_SCOPE_ID) @PathParam("scopeId") ScopeId scopeId, @ApiParam(value = "The device id to filter results.") @PathParam("deviceId") EntityId deviceId, @ApiParam(value = "The operation id to filter results.") @PathParam("operationId") EntityId operationId, @ApiParam(value = "The resource of the ManagementOperationNotification in which to search results") @QueryParam("resource") String resource, @ApiParam(value = "The result set offset.", defaultValue = "0") @QueryParam("offset") @DefaultValue("0") int offset, @ApiParam(value = "The result set limit.", defaultValue = "50") @QueryParam("limit") @DefaultValue("50") int limit) throws Exception { ManagementOperationNotificationQuery query = managementOperationNotificationFactory.newQuery(scopeId); AndPredicateImpl andPredicate = new AndPredicateImpl(); andPredicate.and(new AttributePredicateImpl<>(ManagementOperationNotificationAttributes.OPERATION_ID, operationId)); query.setPredicate(andPredicate); query.setOffset(offset); query.setLimit(limit); return query(scopeId, deviceId, operationId, query); }
@Override public ManagementOperationNotification create(ManagementOperationNotificationCreator creator) throws KapuaException { // // Argument Validation ArgumentValidator.notNull(creator, "managementOperationNotificationCreator"); ArgumentValidator.notNull(creator.getScopeId(), "managementOperationNotificationCreator.scopeId"); ArgumentValidator.notNull(creator.getOperationId(), "managementOperationNotificationCreator.operationId"); ArgumentValidator.notNull(creator.getSentOn(), "managementOperationNotificationCreator.sentOn"); ArgumentValidator.notNull(creator.getStatus(), "managementOperationNotificationCreator.status"); ArgumentValidator.notNull(creator.getProgress(), "managementOperationNotificationCreator.progress"); ArgumentValidator.notNegative(creator.getProgress(), "managementOperationNotificationCreator.progress"); // // Check access authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementRegistryDomains.DEVICE_MANAGEMENT_REGISTRY_DOMAIN, Actions.write, null)); // // Check operation existence if (KapuaSecurityUtils.doPrivileged(() -> deviceManagementOperationRegistryService.find(creator.getScopeId(), creator.getOperationId()) == null)) { throw new KapuaEntityNotFoundException(DeviceManagementOperation.TYPE, creator.getOperationId()); } // // Do create return entityManagerSession.onTransactedInsert(em -> ManagementOperationNotificationDAO.create(em, creator)); }
/** * Queries the results with the given {@link ManagementOperationNotificationQuery} parameter. * * @param scopeId The {@link ScopeId} in which to search results. * @param operationId The id of the {@link Device} in which to search results * @param query The {@link ManagementOperationNotificationQuery} to use to filter results. * @return The {@link ManagementOperationNotificationListResult} of all the result matching the given {@link ManagementOperationNotificationQuery} parameter. * @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "ManagementOperationNotificationQuery", value = "Queries the ManagementOperationNotifications", notes = "Queries the ManagementOperationNotifications with the given ManagementOperationNotifications parameter returning all matching ManagementOperationNotifications", response = ManagementOperationNotificationListResult.class) @POST @Path("_query") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public ManagementOperationNotificationListResult query( @ApiParam(value = "The ScopeId in which to search results.", required = true, defaultValue = DEFAULT_SCOPE_ID) @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 search results") @PathParam("operationId") EntityId operationId, @ApiParam(value = "The ManagementOperationNotificationQuery to use to filter results.", required = true) ManagementOperationNotificationQuery query) throws Exception { query.setScopeId(scopeId); AndPredicateImpl andPredicate = new AndPredicateImpl(); andPredicate.and(new AttributePredicateImpl<>(ManagementOperationNotificationAttributes.OPERATION_ID, operationId)); query.setPredicate(andPredicate); return managementOperationNotificationService.query(query); }
/** * Counts the results with the given {@link ManagementOperationNotificationQuery} parameter. * * @param scopeId The {@link ScopeId} in which to search results. * @param operationId The id of the {@link Device} in which to search results * @param query The {@link ManagementOperationNotificationQuery} to use to filter results. * @return The count of all the result matching the given {@link ManagementOperationNotificationQuery} parameter. * @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "ManagementOperationNotificationCount", value = "Counts the ManagementOperationNotifications", notes = "Counts the ManagementOperationNotifications with the given ManagementOperationNotificationQuery parameter returning the number of matching ManagementOperationNotifications", response = CountResult.class) @POST @Path("_count") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public CountResult count( @ApiParam(value = "The ScopeId in which to count results.", required = true, defaultValue = DEFAULT_SCOPE_ID) @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 count results") @PathParam("operationId") EntityId operationId, @ApiParam(value = "The ManagementOperationNotificationQuery to use to filter count results", required = true) ManagementOperationNotificationQuery query) throws Exception { query.setScopeId(scopeId); query.setPredicate(new AttributePredicateImpl<>(ManagementOperationNotificationAttributes.OPERATION_ID, operationId)); return new CountResult(managementOperationNotificationService.count(query)); }
ManagementOperationNotificationQuery newQuery() { return MANAGEMENT_OPERATION_NOTIFICATION_REGISTRY_FACTORY.newQuery(null); } }
/** * 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(); } }
public ManagementOperationNotificationQuery newQuery() { return factory.newQuery(null); } }
ManagementOperationNotification newManagementOperationNotification() { return MANAGEMENT_OPERATION_NOTIFICATION_REGISTRY_FACTORY.newEntity(null); }
ManagementOperationNotificationCreator newManagementOperationNotificationCreator() { return MANAGEMENT_OPERATION_NOTIFICATION_REGISTRY_FACTORY.newCreator(null); }
ManagementOperationNotificationListResult newManagementOperationNotificationListResult() { return MANAGEMENT_OPERATION_NOTIFICATION_REGISTRY_FACTORY.newListResult(); }