andPredicate.and(new AttributePredicateImpl<>(CredentialAttributes.USER_ID, userId)); query.setPredicate(andPredicate); query.setOffset(offset); query.setLimit(limit);
/** * Queries the results with the given {@link CredentialQuery} parameter. * * @param scopeId * The {@link ScopeId} in which to search results. * @param query * The {@link CredentialQuery} to use to filter results. * @return The {@link CredentialListResult} of all the result matching the given {@link CredentialQuery} parameter. * @throws Exception * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "credentialQuery", value = "Queries the Credentials", notes = "Queries the Credentials with the given CredentialQuery parameter returning all matching Credentials", response = CredentialListResult.class) @POST @Path("_query") @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CredentialListResult query( @ApiParam(value = "The ScopeId in which to search results.", required = true, defaultValue = DEFAULT_SCOPE_ID) @PathParam("scopeId") ScopeId scopeId, @ApiParam(value = "The CredentialQuery to use to filter results.", required = true) CredentialQuery query) throws Exception { query.setScopeId(scopeId); return credentialService.query(query); }
private void deleteCredentialByUserId(KapuaId scopeId, KapuaId userId) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); CredentialQuery query = credentialFactory.newQuery(scopeId); query.setPredicate(new AttributePredicateImpl<>(CredentialAttributes.USER_ID, userId)); CredentialListResult credentialsToDelete = query(query); for (Credential c : credentialsToDelete.getItems()) { delete(c.getScopeId(), c.getId()); } }
private void deleteCredentialByUserId(KapuaId scopeId, KapuaId userId) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); CredentialQuery query = credentialFactory.newQuery(scopeId); query.setPredicate(new AttributePredicateImpl<>(CredentialAttributes.USER_ID, userId)); CredentialListResult credentialsToDelete = query(query); for (Credential c : credentialsToDelete.getItems()) { delete(c.getScopeId(), c.getId()); } }
@Override public CredentialListResult findByUserId(KapuaId scopeId, KapuaId userId) throws KapuaException { // // Argument Validation ArgumentValidator.notNull(scopeId, "scopeId"); ArgumentValidator.notNull(userId, "userId"); // // Check Access KapuaLocator locator = KapuaLocator.getInstance(); AuthorizationService authorizationService = locator.getService(AuthorizationService.class); PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); authorizationService.checkPermission(permissionFactory.newPermission(AuthenticationDomains.CREDENTIAL_DOMAIN, Actions.read, scopeId)); // // Build query CredentialQuery query = new CredentialQueryImpl(scopeId); QueryPredicate predicate = new AttributePredicateImpl<>(CredentialAttributes.USER_ID, userId); query.setPredicate(predicate); // // Query and return result return query(query); }
/** * Counts the results with the given {@link CredentialQuery} parameter. * * @param scopeId * The {@link ScopeId} in which to search results. * @param query * The {@link CredentialQuery} to use to filter results. * @return The count of all the result matching the given {@link CredentialQuery} parameter. * @throws Exception * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "credentialCount", value = "Counts the Credentials", notes = "Counts the Credentials with the given CredentialQuery parameter returning the number of matching Credentials", 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 CredentialQuery to use to filter count results", required = true) CredentialQuery query) throws Exception { query.setScopeId(scopeId); return new CountResult(credentialService.count(query)); }
@Override public CredentialListResult findByUserId(KapuaId scopeId, KapuaId userId) throws KapuaException { // // Argument Validation ArgumentValidator.notNull(scopeId, "scopeId"); ArgumentValidator.notNull(userId, "userId"); // // Check Access KapuaLocator locator = KapuaLocator.getInstance(); AuthorizationService authorizationService = locator.getService(AuthorizationService.class); PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); authorizationService.checkPermission(permissionFactory.newPermission(AuthenticationDomains.CREDENTIAL_DOMAIN, Actions.read, scopeId)); // // Build query CredentialQuery query = new CredentialQueryImpl(scopeId); QueryPredicate predicate = new AttributePredicateImpl<>(CredentialAttributes.USER_ID, userId); query.setPredicate(predicate); // // Query and return result return query(query); }