use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project charon by wso2.
the class AbstractSCIMObject method setLocation.
/*
* set the location of the meta attribute
*
* @param location
*/
public void setLocation(String location) throws CharonException, BadRequestException {
// create the location attribute as defined in schema.
SimpleAttribute locationAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.LOCATION, new SimpleAttribute(SCIMConstants.CommonSchemaConstants.LOCATION, location));
// check meta complex attribute already exist.
if (getMetaAttribute() != null) {
ComplexAttribute metaAttribute = getMetaAttribute();
// check version attribute already exist
if (metaAttribute.isSubAttributeExist(locationAttribute.getName())) {
String error = "Read only attribute is tried to modify";
throw new CharonException(error);
} else {
metaAttribute.setSubAttribute(locationAttribute);
}
} else {
// create meta attribute and set the sub attribute.
createMetaAttribute();
getMetaAttribute().setSubAttribute(locationAttribute);
}
}
use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project charon by wso2.
the class AbstractSCIMObject method setId.
/*
* Set a value for the id attribute. If attribute not already created in the resource,
* create attribute and set the value.
* Unique identifier for the SCIM Resource as defined by the Service Provider
* This is read-only. So can only set once.
*
* @param id Unique identifier for the SCIM Resource as defined by the Service Provider.
* @throws CharonException
* @throws BadRequestException
*/
public void setId(String id) throws CharonException, BadRequestException {
if (isAttributeExist(SCIMConstants.CommonSchemaConstants.ID)) {
String error = "Read only attribute is trying to be modified";
throw new CharonException(error);
} else {
SimpleAttribute idAttribute = new SimpleAttribute(SCIMConstants.CommonSchemaConstants.ID, id);
idAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.ID, idAttribute);
this.setAttribute(idAttribute);
}
}
use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project charon by wso2.
the class Group method setDisplayName.
/*
* set the display name of the group
* @param displayName
* @throws CharonException
* @throws BadRequestException
*/
public void setDisplayName(String displayName) throws CharonException, BadRequestException {
if (this.isAttributeExist(SCIMConstants.GroupSchemaConstants.DISPLAY_NAME)) {
((SimpleAttribute) this.attributeList.get(SCIMConstants.GroupSchemaConstants.DISPLAY_NAME)).updateValue(displayName);
} else {
SimpleAttribute displayAttribute = new SimpleAttribute(SCIMConstants.GroupSchemaConstants.DISPLAY_NAME, displayName);
displayAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.DISPLAY_NAME, displayAttribute);
this.attributeList.put(SCIMConstants.GroupSchemaConstants.DISPLAY_NAME, displayAttribute);
}
}
use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project charon by wso2.
the class User method setSimpleAttribute.
/*
* set simple attribute in the scim object
* @param attributeName
* @param attributeSchema
* @param value
* @throws CharonException
* @throws BadRequestException
*/
private void setSimpleAttribute(String attributeName, AttributeSchema attributeSchema, Object value) throws CharonException, BadRequestException {
if (this.isAttributeExist(attributeName)) {
((SimpleAttribute) this.attributeList.get(attributeName)).updateValue(value);
} else {
SimpleAttribute simpleAttribute = new SimpleAttribute(attributeName, value);
simpleAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(attributeSchema, simpleAttribute);
this.attributeList.put(attributeName, simpleAttribute);
}
}
use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project charon by wso2.
the class User method setGroup.
/*
* set the associated groups of the user
* @param type
* @param value
* @param display
* @throws CharonException
* @throws BadRequestException
*/
public void setGroup(String type, String value, String display) throws CharonException, BadRequestException {
SimpleAttribute typeSimpleAttribute = null;
SimpleAttribute valueSimpleAttribute = null;
SimpleAttribute displaySimpleAttribute = null;
ComplexAttribute complexAttribute = new ComplexAttribute();
if (type != null) {
typeSimpleAttribute = new SimpleAttribute(SCIMConstants.CommonSchemaConstants.TYPE, type);
typeSimpleAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMUserSchemaDefinition.GROUP_TYPE, typeSimpleAttribute);
complexAttribute.setSubAttribute(typeSimpleAttribute);
}
if (value != null) {
valueSimpleAttribute = new SimpleAttribute(SCIMConstants.CommonSchemaConstants.VALUE, value);
valueSimpleAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMUserSchemaDefinition.GROUP_VALUE, valueSimpleAttribute);
complexAttribute.setSubAttribute(valueSimpleAttribute);
}
if (display != null) {
displaySimpleAttribute = new SimpleAttribute(SCIMConstants.CommonSchemaConstants.DISPLAY, display);
displaySimpleAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMUserSchemaDefinition.GROUP_DISPLAY, displaySimpleAttribute);
complexAttribute.setSubAttribute(displaySimpleAttribute);
}
if (complexAttribute.getSubAttributesList().size() != 0) {
Object typeVal = SCIMConstants.DEFAULT;
Object valueVal = SCIMConstants.DEFAULT;
if (typeSimpleAttribute != null && typeSimpleAttribute.getValue() != null) {
typeVal = typeSimpleAttribute.getValue();
}
if (valueSimpleAttribute != null && valueSimpleAttribute.getValue() != null) {
valueVal = valueSimpleAttribute.getValue();
}
String complexAttributeName = SCIMConstants.UserSchemaConstants.GROUPS + "_" + valueVal + "_" + typeVal;
complexAttribute.setName(complexAttributeName);
DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMUserSchemaDefinition.GROUPS, complexAttribute);
setGroup(complexAttribute);
}
}
Aggregations