use of org.wso2.charon3.core.schema.AttributeSchema in project charon by wso2.
the class ResourceManagerUtil method getOnlyRequiredAttributesURIs.
/*
* this method is to get the uri list of the attributes which need to retrieved from the databases.
* Note that we should consider the 'attributes' and 'excludedAttributes' parameters for this process.
*
* @param schema
* @param requestedAttributes
* @param requestedExcludingAttributes
* @return
* @throws CharonException
*/
public static Map<String, Boolean> getOnlyRequiredAttributesURIs(SCIMResourceTypeSchema schema, String requestedAttributes, String requestedExcludingAttributes) throws CharonException {
ArrayList<AttributeSchema> attributeSchemaArrayList = (ArrayList<AttributeSchema>) CopyUtil.deepCopy(schema.getAttributesList());
List<String> requestedAttributesList = null;
List<String> requestedExcludingAttributesList = null;
if (requestedAttributes != null) {
// make a list from the comma separated requestedAttributes
requestedAttributesList = Arrays.asList(requestedAttributes.split(","));
}
if (requestedExcludingAttributes != null) {
// make a list from the comma separated requestedExcludingAttributes
requestedExcludingAttributesList = Arrays.asList(requestedExcludingAttributes.split(","));
}
ArrayList<AttributeSchema> attributeList = schema.getAttributesList();
for (AttributeSchema attributeSchema : attributeList) {
// check for never/request attributes.
if (attributeSchema.getReturned().equals(SCIMDefinitions.Returned.NEVER)) {
removeAttributesFromList(attributeSchemaArrayList, attributeSchema.getName());
}
// If so return it.
if (requestedAttributes == null && requestedExcludingAttributes == null) {
if (attributeSchema.getReturned().equals(SCIMDefinitions.Returned.REQUEST)) {
removeAttributesFromList(attributeSchemaArrayList, attributeSchema.getName());
}
} else {
// A request should only contains either attributes or exclude attribute params. Not both
if (requestedAttributes != null) {
// and add only the requested attributes
if ((attributeSchema.getReturned().equals(SCIMDefinitions.Returned.DEFAULT) || attributeSchema.getReturned().equals(SCIMDefinitions.Returned.REQUEST)) && (!requestedAttributesList.contains(attributeSchema.getName()) && !isSubAttributeExistsInList(requestedAttributesList, attributeSchema))) {
removeAttributesFromList(attributeSchemaArrayList, attributeSchema.getName());
}
} else if (requestedExcludingAttributes != null) {
// removing attributes which has returned as request. This is because no request is made
if (attributeSchema.getReturned().equals(SCIMDefinitions.Returned.REQUEST)) {
removeAttributesFromList(attributeSchemaArrayList, attributeSchema.getName());
}
// removed from the default set of attributes
if ((attributeSchema.getReturned().equals(SCIMDefinitions.Returned.DEFAULT)) && requestedExcludingAttributesList.contains(attributeSchema.getName())) {
removeAttributesFromList(attributeSchemaArrayList, attributeSchema.getName());
}
}
}
getOnlyRequiredSubAttributesURIs(attributeSchema, attributeSchemaArrayList, requestedAttributes, requestedExcludingAttributes, requestedAttributesList, requestedExcludingAttributesList);
}
return convertSchemasToURIs(attributeSchemaArrayList);
}
Aggregations