Search in sources :

Example 36 with SimpleAttribute

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

the class DefaultAttributeFactory method createAttribute.

/*
     * Returns the defined type of attribute with the user defined value
     * included and necessary attribute characteristics set
     * @param attributeSchema - Attribute schema
     * @param attribute - attribute
     * @return Attribute
     */
public static Attribute createAttribute(AttributeSchema attributeSchema, AbstractAttribute attribute) throws CharonException, BadRequestException {
    attribute.setMutability(attributeSchema.getMutability());
    attribute.setRequired(attributeSchema.getRequired());
    attribute.setReturned(attributeSchema.getReturned());
    attribute.setCaseExact(attributeSchema.getCaseExact());
    attribute.setMultiValued(attributeSchema.getMultiValued());
    attribute.setDescription(attributeSchema.getDescription());
    attribute.setUniqueness(attributeSchema.getUniqueness());
    attribute.setURI(attributeSchema.getURI());
    // Default attribute factory knows about SCIMAttribute schema
    try {
        // set data type of the attribute value, if simple attribute
        if (attribute instanceof SimpleAttribute) {
            return createSimpleAttribute(attributeSchema, (SimpleAttribute) attribute);
        } else {
            attribute.setType(attributeSchema.getType());
        }
        return attribute;
    } catch (CharonException e) {
        String error = "Unknown attribute schema.";
        throw new CharonException(error);
    } catch (BadRequestException e) {
        String error = "Violation in attribute schema. DataType doesn't match that of the value.";
        throw new BadRequestException(error, ResponseCodeConstants.INVALID_VALUE);
    }
}
Also used : BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) CharonException(org.wso2.charon3.core.exceptions.CharonException)

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