Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
AnuradhaSK committed Oct 18, 2023
1 parent c54cb8e commit ca64654
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.wso2.charon3.core.attributes.SimpleAttribute;
import org.wso2.charon3.core.exceptions.BadRequestException;
import org.wso2.charon3.core.exceptions.CharonException;
import org.wso2.charon3.core.schema.SCIMAttributeSchema;
import org.wso2.charon3.core.schema.SCIMConstants;
import org.wso2.charon3.core.schema.SCIMResourceSchemaManager;
import org.wso2.charon3.core.schema.SCIMResourceTypeSchema;
Expand All @@ -47,6 +48,7 @@ public class Group extends AbstractSCIMObject {
private static final long serialVersionUID = 6106269076155338045L;
/**
* get the display name of the group
*
* @return
* @throws CharonException
*/
Expand All @@ -61,6 +63,7 @@ public String getDisplayName() {

/**
* set the display name of the group
*
* @param displayName
* @throws CharonException
* @throws BadRequestException
Expand All @@ -87,6 +90,7 @@ public void replaceDisplayName(String displayname) {

/**
* get the members of the group
*
* @return
*/
public List<Object> getMembers() {
Expand All @@ -110,6 +114,7 @@ public List<Object> getMembers() {

/**
* get the members of the group with their display names
*
* @return
*/
public List<String> getMembersWithDisplayName() {
Expand Down Expand Up @@ -171,6 +176,7 @@ public void setMember(String value, String display, String ref, String type)

/**
* set member to the group
*
* @param userId
* @param userName
* @return
Expand Down Expand Up @@ -423,11 +429,6 @@ private void setRole(ComplexAttribute groupPropertiesAttribute) throws CharonExc
public void setRoleV2(RoleV2 role) throws CharonException, BadRequestException {

SimpleAttribute valueSimpleAttribute = null;
SimpleAttribute displaySimpleAttribute;
SimpleAttribute referenceSimpleAttribute;
SimpleAttribute audienceValueSimpleAttribute;
SimpleAttribute audienceDisplaySimpleAttribute;
SimpleAttribute audienceTypeSimpleAttribute;
String reference = role.getLocation();
String value = role.getId();
String display = role.getDisplayName();
Expand All @@ -437,52 +438,34 @@ public void setRoleV2(RoleV2 role) throws CharonException, BadRequestException {
ComplexAttribute complexAttribute = new ComplexAttribute();

if (StringUtils.isNotBlank(value)) {
valueSimpleAttribute = new SimpleAttribute(SCIMConstants.CommonSchemaConstants.VALUE, value);
valueSimpleAttribute = (SimpleAttribute) DefaultAttributeFactory
.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.ROLES_VALUE, valueSimpleAttribute);
valueSimpleAttribute = getSimpleAttribute(SCIMConstants.CommonSchemaConstants.VALUE, value,
SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.ROLES_VALUE);
complexAttribute.setSubAttribute(valueSimpleAttribute);
}

if (StringUtils.isNotBlank(reference)) {
referenceSimpleAttribute = new SimpleAttribute(SCIMConstants.CommonSchemaConstants.REF, reference);
DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.ROLES_REF,
referenceSimpleAttribute);
complexAttribute.setSubAttribute(referenceSimpleAttribute);
complexAttribute.setSubAttribute(getSimpleAttribute(SCIMConstants.CommonSchemaConstants.REF, reference,
SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.ROLES_REF));
}

if (StringUtils.isNotBlank(display)) {
displaySimpleAttribute = new SimpleAttribute(SCIMConstants.CommonSchemaConstants.DISPLAY, display);
displaySimpleAttribute = (SimpleAttribute) DefaultAttributeFactory
.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.ROLES_DISPLAY,
displaySimpleAttribute);
complexAttribute.setSubAttribute(displaySimpleAttribute);
complexAttribute.setSubAttribute(getSimpleAttribute(SCIMConstants.CommonSchemaConstants.DISPLAY, display,
SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.ROLES_DISPLAY));
}

if (StringUtils.isNotBlank(audienceValue)) {
audienceValueSimpleAttribute =
new SimpleAttribute(SCIMConstants.CommonSchemaConstants.AUDIENCE_VALUE, audienceValue);
audienceValueSimpleAttribute = (SimpleAttribute) DefaultAttributeFactory
.createAttribute(SCIMSchemaDefinitions.SCIMUserSchemaDefinition.ROLES_AUDIENCE_VALUE,
audienceValueSimpleAttribute);
complexAttribute.setSubAttribute(audienceValueSimpleAttribute);
complexAttribute.setSubAttribute(getSimpleAttribute(SCIMConstants.CommonSchemaConstants.AUDIENCE_VALUE,
audienceValue, SCIMSchemaDefinitions.SCIMUserSchemaDefinition.ROLES_AUDIENCE_VALUE));
}

if (StringUtils.isNotBlank(audienceDisplay)) {
audienceDisplaySimpleAttribute =
new SimpleAttribute(SCIMConstants.CommonSchemaConstants.AUDIENCE_DISPLAY, audienceDisplay);
audienceDisplaySimpleAttribute = (SimpleAttribute) DefaultAttributeFactory
.createAttribute(SCIMSchemaDefinitions.SCIMUserSchemaDefinition.ROLES_AUDIENCE_DISPLAY,
audienceDisplaySimpleAttribute);
complexAttribute.setSubAttribute(audienceDisplaySimpleAttribute);
complexAttribute.setSubAttribute(getSimpleAttribute(SCIMConstants.CommonSchemaConstants.AUDIENCE_DISPLAY,
audienceDisplay, SCIMSchemaDefinitions.SCIMUserSchemaDefinition.ROLES_AUDIENCE_DISPLAY));
}

if (StringUtils.isNotBlank(audienceType)) {
audienceTypeSimpleAttribute =
new SimpleAttribute(SCIMConstants.CommonSchemaConstants.AUDIENCE_TYPE, audienceType);
audienceTypeSimpleAttribute = (SimpleAttribute) DefaultAttributeFactory
.createAttribute(SCIMSchemaDefinitions.SCIMUserSchemaDefinition.ROLES_AUDIENCE_TYPE,
audienceTypeSimpleAttribute);
complexAttribute.setSubAttribute(audienceTypeSimpleAttribute);
complexAttribute.setSubAttribute(getSimpleAttribute(SCIMConstants.CommonSchemaConstants.AUDIENCE_TYPE,
audienceType, SCIMSchemaDefinitions.SCIMUserSchemaDefinition.ROLES_AUDIENCE_TYPE));
}

if (!complexAttribute.getSubAttributesList().isEmpty()) {
Expand All @@ -499,6 +482,14 @@ public void setRoleV2(RoleV2 role) throws CharonException, BadRequestException {
}
}

private SimpleAttribute getSimpleAttribute(String attributeName, String attributeValue,
SCIMAttributeSchema attributeSchema)
throws CharonException, BadRequestException {

return (SimpleAttribute) DefaultAttributeFactory.createAttribute(attributeSchema,
new SimpleAttribute(attributeName, attributeValue));
}

private void setRoleV2(ComplexAttribute groupPropertiesAttribute) throws CharonException, BadRequestException {

MultiValuedAttribute groupsAttribute;
Expand Down
Loading

0 comments on commit ca64654

Please sign in to comment.