Skip to content
Snippets Groups Projects
Commit dec9cb6b authored by Michael Simon's avatar Michael Simon
Browse files

pull find method with group children one layer down

parent c6612204
No related branches found
No related tags found
No related merge requests found
......@@ -52,6 +52,8 @@ public interface GroupDao extends BaseDao<GroupEntity, Long> {
AttributeSourceGroupDao getAttributeSourceGroupDao();
Set<GroupEntity> findByUserWithChildren(UserEntity user);
Long getNextGID();
ServiceBasedGroupEntity persistWithServiceFlags(
......
......@@ -10,6 +10,7 @@
******************************************************************************/
package edu.kit.scc.webreg.dao.jpa;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -221,6 +222,23 @@ public class JpaGroupDao extends JpaBaseDao<GroupEntity, Long> implements GroupD
}
}
@Override
public Set<GroupEntity> findByUserWithChildren(UserEntity user) {
Set<GroupEntity> groups = new HashSet<GroupEntity>(findByUser(user));
Set<GroupEntity> targetGroups = new HashSet<GroupEntity>();
rollChildren(targetGroups, groups, 0, 3);
return targetGroups;
}
private void rollChildren(Set<GroupEntity> targetGroups, Set<GroupEntity> groups, int depth, int maxDepth) {
if (depth <= maxDepth) {
for (GroupEntity group : groups) {
rollChildren(targetGroups, group.getParents(), depth + 1, maxDepth);
targetGroups.add(group);
}
}
}
@Override
public Long getNextGID() {
return serialDao.next("gid-number-serial");
......
......@@ -10,7 +10,6 @@
******************************************************************************/
package edu.kit.scc.webreg.service.impl;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -96,23 +95,9 @@ public class GroupServiceImpl extends BaseServiceImpl<GroupEntity, Long> impleme
@Override
public Set<GroupEntity> findByUserWithChildren(UserEntity user) {
Set<GroupEntity> groups = new HashSet<GroupEntity>(groupDao.findByUser(user));
Set<GroupEntity> targetGroups = new HashSet<GroupEntity>();
rollChildren(targetGroups, groups, 0, 3);
return targetGroups;
return groupDao.findByUserWithChildren(user);
}
private void rollChildren(Set<GroupEntity> targetGroups, Set<GroupEntity> groups, int depth, int maxDepth) {
if (depth <= maxDepth) {
for (GroupEntity group : groups) {
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);
}
}
}
@Override
protected BaseDao<GroupEntity, Long> getDao() {
return groupDao;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment