Search in sources :

Example 91 with BadRequestException

use of org.wso2.charon3.core.exceptions.BadRequestException 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

BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)63 CharonException (org.wso2.charon3.core.exceptions.CharonException)31 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)30 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)27 HashMap (java.util.HashMap)23 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)23 Attribute (org.wso2.charon3.core.attributes.Attribute)20 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)19 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)19 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)19 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)18 JSONException (org.json.JSONException)17 JSONObject (org.json.JSONObject)17 AbstractSCIMObject (org.wso2.charon3.core.objects.AbstractSCIMObject)16 JSONEncoder (org.wso2.charon3.core.encoder.JSONEncoder)15 JSONDecoder (org.wso2.charon3.core.encoder.JSONDecoder)14 NotImplementedException (org.wso2.charon3.core.exceptions.NotImplementedException)14 User (org.wso2.charon3.core.objects.User)12 JSONArray (org.json.JSONArray)11 ArrayList (java.util.ArrayList)9