use of org.wso2.charon3.core.attributes.MultiValuedAttribute in project charon by wso2.
the class JSONEncoder method encodeComplexAttribute.
/*
* Encode the complex attribute and include it in root json object to be returned.
*
* @param complexAttribute
* @param rootObject
*/
public void encodeComplexAttribute(ComplexAttribute complexAttribute, JSONObject rootObject) throws JSONException {
JSONObject subObject = new JSONObject();
Map<String, Attribute> attributes = complexAttribute.getSubAttributesList();
for (Attribute attributeValue : attributes.values()) {
// using instanceof instead of polymorphic way, in order to make encoder pluggable.
if (attributeValue instanceof SimpleAttribute) {
// most of the time, this if condition is hit according to current SCIM spec.
encodeSimpleAttribute((SimpleAttribute) attributeValue, subObject);
} else if (attributeValue instanceof MultiValuedAttribute) {
encodeMultiValuedAttribute((MultiValuedAttribute) attributeValue, subObject);
} else if (attributeValue instanceof ComplexAttribute) {
encodeComplexAttribute((ComplexAttribute) attributeValue, subObject);
}
rootObject.put(complexAttribute.getName(), subObject);
}
}
use of org.wso2.charon3.core.attributes.MultiValuedAttribute in project charon by wso2.
the class JSONEncoder method getSCIMObjectAsJSONObject.
/*
* Make JSON object from given SCIM object.
*
* @param scimObject
* @return the resulting string after encoding.
*/
public JSONObject getSCIMObjectAsJSONObject(SCIMObject scimObject) throws CharonException {
// root json object containing the encoded SCIM Object.
JSONObject rootObject = new JSONObject();
try {
// encode schemas
this.encodeArrayOfValues(SCIMConstants.CommonSchemaConstants.SCHEMAS, (scimObject.getSchemaList()).toArray(), rootObject);
// encode attribute list
Map<String, Attribute> attributes = scimObject.getAttributeList();
if (attributes != null && !attributes.isEmpty()) {
for (Attribute attribute : attributes.values()) {
// using instanceof instead of polymorphic way, in order to make encoder pluggable.
if (attribute instanceof SimpleAttribute) {
encodeSimpleAttribute((SimpleAttribute) attribute, rootObject);
} else if (attribute instanceof ComplexAttribute) {
encodeComplexAttribute((ComplexAttribute) attribute, rootObject);
} else if (attribute instanceof MultiValuedAttribute) {
encodeMultiValuedAttribute((MultiValuedAttribute) attribute, rootObject);
}
}
}
} catch (JSONException e) {
String errorMessage = "Error in encoding resource..";
// TODO:log the error
throw new CharonException(errorMessage);
}
return rootObject;
}
use of org.wso2.charon3.core.attributes.MultiValuedAttribute in project charon by wso2.
the class Group method setMember.
/*
* set a member to the group
* @param userId
* @param userName
* @throws BadRequestException
* @throws CharonException
*/
public void setMember(String userId, String userName) throws BadRequestException, CharonException {
if (this.isAttributeExist(SCIMConstants.GroupSchemaConstants.MEMBERS)) {
MultiValuedAttribute members = (MultiValuedAttribute) this.attributeList.get(SCIMConstants.GroupSchemaConstants.MEMBERS);
ComplexAttribute complexAttribute = setMemberCommon(userId, userName);
members.setAttributeValue(complexAttribute);
} else {
MultiValuedAttribute members = new MultiValuedAttribute(SCIMConstants.GroupSchemaConstants.MEMBERS);
DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.MEMBERS, members);
ComplexAttribute complexAttribute = setMemberCommon(userId, userName);
members.setAttributeValue(complexAttribute);
this.setAttribute(members);
}
}
use of org.wso2.charon3.core.attributes.MultiValuedAttribute 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.MultiValuedAttribute 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;
}
}
}
}
Aggregations