/** * Queries the results with the given {@link RolePermissionQuery} parameter. * * @param scopeId The {@link ScopeId} in which to search results. * @param roleId The {@link Role} id in which to search results. * @param query The {@link RolePermissionQuery} to use to filter results. * @return The {@link RolePermissionListResult} of all the result matching the given {@link RolePermissionQuery} parameter. * @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "rolePermissionQuery", value = "Queries the RolePermissions", notes = "Queries the RolePermissions with the given RolePermissionQuery parameter returning all matching RolePermissions", response = RolePermissionListResult.class) @POST @Path("_query") @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public RolePermissionListResult query( @ApiParam(value = "The ScopeId in which to search results.", required = true, defaultValue = DEFAULT_SCOPE_ID) @PathParam("scopeId") ScopeId scopeId, @ApiParam(value = "The Role id in which to search results.") @PathParam("roleId") EntityId roleId, @ApiParam(value = "The RolePermissionQuery to use to filter results.", required = true) RolePermissionQuery query) throws Exception { query.setScopeId(scopeId); AndPredicateImpl andPredicate = new AndPredicateImpl(); andPredicate.and(new AttributePredicateImpl<>(RolePermissionAttributes.ROLE_ID, roleId)); andPredicate.and(query.getPredicate()); query.setPredicate(andPredicate); return rolePermissionService.query(query); }
/** * Constructor * * @since 0.1.0 */ public AndPredicateImpl() { setPredicates(new ArrayList<>()); }
AndPredicate andPredicate = new AndPredicateImpl( new AttributePredicateImpl<>(EndpointInfoAttributes.SCHEMA, schema), new AttributePredicateImpl<>(EndpointInfoAttributes.DNS, dns),
/** * This method apply {@link AttributePredicate}s according to the parameters contained into the {@link JobContextWrapper} and {@link StepContextWrapper}. * <p> * It manages the options of resetting the status of the target to a certain {@link JobStepIndex}. * <p> * When no {@link JobStepIndex} is specified, the methods selects all targets that are set to the current {@link StepContextWrapper#getStepIndex()} and that don't have the * {@link JobTargetStatus} set to {@link JobTargetStatus#PROCESS_OK}. * <p> * When a {@link JobStepIndex} is specified, the methods ignores all targets until the {@link StepContextWrapper#getStepIndex()} doesn't match the {@link JobContextWrapper#getFromStepIndex()}. * When they match all the {@link JobTarget}s are seleted regardless of their {@link JobTargetStatus}. After passing the given {@link JobContextWrapper#getFromStepIndex()} {@link JobTarget}s * will be selected as regularly. * <p> * Regardless of the status of the {@link org.eclipse.kapua.service.job.Job} of the {@link StepContextWrapper#getStepIndex()} and the {@link JobContextWrapper#getFromStepIndex()} values, * {@link #targetSublistFiltering(JobContextWrapper, AndPredicateImpl)} can apply filter that will reduce the {@link JobTarget}s selected. * * @param jobContextWrapper The {@link JobContextWrapper} from which extract data * @param stepContextWrapper The {@link StepContextWrapper} from which extract data * @param andPredicate The {@link org.eclipse.kapua.model.query.predicate.AndPredicate} where to apply {@link org.eclipse.kapua.model.query.predicate.QueryPredicate} * @since 1.0.0 */ protected void stepIndexFiltering(JobContextWrapper jobContextWrapper, StepContextWrapper stepContextWrapper, AndPredicateImpl andPredicate) { Integer fromStepIndex = jobContextWrapper.getFromStepIndex(); if (fromStepIndex == null || fromStepIndex < stepContextWrapper.getStepIndex()) { andPredicate.and(new AttributePredicateImpl<>(JobTargetAttributes.STEP_INDEX, stepContextWrapper.getStepIndex())); andPredicate.and(new AttributePredicateImpl<>(JobTargetAttributes.STATUS, JobTargetStatus.PROCESS_OK, AttributePredicate.Operator.NOT_EQUAL)); } else if (fromStepIndex > stepContextWrapper.getStepIndex()) { andPredicate.and(new AttributePredicateImpl<>(JobTargetAttributes.STEP_INDEX, JobStepIndex.NONE)); } }
@Override public void open(Serializable arg0) throws Exception { JobContextWrapper jobContextWrapper = new JobContextWrapper(jobContext); StepContextWrapper stepContextWrapper = new StepContextWrapper(stepContext); LOG.info("JOB {} - Opening cursor...", jobContextWrapper.getJobId()); // // Job Id and JobTarget status filtering AndPredicateImpl andPredicate = new AndPredicateImpl( new AttributePredicateImpl<>(JobTargetAttributes.JOB_ID, jobContextWrapper.getJobId()) ); // // Step index filtering stepIndexFiltering(jobContextWrapper, stepContextWrapper, andPredicate); // // Filter selected target targetSublistFiltering(jobContextWrapper, andPredicate); // // Query the targets JobTargetQuery query = jobTargetFactory.newQuery(jobContextWrapper.getScopeId()); query.setPredicate(andPredicate); jobTargets = KapuaSecurityUtils.doPrivileged(() -> jobTargetService.query(query)); LOG.info("JOB {} - Opening cursor... Done!", jobContextWrapper.getJobId()); }
/** * This method apply {@link AttributePredicate}s according to the parameters contained into the {@link JobContextWrapper} and {@link StepContextWrapper}. * <p> * It manages the options of resetting the status of the target to a certain {@link JobStepIndex}. * <p> * When no {@link JobStepIndex} is specified, the methods selects all targets that are set to the current {@link StepContextWrapper#getStepIndex()} and that don't have the * {@link JobTargetStatus} set to {@link JobTargetStatus#PROCESS_OK}. * <p> * When a {@link JobStepIndex} is specified, the methods ignores all targets until the {@link StepContextWrapper#getStepIndex()} doesn't match the {@link JobContextWrapper#getFromStepIndex()}. * When they match all the {@link JobTarget}s are seleted regardless of their {@link JobTargetStatus}. After passing the given {@link JobContextWrapper#getFromStepIndex()} {@link JobTarget}s * will be selected as regularly. * <p> * Regardless of the status of the {@link org.eclipse.kapua.service.job.Job} of the {@link StepContextWrapper#getStepIndex()} and the {@link JobContextWrapper#getFromStepIndex()} values, * {@link #targetSublistFiltering(JobContextWrapper, AndPredicateImpl)} can apply filter that will reduce the {@link JobTarget}s selected. * * @param jobContextWrapper The {@link JobContextWrapper} from which extract data * @param stepContextWrapper The {@link StepContextWrapper} from which extract data * @param andPredicate The {@link org.eclipse.kapua.model.query.predicate.AndPredicate} where to apply {@link org.eclipse.kapua.model.query.predicate.QueryPredicate} * @since 1.0.0 */ protected void stepIndexFiltering(JobContextWrapper jobContextWrapper, StepContextWrapper stepContextWrapper, AndPredicateImpl andPredicate) { Integer fromStepIndex = jobContextWrapper.getFromStepIndex(); if (fromStepIndex == null || fromStepIndex < stepContextWrapper.getStepIndex()) { andPredicate.and(new AttributePredicateImpl<>(JobTargetAttributes.STEP_INDEX, stepContextWrapper.getStepIndex())); andPredicate.and(new AttributePredicateImpl<>(JobTargetAttributes.STATUS, JobTargetStatus.PROCESS_OK, AttributePredicate.Operator.NOT_EQUAL)); } else if (fromStepIndex > stepContextWrapper.getStepIndex()) { andPredicate.and(new AttributePredicateImpl<>(JobTargetAttributes.STEP_INDEX, JobStepIndex.NONE)); } }
/** * 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); }
@Override public void open(Serializable arg0) throws Exception { JobContextWrapper jobContextWrapper = new JobContextWrapper(jobContext); StepContextWrapper stepContextWrapper = new StepContextWrapper(stepContext); LOG.info("JOB {} - Opening cursor...", jobContextWrapper.getJobId()); // // Job Id and JobTarget status filtering AndPredicateImpl andPredicate = new AndPredicateImpl( new AttributePredicateImpl<>(JobTargetAttributes.JOB_ID, jobContextWrapper.getJobId()) ); // // Step index filtering stepIndexFiltering(jobContextWrapper, stepContextWrapper, andPredicate); // // Filter selected target targetSublistFiltering(jobContextWrapper, andPredicate); // // Query the targets JobTargetQuery query = jobTargetFactory.newQuery(jobContextWrapper.getScopeId()); query.setPredicate(andPredicate); jobTargets = KapuaSecurityUtils.doPrivileged(() -> jobTargetService.query(query)); LOG.info("JOB {} - Opening cursor... Done!", jobContextWrapper.getJobId()); }
/** * This method apply {@link AttributePredicate}s according to the parameters contained into the {@link JobContextWrapper#getTargetSublist()}. * <p> * If the {@link JobContextWrapper#getTargetSublist()} has one or more {@link org.eclipse.kapua.model.id.KapuaId}s they will be added to the * {@link org.eclipse.kapua.model.query.predicate.AndPredicate} to select only given {@link JobTarget}. * * @param jobContextWrapper The {@link JobContextWrapper} from which extract data * @param andPredicate The {@link org.eclipse.kapua.model.query.predicate.AndPredicate} where to apply {@link org.eclipse.kapua.model.query.predicate.QueryPredicate} * @since 1.0.0 */ protected void targetSublistFiltering(JobContextWrapper jobContextWrapper, AndPredicateImpl andPredicate) { if (!jobContextWrapper.getTargetSublist().isEmpty()) { andPredicate.and(new AttributePredicateImpl<>(JobTargetAttributes.ENTITY_ID, jobContextWrapper.getTargetSublist().toArray())); } }
/** * Constructor * * @since 0.1.0 */ public AndPredicateImpl() { setPredicates(new ArrayList<>()); }
/** * 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); }
new AndPredicateImpl( new AttributePredicateImpl<>(RolePermissionAttributes.SCOPE_ID, rolePermissionCreator.getScopeId()), new AttributePredicateImpl<>(RolePermissionAttributes.ROLE_ID, rolePermissionCreator.getRoleId()),
/** * This method apply {@link AttributePredicate}s according to the parameters contained into the {@link JobContextWrapper#getTargetSublist()}. * <p> * If the {@link JobContextWrapper#getTargetSublist()} has one or more {@link org.eclipse.kapua.model.id.KapuaId}s they will be added to the * {@link org.eclipse.kapua.model.query.predicate.AndPredicate} to select only given {@link JobTarget}. * * @param jobContextWrapper The {@link JobContextWrapper} from which extract data * @param andPredicate The {@link org.eclipse.kapua.model.query.predicate.AndPredicate} where to apply {@link org.eclipse.kapua.model.query.predicate.QueryPredicate} * @since 1.0.0 */ protected void targetSublistFiltering(JobContextWrapper jobContextWrapper, AndPredicateImpl andPredicate) { if (!jobContextWrapper.getTargetSublist().isEmpty()) { andPredicate.and(new AttributePredicateImpl<>(JobTargetAttributes.ENTITY_ID, jobContextWrapper.getTargetSublist().toArray())); } }
/** * Constructor which accepts a not null array of {@link QueryPredicate}s. * * @param predicates the {@link QueryPredicate}s to add. * @throws NullPointerException if the given parameter is {@code null}. * @since 1.0.0 */ public AndPredicateImpl(@NotNull QueryPredicate... predicates) { Objects.requireNonNull(predicates); setPredicates(Lists.newArrayList(predicates)); }
/** * Queries the results with the given {@link DeviceEventQuery} 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 DeviceEventQuery} to use to filter results. * @return The {@link DeviceEventListResult} of all the result matching the given {@link DeviceEventQuery} parameter. * @throws Exception * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "deviceEventQuery", value = "Queries the DeviceEvents", notes = "Queries the DeviceEvents with the given DeviceEvents parameter returning all matching DeviceEvents", response = DeviceEventListResult.class) @POST @Path("_query") @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public DeviceEventListResult 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 DeviceEventQuery to use to filter results.", required = true) DeviceEventQuery query) throws Exception { query.setScopeId(scopeId); AndPredicateImpl andPredicate = new AndPredicateImpl(); andPredicate.and(new AttributePredicateImpl<>(DeviceEventAttributes.DEVICE_ID, deviceId)); andPredicate.and(query.getPredicate()); query.setPredicate(andPredicate); return deviceEventService.query(query); }
new AndPredicateImpl( new AttributePredicateImpl<>(AccessPermissionAttributes.SCOPE_ID, accessPermissionCreator.getScopeId()), new AttributePredicateImpl<>(AccessPermissionAttributes.ACCESS_INFO_ID, accessPermissionCreator.getAccessInfoId()),
/** * Constructor which accepts a not null array of {@link QueryPredicate}s. * * @param predicates the {@link QueryPredicate}s to add. * @throws NullPointerException if the given parameter is {@code null}. * @since 1.0.0 */ public AndPredicateImpl(@NotNull QueryPredicate... predicates) { Objects.requireNonNull(predicates); setPredicates(Lists.newArrayList(predicates)); }
private long countExistingCredentials(CredentialType credentialType, KapuaId scopeId, KapuaId userId) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); KapuaQuery<Credential> credentialQuery = credentialFactory.newQuery(scopeId); CredentialType ct = credentialType; QueryPredicate credentialTypePredicate = new AttributePredicateImpl<>(CredentialAttributes.CREDENTIAL_TYPE, ct); QueryPredicate userIdPredicate = new AttributePredicateImpl<>(CredentialAttributes.USER_ID, userId); QueryPredicate andPredicate = new AndPredicateImpl().and(credentialTypePredicate).and(userIdPredicate); credentialQuery.setPredicate(andPredicate); return count(credentialQuery); }
new AndPredicateImpl( new AttributePredicateImpl<>(AccessPermissionAttributes.SCOPE_ID, accessPermissionCreator.getScopeId()), new AttributePredicateImpl<>(AccessPermissionAttributes.ACCESS_INFO_ID, accessPermissionCreator.getAccessInfoId()),
private long countExistingCredentials(CredentialType credentialType, KapuaId scopeId, KapuaId userId) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); KapuaQuery<Credential> credentialQuery = credentialFactory.newQuery(scopeId); CredentialType ct = credentialType; QueryPredicate credentialTypePredicate = new AttributePredicateImpl<>(CredentialAttributes.CREDENTIAL_TYPE, ct); QueryPredicate userIdPredicate = new AttributePredicateImpl<>(CredentialAttributes.USER_ID, userId); QueryPredicate andPredicate = new AndPredicateImpl().and(credentialTypePredicate).and(userIdPredicate); credentialQuery.setPredicate(andPredicate); return count(credentialQuery); }