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;
}
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);
}
}
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;
}
Aggregations