Search in sources :

Example 21 with ComplexAttribute

use of org.wso2.charon3.core.attributes.ComplexAttribute in project charon by wso2.

the class Group method getMembersWithDisplayName.

/*
     * get the members of the group with their display names
     * @return
     */
public List<String> getMembersWithDisplayName() {
    ArrayList displayNames = new ArrayList();
    if (this.isAttributeExist(SCIMConstants.GroupSchemaConstants.MEMBERS)) {
        MultiValuedAttribute members = (MultiValuedAttribute) this.attributeList.get(SCIMConstants.GroupSchemaConstants.MEMBERS);
        List<Attribute> values = members.getAttributeValues();
        if (values != null) {
            List<Attribute> subValuesList = members.getAttributeValues();
            for (Attribute subValue : subValuesList) {
                ComplexAttribute complexAttribute = (ComplexAttribute) subValue;
                Map<String, Attribute> subAttributesList = complexAttribute.getSubAttributesList();
                if (subAttributesList != null && subAttributesList.containsKey(SCIMConstants.CommonSchemaConstants.DISPLAY)) {
                    displayNames.add(((SimpleAttribute) (subAttributesList.get(SCIMConstants.CommonSchemaConstants.DISPLAY))).getValue());
                }
            }
            return displayNames;
        }
    }
    return displayNames;
}
Also used : MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) Attribute(org.wso2.charon3.core.attributes.Attribute) SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ArrayList(java.util.ArrayList) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute)

Example 22 with ComplexAttribute

use of org.wso2.charon3.core.attributes.ComplexAttribute in project charon by wso2.

the class AbstractSCIMObject method deleteValuesSubAttribute.

/*
     * Deleting a sub value's sub attribute of multivalued attribute is the responsibility of an attribute holder.
     *
     */
public void deleteValuesSubAttribute(String attribute, String subAttribute, String subSimpleAttribute) {
    if (attributeList.containsKey(attribute)) {
        MultiValuedAttribute parentAttribute = ((MultiValuedAttribute) attributeList.get(attribute));
        List<Attribute> attributeValues = parentAttribute.getAttributeValues();
        for (Attribute subValue : attributeValues) {
            if (subAttribute.equals(subValue.getName())) {
                ((ComplexAttribute) subValue).removeSubAttribute(subSimpleAttribute);
                break;
            }
        }
    }
}
Also used : MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) Attribute(org.wso2.charon3.core.attributes.Attribute) SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute)

Example 23 with ComplexAttribute

use of org.wso2.charon3.core.attributes.ComplexAttribute in project charon by wso2.

the class AbstractSCIMObject method setLastModified.

/*
     * set the last modified date and time of the resource
     *
     * @param lastModifiedDate
     */
public void setLastModified(Date lastModifiedDate) throws CharonException, BadRequestException {
    // create the lastModified date attribute as defined in schema.
    SimpleAttribute lastModifiedAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.LAST_MODIFIED, new SimpleAttribute(SCIMConstants.CommonSchemaConstants.LAST_MODIFIED, lastModifiedDate));
    // check meta complex attribute already exist.
    if (getMetaAttribute() != null) {
        ComplexAttribute metaAttribute = getMetaAttribute();
        // check last modified attribute already exist
        if (metaAttribute.isSubAttributeExist(lastModifiedAttribute.getName())) {
            metaAttribute.removeSubAttribute(lastModifiedAttribute.getName());
            metaAttribute.setSubAttribute(lastModifiedAttribute);
        } else {
            metaAttribute.setSubAttribute(lastModifiedAttribute);
        }
    } else {
        // create meta attribute and set the sub attribute.
        createMetaAttribute();
        getMetaAttribute().setSubAttribute(lastModifiedAttribute);
    }
}
Also used : SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute)

Example 24 with ComplexAttribute

use of org.wso2.charon3.core.attributes.ComplexAttribute in project charon by wso2.

the class AbstractSCIMObject method deleteSubValuesSubAttribute.

public void deleteSubValuesSubAttribute(String grandParentAttribute, String parentAttribute, String subValue, String childAttribute) {
    if (attributeList.containsKey(grandParentAttribute)) {
        ComplexAttribute grandParent = (ComplexAttribute) attributeList.get(grandParentAttribute);
        Map<String, Attribute> subAttributeList = grandParent.getSubAttributesList();
        MultiValuedAttribute parent = (MultiValuedAttribute) subAttributeList.get(parentAttribute);
        List<Attribute> parentAttributeList = parent.getAttributeValues();
        for (Attribute parentsSubValue : parentAttributeList) {
            if (subValue.equals(parentsSubValue.getName())) {
                ((ComplexAttribute) parentsSubValue).removeSubAttribute(childAttribute);
            }
        }
    }
}
Also used : MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) Attribute(org.wso2.charon3.core.attributes.Attribute) SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute)

Example 25 with ComplexAttribute

use of org.wso2.charon3.core.attributes.ComplexAttribute in project charon by wso2.

the class JSONDecoder method buildComplexValue.

/*
     * To build a complex type value of a Multi Valued Attribute. (eg. Email with value,type,primary as sub attributes
     *
     * @param attributeSchema
     * @param jsonObject
     * @return ComplexAttribute
     */
private ComplexAttribute buildComplexValue(AttributeSchema attributeSchema, JSONObject jsonObject) throws CharonException, BadRequestException {
    ComplexAttribute complexAttribute = new ComplexAttribute(attributeSchema.getName());
    Map<String, Attribute> subAttributesMap = new HashMap<String, Attribute>();
    List<SCIMAttributeSchema> subAttributeSchemas = ((SCIMAttributeSchema) attributeSchema).getSubAttributeSchemas();
    for (SCIMAttributeSchema subAttributeSchema : subAttributeSchemas) {
        Object subAttributeValue = jsonObject.opt(subAttributeSchema.getName());
        // setting up a name for the complex attribute for the reference purpose
        if (subAttributeSchema.getName().equals(SCIMConstants.CommonSchemaConstants.VALUE)) {
            // (value,type) pair is considered as a primary key for each entry
            if (subAttributeValue != null) {
                Object subAttributeValueForType = jsonObject.opt(SCIMConstants.CommonSchemaConstants.TYPE);
                if (subAttributeValueForType != null) {
                    complexAttribute.setName(attributeSchema.getName() + "_" + subAttributeValue + "_" + subAttributeValueForType);
                } else {
                    complexAttribute.setName(attributeSchema.getName() + "_" + subAttributeValue + "_" + SCIMConstants.DEFAULT);
                }
            } else {
                Object subAttributeValueFortype = jsonObject.opt(SCIMConstants.CommonSchemaConstants.TYPE);
                if (subAttributeValueFortype != null) {
                    complexAttribute.setName(attributeSchema.getName() + "_" + SCIMConstants.DEFAULT + "_" + subAttributeValueFortype);
                } else {
                    complexAttribute.setName(attributeSchema.getName() + "_" + SCIMConstants.DEFAULT + "_" + SCIMConstants.DEFAULT);
                }
            }
        }
        if (subAttributeValue != null) {
            if (subAttributeSchema.getMultiValued()) {
                if (subAttributeValue instanceof JSONArray) {
                    MultiValuedAttribute multiValuedAttribute = buildPrimitiveMultiValuedAttribute(subAttributeSchema, (JSONArray) subAttributeValue);
                    // let the attribute factory to set the sub attribute of a complex
                    // attribute to detect schema violations.
                    multiValuedAttribute = (MultiValuedAttribute) DefaultAttributeFactory.createAttribute(subAttributeSchema, multiValuedAttribute);
                    subAttributesMap.put(subAttributeSchema.getName(), multiValuedAttribute);
                } else {
                    throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
                }
            } else {
                if (subAttributeValue instanceof String || subAttributeValue instanceof Boolean || subAttributeValue instanceof Integer) {
                    SimpleAttribute simpleAttribute = buildSimpleAttribute(subAttributeSchema, subAttributeValue);
                    // let the attribute factory to set the sub attribute of a complex
                    // attribute to detect schema violations.
                    simpleAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(subAttributeSchema, simpleAttribute);
                    subAttributesMap.put(subAttributeSchema.getName(), simpleAttribute);
                } else {
                    throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
                }
            }
        }
    }
    complexAttribute.setSubAttributesList(subAttributesMap);
    return (ComplexAttribute) DefaultAttributeFactory.createAttribute(attributeSchema, complexAttribute);
}
Also used : MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute) SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) Attribute(org.wso2.charon3.core.attributes.Attribute) HashMap(java.util.HashMap) SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) SCIMAttributeSchema(org.wso2.charon3.core.schema.SCIMAttributeSchema) JSONArray(org.json.JSONArray) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) AbstractSCIMObject(org.wso2.charon3.core.objects.AbstractSCIMObject) JSONObject(org.json.JSONObject) SCIMObject(org.wso2.charon3.core.objects.SCIMObject)

Aggregations

ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)37 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)35 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)32 Attribute (org.wso2.charon3.core.attributes.Attribute)30 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)17 JSONObject (org.json.JSONObject)12 ArrayList (java.util.ArrayList)9 JSONArray (org.json.JSONArray)9 AbstractSCIMObject (org.wso2.charon3.core.objects.AbstractSCIMObject)8 AttributeSchema (org.wso2.charon3.core.schema.AttributeSchema)8 List (java.util.List)7 Map (java.util.Map)7 CharonException (org.wso2.charon3.core.exceptions.CharonException)7 JSONException (org.json.JSONException)6 AbstractAttribute (org.wso2.charon3.core.attributes.AbstractAttribute)6 HashMap (java.util.HashMap)4 JSONTokener (org.json.JSONTokener)4 SCIMObject (org.wso2.charon3.core.objects.SCIMObject)4 SCIMAttributeSchema (org.wso2.charon3.core.schema.SCIMAttributeSchema)4 Iterator (java.util.Iterator)2