Skip to content

Commit

Permalink
Include support for attributes and excluded attributes in bulk GET th…
Browse files Browse the repository at this point in the history
…rough path parameters
  • Loading branch information
ChanikaRuchini committed Jan 24, 2024
1 parent 4aa1bb5 commit 232ca13
Showing 1 changed file with 54 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
import org.wso2.charon3.core.protocol.endpoints.UserResourceManager;
import org.wso2.charon3.core.schema.SCIMConstants;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
*
Expand Down Expand Up @@ -292,12 +294,20 @@ private BulkResponseContent getBulkResponseContent(BulkRequestContent bulkReques
}

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

String resourceId = extractIDFromGetRequestPath(bulkRequestContent.getPath());
Map<String, String> queryParams = parseQueryParameters(bulkRequestContent.getPath());
String attributes = queryParams.get(SCIMConstants.CommonSchemaConstants.ATTRIBUTES);
String excludeAttributes = queryParams.get(SCIMConstants.CommonSchemaConstants.EXCLUDE_ATTRIBUTES);
if (StringUtils.isNotBlank(bulkRequestContent.getData())) {
if (StringUtils.isBlank(attributes)) {
attributes = getAttributesFromData(bulkRequestContent.getData());
}
if (StringUtils.isBlank(excludeAttributes)) {
excludeAttributes = getExcludedAttributesFromData(bulkRequestContent.getData());
}
}
if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_V2_ENDPOINT)) {
resourceId = extractIDFromV2Path(bulkRequestContent.getPath());
resourceId = extractIDFromV2GetRequestPath(bulkRequestContent.getPath());
response = resourceManager.getRole(resourceId, roleV2Manager, attributes, excludeAttributes);
} else if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_ENDPOINT)) {
response = resourceManager.getRole(resourceId, roleManager, attributes, excludeAttributes);
Expand Down Expand Up @@ -355,6 +365,32 @@ private String extractIDFromPath(String path) throws BadRequestException {
}
}

private String extractIDFromGetRequestPath(String path) throws BadRequestException {

String[] parts = path.split("[?]");
if (parts.length == 1) {
return extractIDFromPath(path);
}
if (parts[0] != null) {
return extractIDFromPath(parts[0]);
}
throw new BadRequestException
("No resource Id is provided in path", ResponseCodeConstants.INVALID_VALUE);
}

private static Map<String, String> parseQueryParameters(String path) {

String[] parts = path.split("[?]");
if (parts.length < 2) {
return new HashMap<>();
}
return Arrays.stream(parts[1].split("&"))
.map(param -> param.split("="))
.collect(Collectors.toMap(
pair -> pair[0],
pair -> pair.length > 1 ? pair[1] : ""));
}

private String extractIDFromV2Path(String path) throws BadRequestException {

String [] parts = path.split("[/]");
Expand All @@ -365,6 +401,19 @@ private String extractIDFromV2Path(String path) throws BadRequestException {
("No resource Id is provided in path", ResponseCodeConstants.INVALID_VALUE);
}

private String extractIDFromV2GetRequestPath(String path) throws BadRequestException {

String[] parts = path.split("[?]");
if (parts.length == 1) {
return extractIDFromV2Path(path);
}
if (parts[0] != null) {
return extractIDFromV2Path(parts[0]);
}
throw new BadRequestException
("No resource Id is provided in path", ResponseCodeConstants.INVALID_VALUE);
}

private BulkResponseContent createBulkResponseContent(SCIMResponse response, String method,
BulkRequestContent requestContent) {

Expand Down

0 comments on commit 232ca13

Please sign in to comment.