Search in sources :

Example 26 with SimpleAttribute

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

the class AbstractSCIMObject method setLocation.

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

Example 27 with SimpleAttribute

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

the class AbstractSCIMObject method setId.

/*
     * Set a value for the id attribute. If attribute not already created in the resource,
     * create attribute and set the value.
     * Unique identifier for the SCIM Resource as defined by the Service Provider
     * This is read-only. So can only set once.
     *
     * @param id Unique identifier for the SCIM Resource as defined by the Service Provider.
     * @throws CharonException
     * @throws BadRequestException
     */
public void setId(String id) throws CharonException, BadRequestException {
    if (isAttributeExist(SCIMConstants.CommonSchemaConstants.ID)) {
        String error = "Read only attribute is trying to be modified";
        throw new CharonException(error);
    } else {
        SimpleAttribute idAttribute = new SimpleAttribute(SCIMConstants.CommonSchemaConstants.ID, id);
        idAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.ID, idAttribute);
        this.setAttribute(idAttribute);
    }
}
Also used : SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) CharonException(org.wso2.charon3.core.exceptions.CharonException)

Example 28 with SimpleAttribute

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

the class Group method setDisplayName.

/*
     * set the display name of the group
     * @param displayName
     * @throws CharonException
     * @throws BadRequestException
     */
public void setDisplayName(String displayName) throws CharonException, BadRequestException {
    if (this.isAttributeExist(SCIMConstants.GroupSchemaConstants.DISPLAY_NAME)) {
        ((SimpleAttribute) this.attributeList.get(SCIMConstants.GroupSchemaConstants.DISPLAY_NAME)).updateValue(displayName);
    } else {
        SimpleAttribute displayAttribute = new SimpleAttribute(SCIMConstants.GroupSchemaConstants.DISPLAY_NAME, displayName);
        displayAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.DISPLAY_NAME, displayAttribute);
        this.attributeList.put(SCIMConstants.GroupSchemaConstants.DISPLAY_NAME, displayAttribute);
    }
}
Also used : SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute)

Example 29 with SimpleAttribute

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

the class Group method getMembers.

/*
     * get the members of the group
     * @return
     */
public List<Object> getMembers() {
    List<Object> memberList = new ArrayList<>();
    if (this.isAttributeExist(SCIMConstants.GroupSchemaConstants.MEMBERS)) {
        MultiValuedAttribute members = (MultiValuedAttribute) this.attributeList.get(SCIMConstants.GroupSchemaConstants.MEMBERS);
        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.VALUE)) {
                memberList.add(((SimpleAttribute) (subAttributesList.get(SCIMConstants.CommonSchemaConstants.VALUE))).getValue());
            }
        }
        return memberList;
    } else {
        return null;
    }
}
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 30 with SimpleAttribute

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

the class ListedResource method setItemsPerPage.

/*
     * paginated listed resource items per page settings
     * @param itemsPerPage
     */
public void setItemsPerPage(int itemsPerPage) {
    if (!isAttributeExist(SCIMConstants.ListedResourceSchemaConstants.ITEMS_PER_PAGE)) {
        SimpleAttribute totalResultsAttribute = new SimpleAttribute(SCIMConstants.ListedResourceSchemaConstants.ITEMS_PER_PAGE, itemsPerPage);
        // No need to let the Default attribute factory to handle the attribute, as this is
        // not officially defined as SCIM attribute, hence have no characteristics defined
        // TODO: may be we can let the default attribute factory to handle it?
        attributeList.put(SCIMConstants.ListedResourceSchemaConstants.ITEMS_PER_PAGE, totalResultsAttribute);
    } else {
        ((SimpleAttribute) attributeList.get(SCIMConstants.ListedResourceSchemaConstants.ITEMS_PER_PAGE)).setValue(itemsPerPage);
    }
}
Also used : SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute)

Aggregations

SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)34 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)26 Attribute (org.wso2.charon3.core.attributes.Attribute)20 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)20 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)15 JSONObject (org.json.JSONObject)13 JSONArray (org.json.JSONArray)9 CharonException (org.wso2.charon3.core.exceptions.CharonException)9 AbstractSCIMObject (org.wso2.charon3.core.objects.AbstractSCIMObject)8 AttributeSchema (org.wso2.charon3.core.schema.AttributeSchema)8 JSONException (org.json.JSONException)6 Map (java.util.Map)5 SCIMObject (org.wso2.charon3.core.objects.SCIMObject)5 JSONTokener (org.json.JSONTokener)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 SCIMAttributeSchema (org.wso2.charon3.core.schema.SCIMAttributeSchema)3 Iterator (java.util.Iterator)2 AbstractAttribute (org.wso2.charon3.core.attributes.AbstractAttribute)2