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
Branches
Tags
No related merge requests found
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*/ */
package de.ozgcloud.user; package de.ozgcloud.user;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
...@@ -78,22 +79,29 @@ public abstract class UserResourceMapper { ...@@ -78,22 +79,29 @@ public abstract class UserResourceMapper {
Set<String> mapOrganisationsEinheitIds(UserResource userRes) { Set<String> mapOrganisationsEinheitIds(UserResource userRes) {
var groups = userRes.groups(); 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); return new HashSet<>(organisationsEinheitIds);
} }
private List<String> getOrganisationsEinheitIdsFromGroups(List<GroupRepresentation> groups) { private Stream<String> getOrganisationsEinheitIdsFromGroups(List<GroupRepresentation> groups) {
return groups.stream() return groups.stream()
.map(this::mapGroup) .map(this::mapGroup)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.map(attributeMap -> attributeMap.get(properties.organisationsEinheitIdKey())) .map(attributeMap -> attributeMap.get(properties.organisationsEinheitIdKey()))
.filter(Objects::nonNull) .filter(Objects::nonNull)
.map(attributeValues -> attributeValues.get(0)) .flatMap(Collection::stream);
.toList();
} }
private List<String> getOrganisationsEinheitIdsFromUser(UserResource userRes) { private Stream<String> getOrganisationsEinheitIdsFromUser(UserResource userRes) {
return List.of(); return Optional.ofNullable(userRes.toRepresentation().getAttributes().get(properties.organisationsEinheitIdKey()))
.orElse(List.of())
.stream();
} }
private Map<String, List<String>> mapGroup(GroupRepresentation group) { private Map<String, List<String>> mapGroup(GroupRepresentation group) {
......
...@@ -270,8 +270,6 @@ class UserResourceMapperTest { ...@@ -270,8 +270,6 @@ class UserResourceMapperTest {
@Mock @Mock
RoleMappingResource roleMappingResource; RoleMappingResource roleMappingResource;
@Mock @Mock
RoleScopeResource roleScopeResource;
@Mock
MappingsRepresentation mappingsRepresentation; MappingsRepresentation mappingsRepresentation;
@Mock @Mock
Map<String, ClientMappingsRepresentation> clientMappingsRepresentation; 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