Search in sources :

Example 16 with MultiValuedAttribute

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

the class JSONEncoder method encodeComplexAttribute.

/*
     * Encode the complex attribute and include it in root json object to be returned.
     *
     * @param complexAttribute
     * @param rootObject
     */
public void encodeComplexAttribute(ComplexAttribute complexAttribute, JSONObject rootObject) throws JSONException {
    JSONObject subObject = new JSONObject();
    Map<String, Attribute> attributes = complexAttribute.getSubAttributesList();
    for (Attribute attributeValue : attributes.values()) {
        // using instanceof instead of polymorphic way, in order to make encoder pluggable.
        if (attributeValue instanceof SimpleAttribute) {
            // most of the time, this if condition is hit according to current SCIM spec.
            encodeSimpleAttribute((SimpleAttribute) attributeValue, subObject);
        } else if (attributeValue instanceof MultiValuedAttribute) {
            encodeMultiValuedAttribute((MultiValuedAttribute) attributeValue, subObject);
        } else if (attributeValue instanceof ComplexAttribute) {
            encodeComplexAttribute((ComplexAttribute) attributeValue, subObject);
        }
        rootObject.put(complexAttribute.getName(), subObject);
    }
}
Also used : JSONObject(org.json.JSONObject) 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) SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute)

Example 17 with MultiValuedAttribute

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

the class JSONEncoder method getSCIMObjectAsJSONObject.

/*
     * Make JSON object from given SCIM object.
     *
     * @param scimObject
     * @return the resulting string after encoding.
     */
public JSONObject getSCIMObjectAsJSONObject(SCIMObject scimObject) throws CharonException {
    // root json object containing the encoded SCIM Object.
    JSONObject rootObject = new JSONObject();
    try {
        // encode schemas
        this.encodeArrayOfValues(SCIMConstants.CommonSchemaConstants.SCHEMAS, (scimObject.getSchemaList()).toArray(), rootObject);
        // encode attribute list
        Map<String, Attribute> attributes = scimObject.getAttributeList();
        if (attributes != null && !attributes.isEmpty()) {
            for (Attribute attribute : attributes.values()) {
                // using instanceof instead of polymorphic way, in order to make encoder pluggable.
                if (attribute instanceof SimpleAttribute) {
                    encodeSimpleAttribute((SimpleAttribute) attribute, rootObject);
                } else if (attribute instanceof ComplexAttribute) {
                    encodeComplexAttribute((ComplexAttribute) attribute, rootObject);
                } else if (attribute instanceof MultiValuedAttribute) {
                    encodeMultiValuedAttribute((MultiValuedAttribute) attribute, rootObject);
                }
            }
        }
    } catch (JSONException e) {
        String errorMessage = "Error in encoding resource..";
        // TODO:log the error
        throw new CharonException(errorMessage);
    }
    return rootObject;
}
Also used : JSONObject(org.json.JSONObject) 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) SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) JSONException(org.json.JSONException) CharonException(org.wso2.charon3.core.exceptions.CharonException) AbstractCharonException(org.wso2.charon3.core.exceptions.AbstractCharonException) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute)

Example 18 with MultiValuedAttribute

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

the class Group method setMember.

/*
     * set a member to the group
     * @param userId
     * @param userName
     * @throws BadRequestException
     * @throws CharonException
     */
public void setMember(String userId, String userName) throws BadRequestException, CharonException {
    if (this.isAttributeExist(SCIMConstants.GroupSchemaConstants.MEMBERS)) {
        MultiValuedAttribute members = (MultiValuedAttribute) this.attributeList.get(SCIMConstants.GroupSchemaConstants.MEMBERS);
        ComplexAttribute complexAttribute = setMemberCommon(userId, userName);
        members.setAttributeValue(complexAttribute);
    } else {
        MultiValuedAttribute members = new MultiValuedAttribute(SCIMConstants.GroupSchemaConstants.MEMBERS);
        DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.MEMBERS, members);
        ComplexAttribute complexAttribute = setMemberCommon(userId, userName);
        members.setAttributeValue(complexAttribute);
        this.setAttribute(members);
    }
}
Also used : ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute)

Example 19 with MultiValuedAttribute

use of org.wso2.charon3.core.attributes.MultiValuedAttribute 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 20 with MultiValuedAttribute

use of org.wso2.charon3.core.attributes.MultiValuedAttribute 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)

Aggregations

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