use of org.wso2.charon3.core.attributes.SimpleAttribute 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.SimpleAttribute in project charon by wso2.
the class AbstractSCIMObject method setResourceType.
/*
* set the resourceType of the meta attribute
*
* @param resourceType
*/
public void setResourceType(String resourceType) throws BadRequestException, CharonException {
// create the resourceType attribute as defined in schema.
SimpleAttribute resourceTypeAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.RESOURCE_TYPE, new SimpleAttribute(SCIMConstants.CommonSchemaConstants.RESOURCE_TYPE, resourceType));
// check meta complex attribute already exist.
if (getMetaAttribute() != null) {
ComplexAttribute metaAttribute = getMetaAttribute();
// check version attribute already exist
if (metaAttribute.isSubAttributeExist(resourceTypeAttribute.getName())) {
String error = "Read only attribute is tried to modify";
throw new CharonException(error);
} else {
metaAttribute.setSubAttribute(resourceTypeAttribute);
}
} else {
// create meta attribute and set the sub attribute.
createMetaAttribute();
getMetaAttribute().setSubAttribute(resourceTypeAttribute);
}
}
use of org.wso2.charon3.core.attributes.SimpleAttribute in project charon by wso2.
the class Group method setMemberCommon.
/*
* set member to the group
* @param userId
* @param userName
* @return
* @throws BadRequestException
* @throws CharonException
*/
private ComplexAttribute setMemberCommon(String userId, String userName) throws BadRequestException, CharonException {
ComplexAttribute complexAttribute = new ComplexAttribute();
complexAttribute.setName(SCIMConstants.GroupSchemaConstants.MEMBERS + "_" + userId + SCIMConstants.DEFAULT);
SimpleAttribute valueSimpleAttribute = new SimpleAttribute(SCIMConstants.CommonSchemaConstants.VALUE, userId);
DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.VALUE, valueSimpleAttribute);
SimpleAttribute displaySimpleAttribute = new SimpleAttribute(SCIMConstants.GroupSchemaConstants.DISPLAY, userName);
DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.DISPLAY, displaySimpleAttribute);
complexAttribute.setSubAttribute(valueSimpleAttribute);
complexAttribute.setSubAttribute(displaySimpleAttribute);
DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.MEMBERS, complexAttribute);
return complexAttribute;
}
use of org.wso2.charon3.core.attributes.SimpleAttribute 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.SimpleAttribute in project charon by wso2.
the class ListedResource method setStartIndex.
/*
* paginated listed resource start index settings
* @param startIndex
*/
public void setStartIndex(int startIndex) {
if (!isAttributeExist(SCIMConstants.ListedResourceSchemaConstants.START_INDEX)) {
SimpleAttribute totalResultsAttribute = new SimpleAttribute(SCIMConstants.ListedResourceSchemaConstants.START_INDEX, startIndex);
// No need to let the Default attribute factory to handle the attribute, as this is
// not officially defined as SCIM attribute, hence have no charactersitics defined
// TODO: may be we can let the default attribute factory to handle it?
attributeList.put(SCIMConstants.ListedResourceSchemaConstants.START_INDEX, totalResultsAttribute);
} else {
((SimpleAttribute) attributeList.get(SCIMConstants.ListedResourceSchemaConstants.START_INDEX)).setValue(startIndex);
}
}
Aggregations