Search in sources :

Example 41 with GluuGroup

use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.

the class GroupWebService method getGroupById.

@Path("{id}")
@GET
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi
@RefAdjusted
@ApiOperation(value = "Find group by id", notes = "Returns a group by id as path param (https://tools.ietf.org/html/rfc7644#section-3.4.2.1)", response = GroupResource.class)
public Response getGroupById(@PathParam("id") String id, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. getGroupById");
        GroupResource group = new GroupResource();
        // gluuGroup is not null (check associated decorator method)
        GluuGroup gluuGroup = groupService.getGroupByInum(id);
        scim2GroupService.transferAttributesToGroupResource(gluuGroup, group, endpointUrl, userWebService.getEndpointUrl());
        String json = resourceSerializer.serialize(group, attrsList, excludedAttrsList);
        response = Response.ok(new URI(group.getMeta().getLocation())).entity(json).build();
    } catch (Exception e) {
        log.error("Failure at getGroupById method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) GluuGroup(org.gluu.oxtrust.model.GluuGroup) URI(java.net.URI) GroupResource(org.gluu.oxtrust.model.scim2.group.GroupResource) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 42 with GluuGroup

use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.

the class CleanUpTest method cleanUpGroups.

/**
 * Test search
 *
 * @throws Exception
 */
// @Test
@Parameters(value = "test.keep.persons")
public void cleanUpGroups(String usedGroups) throws Exception {
    System.out.println("cleanup person Test initialted ");
    assertNotNull(usedGroups);
    List<String> usedGroupsList = Arrays.asList(StringHelper.split(usedGroups, ",", true, false));
    System.out.println("Used Groups: " + usedGroupsList);
    int groupsResultSetSize = 50;
    int countResults = 0;
    int countRemoved = 0;
    boolean existsMoreGroups = true;
    while (existsMoreGroups && countResults < 10000) {
        List<GluuGroup> groups = groupsService.getAllGroups();
        existsMoreGroups = groups.size() == groupsResultSetSize;
        countResults += groups.size();
        assertNotNull(groups);
        System.out.println("Found groups: " + groups.size());
        System.out.println("Total groups: " + countResults);
        for (GluuGroup group : groups) {
            // String clientId = person.getClientId();
            if (!usedGroupsList.contains(group.getInum())) {
                try {
                    groupsService.removeGroup(group);
                    countRemoved++;
                } catch (EntryPersistenceException ex) {
                    System.out.println("Failed to remove group: " + ex.getMessage());
                }
            }
        }
    }
    System.out.println("Removed Persons: " + countRemoved);
}
Also used : EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Parameters(org.testng.annotations.Parameters)

Aggregations

GluuGroup (org.gluu.oxtrust.model.GluuGroup)42 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)13 Produces (javax.ws.rs.Produces)11 Response (javax.ws.rs.core.Response)11 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)11 ArrayList (java.util.ArrayList)10 URI (java.net.URI)7 Path (javax.ws.rs.Path)7 ScimGroup (org.gluu.oxtrust.model.scim.ScimGroup)6 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)6 DefaultValue (javax.ws.rs.DefaultValue)5 GET (javax.ws.rs.GET)5 HeaderParam (javax.ws.rs.HeaderParam)5 Group (org.gluu.oxtrust.model.scim2.Group)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4 Date (java.util.Date)4 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)4 Consumes (javax.ws.rs.Consumes)4 ListViewResponse (org.gluu.persist.model.ListViewResponse)4 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)3