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

OZG-6897 map organisations einheit ids from user attributes

also allow to map multiple oeIds from groups
parent 0d1a6be8
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,7 @@
*/
package de.ozgcloud.user;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
......@@ -78,22 +79,29 @@ public abstract class UserResourceMapper {
Set<String> mapOrganisationsEinheitIds(UserResource userRes) {
var groups = userRes.groups();
var organisationsEinheitIds = getOrganisationsEinheitIdsFromGroups(groups);
var organisationsEinheitIds = Stream.concat(
getOrganisationsEinheitIdsFromGroups(groups),
getOrganisationsEinheitIdsFromUser(userRes)
)
.filter(Objects::nonNull)
.filter(oeId -> !oeId.isBlank())
.toList();
return new HashSet<>(organisationsEinheitIds);
}
private List<String> getOrganisationsEinheitIdsFromGroups(List<GroupRepresentation> groups) {
private Stream<String> getOrganisationsEinheitIdsFromGroups(List<GroupRepresentation> groups) {
return groups.stream()
.map(this::mapGroup)
.filter(Objects::nonNull)
.map(attributeMap -> attributeMap.get(properties.organisationsEinheitIdKey()))
.filter(Objects::nonNull)
.map(attributeValues -> attributeValues.get(0))
.toList();
.flatMap(Collection::stream);
}
private List<String> getOrganisationsEinheitIdsFromUser(UserResource userRes) {
return List.of();
private Stream<String> getOrganisationsEinheitIdsFromUser(UserResource userRes) {
return Optional.ofNullable(userRes.toRepresentation().getAttributes().get(properties.organisationsEinheitIdKey()))
.orElse(List.of())
.stream();
}
private Map<String, List<String>> mapGroup(GroupRepresentation group) {
......
......@@ -270,8 +270,6 @@ class UserResourceMapperTest {
@Mock
RoleMappingResource roleMappingResource;
@Mock
RoleScopeResource roleScopeResource;
@Mock
MappingsRepresentation mappingsRepresentation;
@Mock
Map<String, ClientMappingsRepresentation> clientMappingsRepresentation;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment