Search in sources :

Example 26 with AttributeSchema

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);
}
Also used : SCIMAttributeSchema(org.wso2.charon3.core.schema.SCIMAttributeSchema) AttributeSchema(org.wso2.charon3.core.schema.AttributeSchema) ArrayList(java.util.ArrayList)

Aggregations

SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)19 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)18 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)18 Attribute (org.wso2.charon3.core.attributes.Attribute)17 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)17 AttributeSchema (org.wso2.charon3.core.schema.AttributeSchema)11 ArrayList (java.util.ArrayList)10 JSONObject (org.json.JSONObject)10 JSONArray (org.json.JSONArray)8 AbstractAttribute (org.wso2.charon3.core.attributes.AbstractAttribute)8 AbstractSCIMObject (org.wso2.charon3.core.objects.AbstractSCIMObject)8 List (java.util.List)7 JSONException (org.json.JSONException)7 SCIMAttributeSchema (org.wso2.charon3.core.schema.SCIMAttributeSchema)7 SCIMObject (org.wso2.charon3.core.objects.SCIMObject)6 CharonException (org.wso2.charon3.core.exceptions.CharonException)5 JSONTokener (org.json.JSONTokener)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 SCIMDefinitions (org.wso2.charon3.core.schema.SCIMDefinitions)2