Search in sources :

Example 16 with DuplicateEntryException

use of org.gluu.site.ldap.exception.DuplicateEntryException in project oxTrust by GluuFederation.

the class GroupWebService method createGroup.

@POST
@Consumes({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Create group", notes = "Create group (https://tools.ietf.org/html/rfc7644#section-3.3)", response = Group.class)
public Response createGroup(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @ApiParam(value = "Group", required = true) Group group, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
    Response authorizationResponse;
    if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
        log.info(" ##### SCIM Test Mode is ACTIVE");
        authorizationResponse = processTestModeAuthorization(token);
    } else {
        authorizationResponse = processAuthorization(authorization);
    }
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        Group createdGroup = scim2GroupService.createGroup(group);
        // Serialize to JSON
        String json = serializeToJson(createdGroup, attributesArray);
        URI location = new URI(createdGroup.getMeta().getLocation());
        // Return HTTP response with status code 201 Created
        return Response.created(location).entity(json).build();
    } catch (DuplicateEntryException ex) {
        log.error("DuplicateEntryException", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage());
    } catch (Exception ex) {
        log.error("Failed to create group", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Group(org.gluu.oxtrust.model.scim2.Group) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Aggregations

DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)16 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)15 Consumes (javax.ws.rs.Consumes)10 Produces (javax.ws.rs.Produces)10 Response (javax.ws.rs.core.Response)10 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)10 URI (java.net.URI)8 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)8 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)6 DefaultValue (javax.ws.rs.DefaultValue)6 HeaderParam (javax.ws.rs.HeaderParam)6 PUT (javax.ws.rs.PUT)6 Path (javax.ws.rs.Path)6 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)6 GluuGroup (org.gluu.oxtrust.model.GluuGroup)6 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)6 User (org.gluu.oxtrust.model.scim2.User)5 POST (javax.ws.rs.POST)4 Group (org.gluu.oxtrust.model.scim2.Group)4 ScimPatchUser (org.gluu.oxtrust.model.scim2.ScimPatchUser)4