@Test public void testReadAll() { setRealms(REALM_ID); EntityBody body = getValidRoleDoc(); String id = "old-id"; Mockito.when(service.get(id)).thenReturn((EntityBody) body.clone()); mockGetRealmId(); Entity mockEntity = Mockito.mock(Entity.class); Mockito.when(mockEntity.getEntityId()).thenReturn("mock-id"); Mockito.when(service.get("mock-id")).thenReturn(body); NeutralQuery customRoleQuery = new NeutralQuery(); customRoleQuery.addCriteria(new NeutralCriteria("realmId", NeutralCriteria.CRITERIA_IN, new HashSet<String>(Arrays.asList(REALM_ID)))); Mockito.when(repo.findAllIds("customRole", customRoleQuery)).thenReturn(Arrays.asList("mock-id")); Response res = resource.readAll(uriInfo, ""); Assert.assertEquals(200, res.getStatus()); Assert.assertEquals(Arrays.asList(body), res.getEntity()); }
@GET @RightsAllowed({Right.CRUD_ROLE }) public Response readAll(@Context final UriInfo uriInfo, @DefaultValue("") @QueryParam("realmId") String realmId) { if (uriInfo.getQueryParameters() != null) { String defaultsOnly = uriInfo.getQueryParameters().getFirst("defaultsOnly"); if (defaultsOnly != null && Boolean.valueOf(defaultsOnly).booleanValue()) { return Response.ok(roleInitializer.getDefaultRoles()).build(); } } List<Map<String, Object>> results = new ArrayList<Map<String, Object>>(); Set<String> myRealms = realmHelper.getAssociatedRealmIds(); Set<String> realmsToQuery = null; if (!realmId.isEmpty() && !myRealms.contains(realmId)) { return buildBadRequest(ERROR_INVALID_REALM_ID + ": '" + realmId + "'"); } else { if (realmId.isEmpty()) { realmsToQuery = myRealms; } else { realmsToQuery = new HashSet<String>(); realmsToQuery.add(realmId); } } NeutralQuery customRoleQuery = new NeutralQuery(); customRoleQuery.addCriteria(new NeutralCriteria("realmId", NeutralCriteria.CRITERIA_IN, realmsToQuery)); Iterable<String> customRoles = repo.findAllIds("customRole", customRoleQuery); for (String id : customRoles) { EntityBody result = service.get(id); results.add(result); } return Response.ok(results).build(); }
CustomRoleResource { @GET @RightsAllowed({Right.CRUD_ROLE }) public Response readAll(@Context final UriInfo uriInfo, @DefaultValue("") @QueryParam("realmId") String realmId) { if (uriInfo.getQueryParameters() != null) { String defaultsOnly = uriInfo.getQueryParameters().getFirst("defaultsOnly"); if (defaultsOnly != null && Boolean.valueOf(defaultsOnly).booleanValue()) { return Response.ok(roleInitializer.getDefaultRoles()).build(); } } List<Map<String, Object>> results = new ArrayList<Map<String, Object>>(); Set<String> myRealms = realmHelper.getAssociatedRealmIds(); Set<String> realmsToQuery = null; if (!realmId.isEmpty() && !myRealms.contains(realmId)) { return buildBadRequest(ERROR_INVALID_REALM_ID + ": '" + realmId + "'"); } else { if (realmId.isEmpty()) { realmsToQuery = myRealms; } else { realmsToQuery = new HashSet<String>(); realmsToQuery.add(realmId); } } NeutralQuery customRoleQuery = new NeutralQuery(); customRoleQuery.addCriteria(new NeutralCriteria("realmId", NeutralCriteria.CRITERIA_IN, realmsToQuery)); Iterable<String> customRoles = repo.findAllIds("customRole", customRoleQuery); for (String id : customRoles) { EntityBody result = service.get(id); results.add(result); } return Response.ok(results).build(); } }
CustomRoleResource { @GET @RightsAllowed({Right.CRUD_ROLE }) public Response readAll(@Context final UriInfo uriInfo, @DefaultValue("") @QueryParam("realmId") String realmId) { if (uriInfo.getQueryParameters() != null) { String defaultsOnly = uriInfo.getQueryParameters().getFirst("defaultsOnly"); if (defaultsOnly != null && Boolean.valueOf(defaultsOnly).booleanValue()) { return Response.ok(roleInitializer.getDefaultRoles()).build(); } } List<Map<String, Object>> results = new ArrayList<Map<String, Object>>(); Set<String> myRealms = realmHelper.getAssociatedRealmIds(); Set<String> realmsToQuery = null; if (!realmId.isEmpty() && !myRealms.contains(realmId)) { return buildBadRequest(ERROR_INVALID_REALM_ID + ": '" + realmId + "'"); } else { if (realmId.isEmpty()) { realmsToQuery = myRealms; } else { realmsToQuery = new HashSet<String>(); realmsToQuery.add(realmId); } } NeutralQuery customRoleQuery = new NeutralQuery(); customRoleQuery.addCriteria(new NeutralCriteria("realmId", NeutralCriteria.CRITERIA_IN, realmsToQuery)); Iterable<String> customRoles = repo.findAllIds("customRole", customRoleQuery); for (String id : customRoles) { EntityBody result = service.get(id); results.add(result); } return Response.ok(results).build(); }  }
CustomRoleResource { @GET @RightsAllowed({Right.CRUD_ROLE }) public Response readAll(@Context final UriInfo uriInfo, @DefaultValue("") @QueryParam("realmId") String realmId) { if (uriInfo.getQueryParameters() != null) { String defaultsOnly = uriInfo.getQueryParameters().getFirst("defaultsOnly"); if (defaultsOnly != null && Boolean.valueOf(defaultsOnly).booleanValue()) { return Response.ok(roleInitializer.getDefaultRoles()).build(); } } List<Map<String, Object>> results = new ArrayList<Map<String, Object>>(); Set<String> myRealms = realmHelper.getAssociatedRealmIds(); Set<String> realmsToQuery = null; if (!realmId.isEmpty() && !myRealms.contains(realmId)) { return buildBadRequest(ERROR_INVALID_REALM_ID + ": '" + realmId + "'"); } else { if (realmId.isEmpty()) { realmsToQuery = myRealms; } else { realmsToQuery = new HashSet<String>(); realmsToQuery.add(realmId); } } NeutralQuery customRoleQuery = new NeutralQuery(); customRoleQuery.addCriteria(new NeutralCriteria("realmId", NeutralCriteria.CRITERIA_IN, realmsToQuery)); Iterable<String> customRoles = repo.findAllIds("customRole", customRoleQuery); for (String id : customRoles) { EntityBody result = service.get(id); results.add(result); } return Response.ok(results).build(); }  @PostConstruct void init(); @GET @RightsAllowed({Right.CRUD_ROLE }) Response readAll(@Context final UriInfo uriInfo,
            @DefaultValue("") @QueryParam("realmId") String realmId); @GET @Path("{id}") @RightsAllowed({Right.CRUD_ROLE }) Response read(@PathParam("id") String id, @Context final UriInfo uriInfo); @POST @RightsAllowed({Right.CRUD_ROLE }) Response createCustomRole(EntityBody newCustomRole, @Context final UriInfo uriInfo); @PUT @Path("{id}") @RightsAllowed({Right.CRUD_ROLE }) Response updateCustomRole(@PathParam("id") String id, EntityBody updated, @Context final UriInfo uriInfo); @DELETE @Path("{id}") @RightsAllowed({Right.CRUD_ROLE }) Response deleteCustomRole(@PathParam("id") String id, @Context final UriInfo uriInfo); }
CustomRoleResource { @GET @RightsAllowed({Right.CRUD_ROLE }) public Response readAll(@Context final UriInfo uriInfo, @DefaultValue("") @QueryParam("realmId") String realmId) { if (uriInfo.getQueryParameters() != null) { String defaultsOnly = uriInfo.getQueryParameters().getFirst("defaultsOnly"); if (defaultsOnly != null && Boolean.valueOf(defaultsOnly).booleanValue()) { return Response.ok(roleInitializer.getDefaultRoles()).build(); } } List<Map<String, Object>> results = new ArrayList<Map<String, Object>>(); Set<String> myRealms = realmHelper.getAssociatedRealmIds(); Set<String> realmsToQuery = null; if (!realmId.isEmpty() && !myRealms.contains(realmId)) { return buildBadRequest(ERROR_INVALID_REALM_ID + ": '" + realmId + "'"); } else { if (realmId.isEmpty()) { realmsToQuery = myRealms; } else { realmsToQuery = new HashSet<String>(); realmsToQuery.add(realmId); } } NeutralQuery customRoleQuery = new NeutralQuery(); customRoleQuery.addCriteria(new NeutralCriteria("realmId", NeutralCriteria.CRITERIA_IN, realmsToQuery)); Iterable<String> customRoles = repo.findAllIds("customRole", customRoleQuery); for (String id : customRoles) { EntityBody result = service.get(id); results.add(result); } return Response.ok(results).build(); }  @PostConstruct void init(); @GET @RightsAllowed({Right.CRUD_ROLE }) Response readAll(@Context final UriInfo uriInfo,
            @DefaultValue("") @QueryParam("realmId") String realmId); @GET @Path("{id}") @RightsAllowed({Right.CRUD_ROLE }) Response read(@PathParam("id") String id, @Context final UriInfo uriInfo); @POST @RightsAllowed({Right.CRUD_ROLE }) Response createCustomRole(EntityBody newCustomRole, @Context final UriInfo uriInfo); @PUT @Path("{id}") @RightsAllowed({Right.CRUD_ROLE }) Response updateCustomRole(@PathParam("id") String id, EntityBody updated, @Context final UriInfo uriInfo); @DELETE @Path("{id}") @RightsAllowed({Right.CRUD_ROLE }) Response deleteCustomRole(@PathParam("id") String id, @Context final UriInfo uriInfo); static final String RESOURCE_NAME; }