Skip to content

Commit

Permalink
feat(jans-config-api): user management enhancement to chk mandatory f…
Browse files Browse the repository at this point in the history
…eilds
  • Loading branch information
pujavs committed Apr 13, 2022
1 parent 3ac4b19 commit 0bc2282
Showing 1 changed file with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,31 +138,33 @@ public User getUserBasedOnInum(String inum) {
private User updateCustomAttributes(User user, List<CustomObjectAttribute> customAttributes) {
logger.debug("Custom Attributes to update for - user:{}, customAttributes:{} ", user, customAttributes);

if (customAttributes != null && !customAttributes.isEmpty()) {
for (CustomObjectAttribute attribute : customAttributes) {
CustomObjectAttribute existingAttribute = getCustomAttribute(user, attribute.getName());
logger.debug("Existing CustomAttributes with existingAttribute:{} ", existingAttribute);

// add
if (existingAttribute == null) {
boolean result = addUserAttribute(user, attribute.getName(), attribute.getValues(),
attribute.isMultiValued());
logger.debug("Result of adding CustomAttributes attribute:{} , result:{} ", attribute, result);
}
// remove attribute
else if (attribute.getValue() == null || attribute.getValues() == null) {

user.removeAttribute(attribute.getName());
}
// replace attribute
else {
existingAttribute.setMultiValued(attribute.isMultiValued());
existingAttribute.setValues(attribute.getValues());
}
// Final attribute
logger.debug("Finally user CustomAttributes user.getCustomAttributes:{} ", user.getCustomAttributes());
if (customAttributes == null || customAttributes.isEmpty()) {
return user;
}

for (CustomObjectAttribute attribute : customAttributes) {
CustomObjectAttribute existingAttribute = getCustomAttribute(user, attribute.getName());
logger.debug("Existing CustomAttributes with existingAttribute:{} ", existingAttribute);

// add
if (existingAttribute == null) {
boolean result = addUserAttribute(user, attribute.getName(), attribute.getValues(),
attribute.isMultiValued());
logger.debug("Result of adding CustomAttributes attribute:{} , result:{} ", attribute, result);
}
// remove attribute
else if (attribute.getValue() == null || attribute.getValues() == null) {

user.removeAttribute(attribute.getName());
}
// replace attribute
else {
existingAttribute.setMultiValued(attribute.isMultiValued());
existingAttribute.setValues(attribute.getValues());
}
// Final attribute
logger.debug("Finally user CustomAttributes user.getCustomAttributes:{} ", user.getCustomAttributes());

}

return user;
Expand All @@ -171,6 +173,11 @@ else if (attribute.getValue() == null || attribute.getValues() == null) {
public List<User> excludeAttributes(List<User> users, String commaSeparatedString)
throws IllegalAccessException, InvocationTargetException {
logger.debug("Attributes:{} to be excluded from users:{} ", commaSeparatedString, users);

if (users == null || users.isEmpty() || StringUtils.isEmpty(commaSeparatedString)) {
return users;
}

for (User user : users) {
excludeAttributes(user, commaSeparatedString);
}
Expand All @@ -182,9 +189,11 @@ public List<User> excludeAttributes(List<User> users, String commaSeparatedStrin
public User excludeAttributes(User user, String commaSeparatedString)
throws IllegalAccessException, InvocationTargetException {
logger.debug("Attributes:{} to be excluded from user:{} ", commaSeparatedString, user);

if (user == null || StringUtils.isEmpty(commaSeparatedString)) {
return user;
}

List<String> excludedAttributes = Arrays.asList(commaSeparatedString.split(","));
logger.debug("Attributes List:{} to be excluded ", excludedAttributes);

Expand Down Expand Up @@ -251,7 +260,9 @@ public String checkMandatoryFields(User user)
}
}
logger.debug("Checking mandatory missingAttributes:{} ", missingAttributes);
missingAttributes.replace(missingAttributes.lastIndexOf(","), missingAttributes.length(), "");
if (missingAttributes != null && missingAttributes.length() > 0) {
missingAttributes.replace(missingAttributes.lastIndexOf(","), missingAttributes.length(), "");
}

logger.debug("Returning missingAttributes:{} ", missingAttributes);
return missingAttributes.toString();
Expand Down

0 comments on commit 0bc2282

Please sign in to comment.