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);
}
}
Aggregations