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