Search in sources :

Example 1 with BulkResponseData

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

the class JSONEncoder method encodeBulkResponseData.

/*
     * Encode given bulkResponseData object and return the encoded string
     *
     * @param bulkResponseData
     * @return
     */
public String encodeBulkResponseData(BulkResponseData bulkResponseData) throws InternalErrorException {
    String encodedString = "";
    List<BulkResponseContent> userResponseDataList = bulkResponseData.getUserOperationResponse();
    List<BulkResponseContent> groupResponseDataList = bulkResponseData.getGroupOperationResponse();
    JSONObject rootObject = new JSONObject();
    // encode schemas
    try {
        // set the [schemas]
        this.encodeArrayOfValues(SCIMConstants.CommonSchemaConstants.SCHEMAS, bulkResponseData.getSchemas().toArray(), rootObject);
        // [Operations] - multi value attribute
        ArrayList<JSONObject> operationResponseList = new ArrayList<>();
        for (BulkResponseContent userOperationResponse : userResponseDataList) {
            encodeResponseContent(userOperationResponse, operationResponseList);
        }
        for (BulkResponseContent groupOperationResponse : groupResponseDataList) {
            encodeResponseContent(groupOperationResponse, operationResponseList);
        }
        // set operations
        this.encodeArrayOfValues(SCIMConstants.OperationalConstants.OPERATIONS, operationResponseList.toArray(), rootObject);
        encodedString = rootObject.toString();
    } catch (JSONException e) {
        throw new InternalErrorException("Error in encoding the response");
    }
    return encodedString;
}
Also used : BulkResponseContent(org.wso2.charon3.core.objects.bulk.BulkResponseContent) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException)

Example 2 with BulkResponseData

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

the class BulkResourceManager method processBulkData.

public SCIMResponse processBulkData(String data, UserManager userManager) {
    BulkResponseData bulkResponseData;
    try {
        // Get encoder and decoder from AbstractResourceEndpoint
        encoder = getEncoder();
        decoder = getDecoder();
        BulkRequestData bulkRequestDataObject;
        // decode the request
        bulkRequestDataObject = decoder.decodeBulkData(data);
        bulkRequestProcessor.setFailOnError(bulkRequestDataObject.getFailOnErrors());
        bulkRequestProcessor.setUserManager(userManager);
        // Get bulk response data
        bulkResponseData = bulkRequestProcessor.processBulkRequests(bulkRequestDataObject);
        // encode the BulkResponseData object
        String finalEncodedResponse = encoder.encodeBulkResponseData(bulkResponseData);
        // careate SCIM response message
        Map<String, String> responseHeaders = new HashMap<String, String>();
        // add location header
        responseHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
        // create the final response
        return new SCIMResponse(ResponseCodeConstants.CODE_OK, finalEncodedResponse, responseHeaders);
    } catch (CharonException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (BadRequestException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (InternalErrorException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    }
}
Also used : BulkRequestData(org.wso2.charon3.core.objects.bulk.BulkRequestData) HashMap(java.util.HashMap) BulkResponseData(org.wso2.charon3.core.objects.bulk.BulkResponseData) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) CharonException(org.wso2.charon3.core.exceptions.CharonException) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse)

Example 3 with BulkResponseData

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

the class BulkRequestProcessor method processBulkRequests.

public BulkResponseData processBulkRequests(BulkRequestData bulkRequestData) throws BadRequestException {
    BulkResponseData bulkResponseData = new BulkResponseData();
    SCIMResponse response = null;
    for (BulkRequestContent bulkRequestContent : bulkRequestData.getUserOperationRequests()) {
        if (failOnError == 0) {
            bulkResponseData.addUserOperation(getBulkResponseContent(bulkRequestContent, userResourceManager));
        } else {
            if (errors < failOnError) {
                bulkResponseData.addUserOperation(getBulkResponseContent(bulkRequestContent, userResourceManager));
            }
        }
    }
    for (BulkRequestContent bulkRequestContent : bulkRequestData.getGroupOperationRequests()) {
        if (failOnError == 0) {
            bulkResponseData.addGroupOperation(getBulkResponseContent(bulkRequestContent, groupResourceManager));
        } else {
            if (errors < failOnError) {
                bulkResponseData.addGroupOperation(getBulkResponseContent(bulkRequestContent, groupResourceManager));
            }
        }
    }
    bulkResponseData.setSchema(SCIMConstants.BULK_RESPONSE_URI);
    return bulkResponseData;
}
Also used : BulkRequestContent(org.wso2.charon3.core.objects.bulk.BulkRequestContent) BulkResponseData(org.wso2.charon3.core.objects.bulk.BulkResponseData)

Aggregations

InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)2 BulkResponseData (org.wso2.charon3.core.objects.bulk.BulkResponseData)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)1 CharonException (org.wso2.charon3.core.exceptions.CharonException)1 BulkRequestContent (org.wso2.charon3.core.objects.bulk.BulkRequestContent)1 BulkRequestData (org.wso2.charon3.core.objects.bulk.BulkRequestData)1 BulkResponseContent (org.wso2.charon3.core.objects.bulk.BulkResponseContent)1 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)1