Search in sources :

Example 1 with BulkResponseContent

use of org.wso2.charon3.core.objects.bulk.BulkResponseContent 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 2 with BulkResponseContent

use of org.wso2.charon3.core.objects.bulk.BulkResponseContent 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 3 with BulkResponseContent

use of org.wso2.charon3.core.objects.bulk.BulkResponseContent 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

BulkResponseContent (org.wso2.charon3.core.objects.bulk.BulkResponseContent)3 ArrayList (java.util.ArrayList)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)1