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

Groups are now rolled correctly

parent 9be83c7b
......@@ -33,7 +33,7 @@ public interface GroupService extends BaseService<GroupEntity, Long> {
void removeUserGromGroup(UserEntity user, GroupEntity group);
Set<GroupEntity> findByUserWithParents(UserEntity user);
Set<GroupEntity> findByUserWithChildren(UserEntity user);
ServiceBasedGroupEntity persistWithServiceFlags(
ServiceBasedGroupEntity entity);
......
......@@ -17,6 +17,8 @@ import java.util.Set;
import javax.ejb.Stateless;
import javax.inject.Inject;
import org.slf4j.Logger;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.GroupDao;
import edu.kit.scc.webreg.dao.UserDao;
......@@ -31,6 +33,9 @@ public class GroupServiceImpl extends BaseServiceImpl<GroupEntity, Long> impleme
private static final long serialVersionUID = 1L;
@Inject
private Logger logger;
@Inject
private GroupDao groupDao;
......@@ -98,17 +103,19 @@ public class GroupServiceImpl extends BaseServiceImpl<GroupEntity, Long> impleme
}
@Override
public Set<GroupEntity> findByUserWithParents(UserEntity user) {
public Set<GroupEntity> findByUserWithChildren(UserEntity user) {
Set<GroupEntity> groups = new HashSet<GroupEntity>(groupDao.findByUser(user));
Set<GroupEntity> targetGroups = new HashSet<GroupEntity>();
rollParents(targetGroups, groups, 0, 3);
return groups;
rollChildren(targetGroups, groups, 0, 3);
return targetGroups;
}
private void rollParents(Set<GroupEntity> targetGroups, Set<GroupEntity> groups, int depth, int maxDepth) {
private void rollChildren(Set<GroupEntity> targetGroups, Set<GroupEntity> groups, int depth, int maxDepth) {
if (depth <= maxDepth) {
for (GroupEntity group : groups) {
rollParents(targetGroups, group.getParents(), depth + 1, maxDepth);
if (logger.isTraceEnabled())
logger.trace("Inspecting group {} with children count {}", group.getName(), group.getParents().size());
rollChildren(targetGroups, group.getParents(), depth + 1, maxDepth);
targetGroups.add(group);
}
}
......
......@@ -106,12 +106,13 @@ public class AuthorizationBean implements Serializable {
if (sessionManager.getGroupSetCreated() == null ||
(System.currentTimeMillis() - sessionManager.getGroupSetCreated()) > groupsTimeout) {
start = System.currentTimeMillis();
Set<GroupEntity> groupList = groupService.findByUserWithParents(user);
Set<GroupEntity> groupList = groupService.findByUserWithChildren(user);
sessionManager.clearGroups();
sessionManager.getGroups().addAll(groupList);
for (GroupEntity g : groupList)
for (GroupEntity g : groupList) {
sessionManager.getGroupNames().add(g.getName());
}
sessionManager.setGroupSetCreated(System.currentTimeMillis());
end = System.currentTimeMillis();
......
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