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> { ...@@ -32,4 +32,6 @@ public interface GroupService extends BaseService<GroupEntity, Long> {
void removeUserGromGroup(UserEntity user, GroupEntity group); void removeUserGromGroup(UserEntity user, GroupEntity group);
Set<GroupEntity> findByUserWithParents(UserEntity user);
} }
...@@ -85,6 +85,23 @@ public class GroupServiceImpl extends BaseServiceImpl<GroupEntity, Long> impleme ...@@ -85,6 +85,23 @@ public class GroupServiceImpl extends BaseServiceImpl<GroupEntity, Long> impleme
return groupDao.findByUser(user); 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 @Override
protected BaseDao<GroupEntity, Long> getDao() { protected BaseDao<GroupEntity, Long> getDao() {
return groupDao; return groupDao;
......
...@@ -93,7 +93,8 @@ public class AuthorizationBean implements Serializable { ...@@ -93,7 +93,8 @@ public class AuthorizationBean implements Serializable {
if (sessionManager.getRoleSetCreated() == null || if (sessionManager.getRoleSetCreated() == null ||
(System.currentTimeMillis() - sessionManager.getRoleSetCreated()) > 5 * 60 * 1000L) { (System.currentTimeMillis() - sessionManager.getRoleSetCreated()) > 5 * 60 * 1000L) {
start = System.currentTimeMillis(); start = System.currentTimeMillis();
List<GroupEntity> groupList = groupService.findByUser(user); Set<GroupEntity> groupList = groupService.findByUserWithParents(user);
sessionManager.setGroupString(groupsToString(groupList)); sessionManager.setGroupString(groupsToString(groupList));
for (GroupEntity g : groupList) { for (GroupEntity g : groupList) {
...@@ -267,9 +268,9 @@ public class AuthorizationBean implements Serializable { ...@@ -267,9 +268,9 @@ public class AuthorizationBean implements Serializable {
return unregisteredServiceList; return unregisteredServiceList;
} }
private String groupsToString(List<GroupEntity> groupList) { private String groupsToString(Set<GroupEntity> groups) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (GroupEntity group : groupList) { for (GroupEntity group : groups) {
if (group instanceof HomeOrgGroupEntity && if (group instanceof HomeOrgGroupEntity &&
((HomeOrgGroupEntity) group).getPrefix() != null) { ((HomeOrgGroupEntity) group).getPrefix() != null) {
sb.append(((HomeOrgGroupEntity) group).getPrefix()); 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