Search in sources :

Example 16 with ComplexAttribute

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

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

the class AbstractSCIMObject method deleteSubSubAttribute.

/*
     * This deletion method is only applicable for extension schema
     * Deleting a sub attribute of complex attribute is the responsibility of an attribute holder.
     *
     * @param grandParentAttribute
     * @param parentAttribute
     * @param childAttribute
     */
public void deleteSubSubAttribute(String childAttribute, String parentAttribute, String grandParentAttribute) throws CharonException {
    if (attributeList.containsKey(grandParentAttribute)) {
        ComplexAttribute grandParent = (ComplexAttribute) attributeList.get(grandParentAttribute);
        Attribute parent = ((ComplexAttribute) grandParent).getSubAttribute(parentAttribute);
        ((ComplexAttribute) (parent)).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)

Example 18 with ComplexAttribute

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

the class AbstractSCIMObject method setResourceType.

/*
     * set the resourceType of the meta attribute
     *
     * @param resourceType
     */
public void setResourceType(String resourceType) throws BadRequestException, CharonException {
    // create the resourceType attribute as defined in schema.
    SimpleAttribute resourceTypeAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.RESOURCE_TYPE, new SimpleAttribute(SCIMConstants.CommonSchemaConstants.RESOURCE_TYPE, resourceType));
    // check meta complex attribute already exist.
    if (getMetaAttribute() != null) {
        ComplexAttribute metaAttribute = getMetaAttribute();
        // check version attribute already exist
        if (metaAttribute.isSubAttributeExist(resourceTypeAttribute.getName())) {
            String error = "Read only attribute is tried to modify";
            throw new CharonException(error);
        } else {
            metaAttribute.setSubAttribute(resourceTypeAttribute);
        }
    } else {
        // create meta attribute and set the sub attribute.
        createMetaAttribute();
        getMetaAttribute().setSubAttribute(resourceTypeAttribute);
    }
}
Also used : SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) CharonException(org.wso2.charon3.core.exceptions.CharonException)

Example 19 with ComplexAttribute

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

the class Group method setMemberCommon.

/*
     * set member to the group
     * @param userId
     * @param userName
     * @return
     * @throws BadRequestException
     * @throws CharonException
     */
private ComplexAttribute setMemberCommon(String userId, String userName) throws BadRequestException, CharonException {
    ComplexAttribute complexAttribute = new ComplexAttribute();
    complexAttribute.setName(SCIMConstants.GroupSchemaConstants.MEMBERS + "_" + userId + SCIMConstants.DEFAULT);
    SimpleAttribute valueSimpleAttribute = new SimpleAttribute(SCIMConstants.CommonSchemaConstants.VALUE, userId);
    DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.VALUE, valueSimpleAttribute);
    SimpleAttribute displaySimpleAttribute = new SimpleAttribute(SCIMConstants.GroupSchemaConstants.DISPLAY, userName);
    DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.DISPLAY, displaySimpleAttribute);
    complexAttribute.setSubAttribute(valueSimpleAttribute);
    complexAttribute.setSubAttribute(displaySimpleAttribute);
    DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.MEMBERS, complexAttribute);
    return complexAttribute;
}
Also used : SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute)

Example 20 with ComplexAttribute

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

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