use of org.wso2.charon3.core.attributes.ComplexAttribute in project charon by wso2.
the class Group method getMembersWithDisplayName.
/*
* get the members of the group with their display names
* @return
*/
public List<String> getMembersWithDisplayName() {
ArrayList displayNames = new ArrayList();
if (this.isAttributeExist(SCIMConstants.GroupSchemaConstants.MEMBERS)) {
MultiValuedAttribute members = (MultiValuedAttribute) this.attributeList.get(SCIMConstants.GroupSchemaConstants.MEMBERS);
List<Attribute> values = members.getAttributeValues();
if (values != null) {
List<Attribute> subValuesList = members.getAttributeValues();
for (Attribute subValue : subValuesList) {
ComplexAttribute complexAttribute = (ComplexAttribute) subValue;
Map<String, Attribute> subAttributesList = complexAttribute.getSubAttributesList();
if (subAttributesList != null && subAttributesList.containsKey(SCIMConstants.CommonSchemaConstants.DISPLAY)) {
displayNames.add(((SimpleAttribute) (subAttributesList.get(SCIMConstants.CommonSchemaConstants.DISPLAY))).getValue());
}
}
return displayNames;
}
}
return displayNames;
}
use of org.wso2.charon3.core.attributes.ComplexAttribute in project charon by wso2.
the class AbstractSCIMObject method deleteValuesSubAttribute.
/*
* Deleting a sub value's sub attribute of multivalued attribute is the responsibility of an attribute holder.
*
*/
public void deleteValuesSubAttribute(String attribute, String subAttribute, String subSimpleAttribute) {
if (attributeList.containsKey(attribute)) {
MultiValuedAttribute parentAttribute = ((MultiValuedAttribute) attributeList.get(attribute));
List<Attribute> attributeValues = parentAttribute.getAttributeValues();
for (Attribute subValue : attributeValues) {
if (subAttribute.equals(subValue.getName())) {
((ComplexAttribute) subValue).removeSubAttribute(subSimpleAttribute);
break;
}
}
}
}
use of org.wso2.charon3.core.attributes.ComplexAttribute in project charon by wso2.
the class AbstractSCIMObject method setLastModified.
/*
* set the last modified date and time of the resource
*
* @param lastModifiedDate
*/
public void setLastModified(Date lastModifiedDate) throws CharonException, BadRequestException {
// create the lastModified date attribute as defined in schema.
SimpleAttribute lastModifiedAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.LAST_MODIFIED, new SimpleAttribute(SCIMConstants.CommonSchemaConstants.LAST_MODIFIED, lastModifiedDate));
// check meta complex attribute already exist.
if (getMetaAttribute() != null) {
ComplexAttribute metaAttribute = getMetaAttribute();
// check last modified attribute already exist
if (metaAttribute.isSubAttributeExist(lastModifiedAttribute.getName())) {
metaAttribute.removeSubAttribute(lastModifiedAttribute.getName());
metaAttribute.setSubAttribute(lastModifiedAttribute);
} else {
metaAttribute.setSubAttribute(lastModifiedAttribute);
}
} else {
// create meta attribute and set the sub attribute.
createMetaAttribute();
getMetaAttribute().setSubAttribute(lastModifiedAttribute);
}
}
use of org.wso2.charon3.core.attributes.ComplexAttribute in project charon by wso2.
the class AbstractSCIMObject method deleteSubValuesSubAttribute.
public void deleteSubValuesSubAttribute(String grandParentAttribute, String parentAttribute, String subValue, String childAttribute) {
if (attributeList.containsKey(grandParentAttribute)) {
ComplexAttribute grandParent = (ComplexAttribute) attributeList.get(grandParentAttribute);
Map<String, Attribute> subAttributeList = grandParent.getSubAttributesList();
MultiValuedAttribute parent = (MultiValuedAttribute) subAttributeList.get(parentAttribute);
List<Attribute> parentAttributeList = parent.getAttributeValues();
for (Attribute parentsSubValue : parentAttributeList) {
if (subValue.equals(parentsSubValue.getName())) {
((ComplexAttribute) parentsSubValue).removeSubAttribute(childAttribute);
}
}
}
}
use of org.wso2.charon3.core.attributes.ComplexAttribute in project charon by wso2.
the class JSONDecoder method buildComplexValue.
/*
* To build a complex type value of a Multi Valued Attribute. (eg. Email with value,type,primary as sub attributes
*
* @param attributeSchema
* @param jsonObject
* @return ComplexAttribute
*/
private ComplexAttribute buildComplexValue(AttributeSchema attributeSchema, JSONObject jsonObject) throws CharonException, BadRequestException {
ComplexAttribute complexAttribute = new ComplexAttribute(attributeSchema.getName());
Map<String, Attribute> subAttributesMap = new HashMap<String, Attribute>();
List<SCIMAttributeSchema> subAttributeSchemas = ((SCIMAttributeSchema) attributeSchema).getSubAttributeSchemas();
for (SCIMAttributeSchema subAttributeSchema : subAttributeSchemas) {
Object subAttributeValue = jsonObject.opt(subAttributeSchema.getName());
// setting up a name for the complex attribute for the reference purpose
if (subAttributeSchema.getName().equals(SCIMConstants.CommonSchemaConstants.VALUE)) {
// (value,type) pair is considered as a primary key for each entry
if (subAttributeValue != null) {
Object subAttributeValueForType = jsonObject.opt(SCIMConstants.CommonSchemaConstants.TYPE);
if (subAttributeValueForType != null) {
complexAttribute.setName(attributeSchema.getName() + "_" + subAttributeValue + "_" + subAttributeValueForType);
} else {
complexAttribute.setName(attributeSchema.getName() + "_" + subAttributeValue + "_" + SCIMConstants.DEFAULT);
}
} else {
Object subAttributeValueFortype = jsonObject.opt(SCIMConstants.CommonSchemaConstants.TYPE);
if (subAttributeValueFortype != null) {
complexAttribute.setName(attributeSchema.getName() + "_" + SCIMConstants.DEFAULT + "_" + subAttributeValueFortype);
} else {
complexAttribute.setName(attributeSchema.getName() + "_" + SCIMConstants.DEFAULT + "_" + SCIMConstants.DEFAULT);
}
}
}
if (subAttributeValue != null) {
if (subAttributeSchema.getMultiValued()) {
if (subAttributeValue instanceof JSONArray) {
MultiValuedAttribute multiValuedAttribute = buildPrimitiveMultiValuedAttribute(subAttributeSchema, (JSONArray) subAttributeValue);
// let the attribute factory to set the sub attribute of a complex
// attribute to detect schema violations.
multiValuedAttribute = (MultiValuedAttribute) DefaultAttributeFactory.createAttribute(subAttributeSchema, multiValuedAttribute);
subAttributesMap.put(subAttributeSchema.getName(), multiValuedAttribute);
} else {
throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
}
} else {
if (subAttributeValue instanceof String || subAttributeValue instanceof Boolean || subAttributeValue instanceof Integer) {
SimpleAttribute simpleAttribute = buildSimpleAttribute(subAttributeSchema, subAttributeValue);
// let the attribute factory to set the sub attribute of a complex
// attribute to detect schema violations.
simpleAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(subAttributeSchema, simpleAttribute);
subAttributesMap.put(subAttributeSchema.getName(), simpleAttribute);
} else {
throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
}
}
}
}
complexAttribute.setSubAttributesList(subAttributesMap);
return (ComplexAttribute) DefaultAttributeFactory.createAttribute(attributeSchema, complexAttribute);
}
Aggregations