Search in sources :

Example 1 with BulkResponses

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

the class BulkWebService method bulkOperation.

@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response bulkOperation(@Context HttpServletRequest request, @HeaderParam("Authorization") String authorization, ScimBulkOperation operation) throws Exception {
    Response authorizationResponse = processAuthorization(authorization);
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    String domain;
    URL reconstructedURL;
    reconstructedURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), "");
    domain = reconstructedURL.toString();
    log.info(" getting list of BulkRequest ");
    List<BulkRequests> bulkRequests = operation.getOperations();
    ScimBulkResponse scimBulkResponse = new ScimBulkResponse();
    List<BulkResponses> listResponses = new ArrayList<BulkResponses>();
    for (BulkRequests oneRequest : bulkRequests) {
        log.info(" checking operations ");
        if (oneRequest.getPath().contains("Users")) {
            log.info("  operations is for Users ");
            log.info(" method : " + oneRequest.getMethod());
            if (oneRequest.getMethod().equalsIgnoreCase("POST")) {
                log.info(" method is post ");
                String bulkId = oneRequest.getBulkId();
                String method = oneRequest.getMethod();
                ScimPerson person = oneRequest.getData();
                boolean status = createUser(person);
                if (status) {
                    log.info(" POST status is true ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setBulkId(bulkId);
                    bulkResponses.setMethod(method);
                    GluuCustomPerson gluuPerson = personService.getPersonByUid(person.getUserName());
                    String iD = gluuPerson.getInum();
                    String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Users/").append(iD).toString();
                    bulkResponses.setLocation(location);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("201");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                } else if (!status) {
                    log.info(" POST status is false ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setBulkId(bulkId);
                    bulkResponses.setMethod(method);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("400");
                    result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                }
            } else if (oneRequest.getMethod().equalsIgnoreCase("PUT")) {
                log.info(" Status is PUT ");
                String method = oneRequest.getMethod();
                String version = oneRequest.getVersion();
                String path = oneRequest.getPath();
                ScimPerson person = oneRequest.getData();
                String personiD = getId(path);
                log.info(" Inum :  " + getId(path));
                boolean status = updateUser(personiD, person);
                if (status) {
                    log.info(" PUT status is true ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setMethod(method);
                    String iD = personiD;
                    String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Users/").append(iD).toString();
                    bulkResponses.setLocation(location);
                    EntityTag eTag = new EntityTag(version, true);
                    String newVersion = eTag.getValue();
                    bulkResponses.setVersion(newVersion);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("200");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                } else if (!status) {
                    log.info(" PUT status is false ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setMethod(method);
                    bulkResponses.setVersion(version);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("400");
                    result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                }
            } else if (oneRequest.getMethod().equalsIgnoreCase("DELETE")) {
                log.info(" Operation is DELETE ");
                String method = oneRequest.getMethod();
                String path = oneRequest.getPath();
                String personiD = getId(path);
                boolean status = deleteUser(personiD);
                if (status) {
                    log.info(" DELETE operation is true ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setMethod(method);
                    String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Users/").append(personiD).toString();
                    bulkResponses.setLocation(location);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("200");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                } else if (!status) {
                    log.info(" DELETE operation is False ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setMethod(method);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("400");
                    result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                }
            }
        //
        } else if (oneRequest.getPath().contains("Groups")) {
            if (oneRequest.getMethod().equalsIgnoreCase("POST")) {
                log.info(" method is post ");
                String bulkId = oneRequest.getBulkId();
                String method = oneRequest.getMethod();
                ScimGroup group = copyUtils.copy(oneRequest.getData(), null);
                boolean status = createGroup(group);
                if (status) {
                    log.info(" POST status is true ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setBulkId(bulkId);
                    bulkResponses.setMethod(method);
                    GluuGroup gluuGroup = groupService.getGroupByDisplayName(group.getDisplayName());
                    String iD = gluuGroup.getInum();
                    String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Groups/").append(iD).toString();
                    bulkResponses.setLocation(location);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("201");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                } else if (!status) {
                    log.info(" POST status is false ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setBulkId(bulkId);
                    bulkResponses.setMethod(method);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("400");
                    result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                }
            } else if (oneRequest.getMethod().equalsIgnoreCase("PUT")) {
                log.info(" Status is PUT ");
                String method = oneRequest.getMethod();
                String version = oneRequest.getVersion();
                String path = oneRequest.getPath();
                ScimGroup group = copyUtils.copy(oneRequest.getData(), null);
                String groupiD = getId(path);
                boolean status = updateGroup(groupiD, group);
                if (status) {
                    log.info(" PUT status is true ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setMethod(method);
                    String iD = groupiD;
                    String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Groups/").append(iD).toString();
                    bulkResponses.setLocation(location);
                    EntityTag eTag = new EntityTag(version, true);
                    String newVersion = eTag.getValue();
                    bulkResponses.setVersion(newVersion);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("200");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                } else if (!status) {
                    log.info(" PUT status is false ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setMethod(method);
                    bulkResponses.setVersion(version);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("400");
                    result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                }
            } else if (oneRequest.getMethod().equalsIgnoreCase("DELETE")) {
                log.info(" Operation is DELETE ");
                String method = oneRequest.getMethod();
                String path = oneRequest.getPath();
                String groupiD = getId(path);
                boolean status = deleteGroup(groupiD);
                if (status) {
                    log.info(" DELETE operation is true ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setMethod(method);
                    String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Groups/").append(groupiD).toString();
                    bulkResponses.setLocation(location);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("200");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                } else if (!status) {
                    log.info(" DELETE operation is False ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setMethod(method);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("400");
                    result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                }
            }
        }
    }
    List<String> schemas = new ArrayList<String>();
    schemas.add(Constants.SCIM1_CORE_SCHEMA_ID);
    scimBulkResponse.setSchemas(schemas);
    scimBulkResponse.setOperations(listResponses);
    URI location = new URI("/Bulk/");
    return Response.ok(scimBulkResponse).location(location).build();
}
Also used : BulkResponseStatus(org.gluu.oxtrust.model.scim.BulkResponseStatus) BulkResponses(org.gluu.oxtrust.model.scim.BulkResponses) BulkRequests(org.gluu.oxtrust.model.scim.BulkRequests) ScimBulkResponse(org.gluu.oxtrust.model.scim.ScimBulkResponse) ArrayList(java.util.ArrayList) GluuGroup(org.gluu.oxtrust.model.GluuGroup) URI(java.net.URI) URL(java.net.URL) ScimBulkResponse(org.gluu.oxtrust.model.scim.ScimBulkResponse) Response(javax.ws.rs.core.Response) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ScimPerson(org.gluu.oxtrust.model.scim.ScimPerson) EntityTag(javax.ws.rs.core.EntityTag) ScimGroup(org.gluu.oxtrust.model.scim.ScimGroup) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

URI (java.net.URI)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 EntityTag (javax.ws.rs.core.EntityTag)1 Response (javax.ws.rs.core.Response)1 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)1 GluuGroup (org.gluu.oxtrust.model.GluuGroup)1 BulkRequests (org.gluu.oxtrust.model.scim.BulkRequests)1 BulkResponseStatus (org.gluu.oxtrust.model.scim.BulkResponseStatus)1 BulkResponses (org.gluu.oxtrust.model.scim.BulkResponses)1 ScimBulkResponse (org.gluu.oxtrust.model.scim.ScimBulkResponse)1 ScimGroup (org.gluu.oxtrust.model.scim.ScimGroup)1 ScimPerson (org.gluu.oxtrust.model.scim.ScimPerson)1