Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bulk get support. #396

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -587,30 +587,29 @@ private void encodeResponseContent(BulkResponseContent responseContent,
ArrayList<JSONObject> operationResponseList)
throws JSONException {

JSONObject operationObject = new JSONObject();
int statusCode = responseContent.getScimResponse().getResponseStatus();

JSONObject status = new JSONObject();
int statusCode = responseContent.getScimResponse().getResponseStatus();
status.put(SCIMConstants.OperationalConstants.CODE, statusCode);


JSONObject operationObject = new JSONObject();
operationObject.put(SCIMConstants.CommonSchemaConstants.LOCATION, responseContent.getLocation());
operationObject.put(SCIMConstants.OperationalConstants.METHOD, responseContent.getMethod());
operationObject.put(SCIMConstants.OperationalConstants.BULK_ID, responseContent.getBulkID());
operationObject.put(SCIMConstants.OperationalConstants.STATUS, status);

//When indicating a response with an HTTP status other than a 200-series response,
// When indicating a response with an HTTP status other than a 200-series response,
// the response body MUST be included.
if (statusCode != 200 && statusCode != 201 && statusCode != 204) {
//
// Addition: 2023/11/15
// We are now supporting bulk get as well. Hence, even with 200 responses, we can get a body. Hence, null
// checking the scim response and if not null adding the response as well.
// Keeping the old status code check for backward compatibility.
if ((statusCode != 200 && statusCode != 201 && statusCode != 204)
|| responseContent.getScimResponse() != null) {
operationObject.put(SCIMConstants.OperationalConstants.RESPONSE,
responseContent.getScimResponse().getResponseMessage());
}

operationResponseList.add(operationObject);

}
}




Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,60 @@ private BulkResponseContent getBulkResponseContent(BulkRequestContent bulkReques
errorsCheck(response);
break;
}

case SCIMConstants.OperationalConstants.GET: {
String resourceId = extractIDFromPath(bulkRequestContent.getPath());
String attributes = getAttributesFromData(bulkRequestContent.getData());
String excludeAttributes = getExcludedAttributesFromData(bulkRequestContent.getData());

if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_V2_ENDPOINT)) {
resourceId = extractIDFromV2Path(bulkRequestContent.getPath());
response = resourceManager.getRole(resourceId, roleV2Manager, attributes, excludeAttributes);
} else if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_ENDPOINT)) {
response = resourceManager.getRole(resourceId, roleManager, attributes, excludeAttributes);
} else {
response = resourceManager.get(resourceId, userManager, attributes, excludeAttributes);
}

bulkResponseContent = createBulkResponseContent(response, SCIMConstants.OperationalConstants.GET,
bulkRequestContent);
errorsCheck(response);
break;
}
}
return bulkResponseContent;
}

private String getExcludedAttributesFromData(String data) throws BadRequestException {

String excludedAttributes = null;
try {
JSONObject dataJson = new JSONObject(data);
if (dataJson.has(SCIMConstants.CommonSchemaConstants.EXCLUDE_ATTRIBUTES)) {
excludedAttributes = dataJson.getString(SCIMConstants.CommonSchemaConstants.EXCLUDE_ATTRIBUTES);
}
} catch (JSONException e) {
throw new BadRequestException("Error while parsing the data field of the bulk request content",
ResponseCodeConstants.INVALID_SYNTAX);
}
return excludedAttributes;
}

private String getAttributesFromData(String data) throws BadRequestException {

String attributes = null;
try {
JSONObject dataJson = new JSONObject(data);
if (dataJson.has(SCIMConstants.CommonSchemaConstants.ATTRIBUTES)) {
attributes = dataJson.getString(SCIMConstants.CommonSchemaConstants.ATTRIBUTES);
}
} catch (JSONException e) {
throw new BadRequestException("Error while parsing the data field of the bulk request content",
ResponseCodeConstants.INVALID_SYNTAX);
}
return attributes;
}

private String extractIDFromPath(String path) throws BadRequestException {

String [] parts = path.split("[/]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public static class CommonSchemaConstants {
public static final String VERSION_DESC = "The version of the resource being returned.";
public static final String SYSTEM_ROLE_DESC = "Whether the returned role is a read only system role.";

public static final String ATTRIBUTES = "attributes";
public static final String EXCLUDE_ATTRIBUTES = "excludedAttributes";
}

/**
Expand Down Expand Up @@ -830,6 +832,7 @@ public static class OperationalConstants {
public static final String DELETE = "DELETE";
public static final String PUT = "PUT";
public static final String PATCH = "PATCH";
public static final String GET = "GET";

public static final String COLON = ":";
public static final String URL_SEPARATOR = "/";
Expand Down
Loading