Skip to content
Snippets Groups Projects
Commit da7eac44 authored by Lukas Malte Monnerjahn's avatar Lukas Malte Monnerjahn
Browse files

OZG-6897 cleanup

parent cc4bd47c
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,7 @@ import java.util.stream.Stream;
import jakarta.inject.Inject;
import org.apache.commons.lang3.StringUtils;
import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.admin.client.resource.UserResource;
import org.keycloak.representations.idm.ClientMappingsRepresentation;
......@@ -83,8 +84,7 @@ public abstract class UserResourceMapper {
getOrganisationsEinheitIdsFromGroups(groups),
getOrganisationsEinheitIdsFromUser(userRes)
)
.filter(Objects::nonNull)
.filter(oeId -> !oeId.isBlank())
.filter(StringUtils::isNotBlank)
.collect(Collectors.toSet());
}
......@@ -93,12 +93,12 @@ public abstract class UserResourceMapper {
.map(this::mapGroup)
.filter(Objects::nonNull)
.map(attributeMap -> attributeMap.get(properties.organisationsEinheitIdKey()))
.filter(Objects::nonNull)
.flatMap(Collection::stream);
}
private Stream<String> getOrganisationsEinheitIdsFromUser(UserResource userRes) {
return Optional.ofNullable(getUserAttributes(userRes).get(properties.organisationsEinheitIdKey()))
return getUserAttributes(userRes)
.map(attributes -> attributes.get(properties.organisationsEinheitIdKey()))
.orElse(Collections.emptyList())
.stream();
}
......@@ -124,7 +124,7 @@ public abstract class UserResourceMapper {
return Optional.ofNullable(userRepresentation.getAttributes())
.map(attributes -> attributes.get(properties.ldapIdKey()))
.map(id -> id.get(0))
.map(List::getFirst)
.orElseGet(userRepresentation::getId);
}
......@@ -159,7 +159,7 @@ public abstract class UserResourceMapper {
.filter(Objects::nonNull).toArray(String[]::new));
}
private Map<String, List<String>> getUserAttributes(UserResource userResource) {
return Optional.ofNullable(userResource.toRepresentation().getAttributes()).orElse(Map.of());
private Optional<Map<String, List<String>>> getUserAttributes(UserResource userResource) {
return Optional.ofNullable(userResource.toRepresentation().getAttributes());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment