Commit f2b9e880 authored by michael.simon's avatar michael.simon
Browse files

Load groups recursive for user

parent c11db231
......@@ -32,4 +32,6 @@ public interface GroupService extends BaseService<GroupEntity, Long> {
void removeUserGromGroup(UserEntity user, GroupEntity group);
Set<GroupEntity> findByUserWithParents(UserEntity user);
}
......@@ -85,6 +85,23 @@ public class GroupServiceImpl extends BaseServiceImpl<GroupEntity, Long> impleme
return groupDao.findByUser(user);
}
@Override
public Set<GroupEntity> findByUserWithParents(UserEntity user) {
Set<GroupEntity> groups = new HashSet<GroupEntity>(groupDao.findByUser(user));
Set<GroupEntity> targetGroups = new HashSet<GroupEntity>();
rollParents(targetGroups, groups, 0, 3);
return groups;
}
private void rollParents(Set<GroupEntity> targetGroups, Set<GroupEntity> groups, int depth, int maxDepth) {
if (depth <= maxDepth) {
for (GroupEntity group : groups) {
rollParents(targetGroups, group.getParents(), depth + 1, maxDepth);
targetGroups.add(group);
}
}
}
@Override
protected BaseDao<GroupEntity, Long> getDao() {
return groupDao;
......
......@@ -93,7 +93,8 @@ public class AuthorizationBean implements Serializable {
if (sessionManager.getRoleSetCreated() == null ||
(System.currentTimeMillis() - sessionManager.getRoleSetCreated()) > 5 * 60 * 1000L) {
start = System.currentTimeMillis();
List<GroupEntity> groupList = groupService.findByUser(user);
Set<GroupEntity> groupList = groupService.findByUserWithParents(user);
sessionManager.setGroupString(groupsToString(groupList));
for (GroupEntity g : groupList) {
......@@ -267,9 +268,9 @@ public class AuthorizationBean implements Serializable {
return unregisteredServiceList;
}
private String groupsToString(List<GroupEntity> groupList) {
private String groupsToString(Set<GroupEntity> groups) {
StringBuilder sb = new StringBuilder();
for (GroupEntity group : groupList) {
for (GroupEntity group : groups) {
if (group instanceof HomeOrgGroupEntity &&
((HomeOrgGroupEntity) group).getPrefix() != null) {
sb.append(((HomeOrgGroupEntity) group).getPrefix());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment