Search in sources :

Example 1 with IdentityService

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();
}
Also used : IdentityService(org.kuali.kfs.kim.api.identity.IdentityService) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) Principal(org.kuali.kfs.kim.impl.identity.principal.Principal)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 IdentityService (org.kuali.kfs.kim.api.identity.IdentityService)1 Principal (org.kuali.kfs.kim.impl.identity.principal.Principal)1