Search in sources :

Example 11 with AttributeSchema

use of org.wso2.charon3.core.schema.AttributeSchema in project charon by wso2.

the class SCIMUserSchemaExtensionBuilder method buildSimpleAttributeSchema.

/*
     * Builds simple attribute schema
     *
     * @param config
     */
private void buildSimpleAttributeSchema(ExtensionAttributeSchemaConfig config) {
    ArrayList<SCIMAttributeSchema> subAttributeList = new ArrayList<SCIMAttributeSchema>();
    if (!attributeSchemas.containsKey(config.getName())) {
        SCIMAttributeSchema attributeSchema = createSCIMAttributeSchema(config, subAttributeList);
        attributeSchemas.put(config.getName(), attributeSchema);
    }
}
Also used : SCIMAttributeSchema(org.wso2.charon3.core.schema.SCIMAttributeSchema) ArrayList(java.util.ArrayList)

Example 12 with AttributeSchema

use of org.wso2.charon3.core.schema.AttributeSchema in project charon by wso2.

the class JSONDecoder method buildSimpleAttribute.

/*
     * Return a simple attribute with the user defined value included and necessary attribute characteristics set
     *
     * @param attributeSchema - Attribute schema
     * @param attributeValue  - value for the attribute
     * @return SimpleAttribute
     */
public SimpleAttribute buildSimpleAttribute(AttributeSchema attributeSchema, Object attributeValue) throws CharonException, BadRequestException {
    Object attributeValueObject = AttributeUtil.getAttributeValueFromString(attributeValue, attributeSchema.getType());
    SimpleAttribute simpleAttribute = new SimpleAttribute(attributeSchema.getName(), attributeValueObject);
    return (SimpleAttribute) DefaultAttributeFactory.createAttribute(attributeSchema, simpleAttribute);
}
Also used : SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) AbstractSCIMObject(org.wso2.charon3.core.objects.AbstractSCIMObject) JSONObject(org.json.JSONObject) SCIMObject(org.wso2.charon3.core.objects.SCIMObject)

Example 13 with AttributeSchema

use of org.wso2.charon3.core.schema.AttributeSchema in project charon by wso2.

the class JSONDecoder method buildComplexMultiValuedAttribute.

/*
     * Return complex type multi valued attribute with the user defined
     * value included and necessary attribute characteristics set
     * @param attributeSchema - Attribute schema
     * @param attributeValues - values for the attribute
     * @return MultiValuedAttribute
     */
public MultiValuedAttribute buildComplexMultiValuedAttribute(AttributeSchema attributeSchema, JSONArray attributeValues) throws CharonException, BadRequestException {
    try {
        MultiValuedAttribute multiValuedAttribute = new MultiValuedAttribute(attributeSchema.getName());
        List<Attribute> complexAttributeValues = new ArrayList<Attribute>();
        // iterate through JSONArray and create the list of string values.
        for (int i = 0; i < attributeValues.length(); i++) {
            Object attributeValue = attributeValues.get(i);
            if (attributeValue instanceof JSONObject) {
                JSONObject complexAttributeValue = (JSONObject) attributeValue;
                complexAttributeValues.add(buildComplexValue(attributeSchema, complexAttributeValue));
            } else {
                String error = "Unknown JSON representation for the MultiValued attribute " + attributeSchema.getName() + " which has data type as " + attributeSchema.getType();
                throw new BadRequestException(error, ResponseCodeConstants.INVALID_SYNTAX);
            }
        }
        multiValuedAttribute.setAttributeValues(complexAttributeValues);
        return (MultiValuedAttribute) DefaultAttributeFactory.createAttribute(attributeSchema, multiValuedAttribute);
    } catch (JSONException e) {
        String error = "Error in accessing JSON value of multivalued attribute";
        throw new CharonException(error, e);
    }
}
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) ArrayList(java.util.ArrayList) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) JSONException(org.json.JSONException) AbstractSCIMObject(org.wso2.charon3.core.objects.AbstractSCIMObject) JSONObject(org.json.JSONObject) SCIMObject(org.wso2.charon3.core.objects.SCIMObject) CharonException(org.wso2.charon3.core.exceptions.CharonException) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute)

Example 14 with AttributeSchema

use of org.wso2.charon3.core.schema.AttributeSchema in project charon by wso2.

the class JSONDecoder method buildPrimitiveMultiValuedAttribute.

/*
     * Return a primitive type multi valued attribute with the user defined value included and necessary
     * attribute characteristics set
     *
     * @param attributeSchema - Attribute schema
     * @param attributeValues - values for the attribute
     * @return MultiValuedAttribute
     */
public MultiValuedAttribute buildPrimitiveMultiValuedAttribute(AttributeSchema attributeSchema, JSONArray attributeValues) throws CharonException, BadRequestException {
    try {
        MultiValuedAttribute multiValuedAttribute = new MultiValuedAttribute(attributeSchema.getName());
        List<Object> primitiveValues = new ArrayList<Object>();
        // iterate through JSONArray and create the list of string values.
        for (int i = 0; i < attributeValues.length(); i++) {
            Object attributeValue = attributeValues.get(i);
            if (attributeValue instanceof String || attributeValue instanceof Boolean || attributeValue instanceof Integer || attributeValue == null) {
                // If an attribute is passed without a value, no need to save it.
                if (attributeValue == null) {
                    continue;
                }
                primitiveValues.add(attributeValue);
            } else {
                String error = "Unknown JSON representation for the MultiValued attribute " + attributeSchema.getName() + " which has data type as " + attributeSchema.getType();
                throw new BadRequestException(error, ResponseCodeConstants.INVALID_SYNTAX);
            }
        }
        multiValuedAttribute.setAttributePrimitiveValues(primitiveValues);
        return (MultiValuedAttribute) DefaultAttributeFactory.createAttribute(attributeSchema, multiValuedAttribute);
    } catch (JSONException e) {
        String error = "Error in accessing JSON value of multivalued attribute";
        throw new CharonException(error, e);
    }
}
Also used : ArrayList(java.util.ArrayList) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) JSONException(org.json.JSONException) AbstractSCIMObject(org.wso2.charon3.core.objects.AbstractSCIMObject) JSONObject(org.json.JSONObject) SCIMObject(org.wso2.charon3.core.objects.SCIMObject) CharonException(org.wso2.charon3.core.exceptions.CharonException) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute)

Example 15 with AttributeSchema

use of org.wso2.charon3.core.schema.AttributeSchema in project charon by wso2.

the class ResourceManagerUtil method removeAttributesFromList.

/*
     * this is to remove given attribute from the given list.
     *
     * @param attributeSchemaList
     * @param attributeName
     * @throws CharonException
     */
private static void removeAttributesFromList(List<AttributeSchema> attributeSchemaList, String attributeName) throws CharonException {
    List<AttributeSchema> tempList = (List<AttributeSchema>) CopyUtil.deepCopy(attributeSchemaList);
    int count = 0;
    for (AttributeSchema attributeSchema : tempList) {
        if (attributeSchema.getName().equals(attributeName)) {
            attributeSchemaList.remove(count);
        }
        count++;
    }
}
Also used : SCIMAttributeSchema(org.wso2.charon3.core.schema.SCIMAttributeSchema) AttributeSchema(org.wso2.charon3.core.schema.AttributeSchema) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)19 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)18 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)18 Attribute (org.wso2.charon3.core.attributes.Attribute)17 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)17 AttributeSchema (org.wso2.charon3.core.schema.AttributeSchema)11 ArrayList (java.util.ArrayList)10 JSONObject (org.json.JSONObject)10 JSONArray (org.json.JSONArray)8 AbstractAttribute (org.wso2.charon3.core.attributes.AbstractAttribute)8 AbstractSCIMObject (org.wso2.charon3.core.objects.AbstractSCIMObject)8 List (java.util.List)7 JSONException (org.json.JSONException)7 SCIMAttributeSchema (org.wso2.charon3.core.schema.SCIMAttributeSchema)7 SCIMObject (org.wso2.charon3.core.objects.SCIMObject)6 CharonException (org.wso2.charon3.core.exceptions.CharonException)5 JSONTokener (org.json.JSONTokener)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 SCIMDefinitions (org.wso2.charon3.core.schema.SCIMDefinitions)2