use of org.kuali.kfs.kim.api.identity.IdentityService in project cu-kfs by CU-CommunityApps.
the class PrincipalNameHandlingLookupableHelperService method buildCriteriaWithMatchableConvertedPrincipalValues.
default Optional<Map<String, String>> buildCriteriaWithMatchableConvertedPrincipalValues(Map<String, String> fieldValues) {
Map<String, String> newFieldValues = new HashMap<>(fieldValues);
Map<String, String> fieldMappings = getMappingsFromPrincipalNameFieldsToPrincipalIdFields();
IdentityService identityService = getIdentityService();
boolean allPrincipalNamesHaveMatches = true;
for (Map.Entry<String, String> fieldMapping : fieldMappings.entrySet()) {
String principalNameField = fieldMapping.getKey();
String principalIdField = fieldMapping.getValue();
if (fieldValues.containsKey(principalNameField)) {
String principalName = newFieldValues.remove(principalNameField);
if (StringUtils.isNotBlank(principalName)) {
Principal principal = identityService.getPrincipalByPrincipalName(principalName);
if (ObjectUtils.isNotNull(principal)) {
newFieldValues.put(principalIdField, principal.getPrincipalId());
} else {
allPrincipalNamesHaveMatches = false;
}
}
}
}
return allPrincipalNamesHaveMatches ? Optional.of(newFieldValues) : Optional.empty();
}
Aggregations