Search in sources :

Example 1 with BulkRequestContent

use of org.wso2.charon3.core.objects.bulk.BulkRequestContent in project charon by wso2.

the class JSONDecoder method setRequestData.

private void setRequestData(String requestType, String requestMethod, String requestVersion, JSONObject member, List<BulkRequestContent> usersEndpointOperationList, List<BulkRequestContent> groupsEndpointOperationList) {
    // create user request list
    if (requestType.contains(SCIMConstants.USER_ENDPOINT)) {
        BulkRequestContent newRequestData = getBulkRequestContent(member, requestMethod, requestType, requestVersion);
        usersEndpointOperationList.add(newRequestData);
    }
    // create group request list
    if (requestType.contains(SCIMConstants.GROUP_ENDPOINT)) {
        BulkRequestContent newRequestData = getBulkRequestContent(member, requestMethod, requestType, requestVersion);
        groupsEndpointOperationList.add(newRequestData);
    }
}
Also used : BulkRequestContent(org.wso2.charon3.core.objects.bulk.BulkRequestContent)

Example 2 with BulkRequestContent

use of org.wso2.charon3.core.objects.bulk.BulkRequestContent in project charon by wso2.

the class BulkRequestProcessor method createBulkResponseContent.

private BulkResponseContent createBulkResponseContent(SCIMResponse response, String method, BulkRequestContent requestContent) {
    BulkResponseContent bulkResponseContent = new BulkResponseContent();
    bulkResponseContent.setScimResponse(response);
    bulkResponseContent.setMethod(method);
    bulkResponseContent.setLocation(response.getHeaderParamMap().get(SCIMConstants.LOCATION_HEADER));
    bulkResponseContent.setBulkID(requestContent.getBulkID());
    bulkResponseContent.setVersion(requestContent.getVersion());
    return bulkResponseContent;
}
Also used : BulkResponseContent(org.wso2.charon3.core.objects.bulk.BulkResponseContent)

Example 3 with BulkRequestContent

use of org.wso2.charon3.core.objects.bulk.BulkRequestContent in project charon by wso2.

the class JSONDecoder method getBulkRequestContent.

private BulkRequestContent getBulkRequestContent(JSONObject member, String requestMethod, String requestType, String requestVersion) {
    BulkRequestContent newRequestData = new BulkRequestContent();
    newRequestData.setData(member.optString(SCIMConstants.OperationalConstants.DATA));
    newRequestData.setBulkID(member.optString(SCIMConstants.OperationalConstants.BULK_ID));
    newRequestData.setMethod(requestMethod);
    newRequestData.setPath(requestType);
    newRequestData.setVersion(requestMethod);
    newRequestData.setVersion(requestVersion);
    return newRequestData;
}
Also used : BulkRequestContent(org.wso2.charon3.core.objects.bulk.BulkRequestContent)

Example 4 with BulkRequestContent

use of org.wso2.charon3.core.objects.bulk.BulkRequestContent in project charon by wso2.

the class JSONDecoder method decodeBulkData.

/**
 * Decode BulkRequestData Json Sting.
 *
 * @param bulkResourceString
 * @return BulkRequestData Object
 */
public BulkRequestData decodeBulkData(String bulkResourceString) throws BadRequestException {
    BulkRequestData bulkRequestDataObject = new BulkRequestData();
    List<BulkRequestContent> usersEndpointOperationList = new ArrayList<BulkRequestContent>();
    List<BulkRequestContent> groupsEndpointOperationList = new ArrayList<BulkRequestContent>();
    int failOnErrorsAttribute = 0;
    List<String> schemas = new ArrayList<String>();
    JSONObject decodedObject = null;
    try {
        decodedObject = new JSONObject(new JSONTokener(bulkResourceString));
        // prepare the schema list
        JSONArray membersAttributeSchemas = (JSONArray) decodedObject.opt(SCIMConstants.CommonSchemaConstants.SCHEMAS);
        for (int i = 0; i < membersAttributeSchemas.length(); i++) {
            schemas.add(membersAttributeSchemas.get(i).toString());
        }
        bulkRequestDataObject.setSchemas(schemas);
        // get [operations] from the Json String and prepare the request List
        JSONArray membersAttributeOperations = (JSONArray) decodedObject.opt(SCIMConstants.OperationalConstants.OPERATIONS);
        for (int i = 0; i < membersAttributeOperations.length(); i++) {
            JSONObject member = (JSONObject) membersAttributeOperations.get(i);
            // Request path - /Users or /Groups
            String requestType = member.optString(SCIMConstants.OperationalConstants.PATH);
            if (requestType == null) {
                throw new BadRequestException("Missing required attribute : path", ResponseCodeConstants.INVALID_SYNTAX);
            }
            // Request method  - POST,PUT..etc
            String requestMethod = member.optString(SCIMConstants.OperationalConstants.METHOD);
            if (requestMethod == null) {
                throw new BadRequestException("Missing required attribute : method", ResponseCodeConstants.INVALID_SYNTAX);
            }
            // Request version
            String requestVersion = member.optString(SCIMConstants.OperationalConstants.VERSION);
            if (requestMethod.equals(SCIMConstants.OperationalConstants.POST)) {
                if (!member.optString(SCIMConstants.OperationalConstants.BULK_ID).equals("") && member.optString(SCIMConstants.OperationalConstants.BULK_ID) != null) {
                    setRequestData(requestType, requestMethod, requestVersion, member, usersEndpointOperationList, groupsEndpointOperationList);
                } else {
                    String error = "JSON string could not be decoded properly.Required " + "attribute BULK_ID is missing in the request";
                    logger.error(error);
                    throw new BadRequestException(error, ResponseCodeConstants.INVALID_VALUE);
                }
            } else {
                setRequestData(requestType, requestMethod, requestVersion, member, usersEndpointOperationList, groupsEndpointOperationList);
            }
        }
        // extract [failOnErrors] attribute from Json string
        failOnErrorsAttribute = decodedObject.optInt(SCIMConstants.OperationalConstants.FAIL_ON_ERRORS);
        bulkRequestDataObject.setFailOnErrors(failOnErrorsAttribute);
        bulkRequestDataObject.setUserOperationRequests(usersEndpointOperationList);
        bulkRequestDataObject.setGroupOperationRequests(groupsEndpointOperationList);
    } catch (JSONException e1) {
        String error = "JSON string could not be decoded properly.";
        logger.error(error);
        throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
    }
    return bulkRequestDataObject;
}
Also used : JSONTokener(org.json.JSONTokener) BulkRequestData(org.wso2.charon3.core.objects.bulk.BulkRequestData) JSONObject(org.json.JSONObject) BulkRequestContent(org.wso2.charon3.core.objects.bulk.BulkRequestContent) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) JSONException(org.json.JSONException)

Example 5 with BulkRequestContent

use of org.wso2.charon3.core.objects.bulk.BulkRequestContent in project charon by wso2.

the class BulkRequestProcessor method getBulkResponseContent.

private BulkResponseContent getBulkResponseContent(BulkRequestContent bulkRequestContent, ResourceManager resourceManager) throws BadRequestException {
    BulkResponseContent bulkResponseContent = null;
    SCIMResponse response;
    if (bulkRequestContent.getMethod().equals(SCIMConstants.OperationalConstants.POST)) {
        response = resourceManager.create(bulkRequestContent.getData(), userManager, null, null);
        bulkResponseContent = createBulkResponseContent(response, SCIMConstants.OperationalConstants.POST, bulkRequestContent);
        errorsCheck(response);
    } else if (bulkRequestContent.getMethod().equals(SCIMConstants.OperationalConstants.PUT)) {
        String resourceId = extractIDFromPath(bulkRequestContent.getPath());
        response = resourceManager.updateWithPUT(resourceId, bulkRequestContent.getData(), userManager, null, null);
        bulkResponseContent = createBulkResponseContent(response, SCIMConstants.OperationalConstants.PUT, bulkRequestContent);
        errorsCheck(response);
    } else if (bulkRequestContent.getMethod().equals(SCIMConstants.OperationalConstants.PATCH)) {
        String resourceId = extractIDFromPath(bulkRequestContent.getPath());
        response = resourceManager.updateWithPATCH(resourceId, bulkRequestContent.getData(), userManager, null, null);
        bulkResponseContent = createBulkResponseContent(response, SCIMConstants.OperationalConstants.PATCH, bulkRequestContent);
        errorsCheck(response);
    } else if (bulkRequestContent.getMethod().equals(SCIMConstants.OperationalConstants.DELETE)) {
        String resourceId = extractIDFromPath(bulkRequestContent.getPath());
        response = resourceManager.delete(resourceId, userManager);
        bulkResponseContent = createBulkResponseContent(response, SCIMConstants.OperationalConstants.DELETE, bulkRequestContent);
        errorsCheck(response);
    }
    return bulkResponseContent;
}
Also used : BulkResponseContent(org.wso2.charon3.core.objects.bulk.BulkResponseContent)

Aggregations

BulkRequestContent (org.wso2.charon3.core.objects.bulk.BulkRequestContent)4 BulkResponseContent (org.wso2.charon3.core.objects.bulk.BulkResponseContent)2 ArrayList (java.util.ArrayList)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 JSONTokener (org.json.JSONTokener)1 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)1 BulkRequestData (org.wso2.charon3.core.objects.bulk.BulkRequestData)1 BulkResponseData (org.wso2.charon3.core.objects.bulk.BulkResponseData)1