mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
Replace several usages of allMembers() with count methods to avoid performance issues
This commit is contained in:
@@ -305,10 +305,13 @@ public class EPersonServiceImpl extends DSpaceObjectServiceImpl<EPerson> impleme
|
|||||||
throw new AuthorizeException(
|
throw new AuthorizeException(
|
||||||
"You must be an admin to delete an EPerson");
|
"You must be an admin to delete an EPerson");
|
||||||
}
|
}
|
||||||
|
// Get all workflow-related groups that the current EPerson belongs to
|
||||||
Set<Group> workFlowGroups = getAllWorkFlowGroups(context, ePerson);
|
Set<Group> workFlowGroups = getAllWorkFlowGroups(context, ePerson);
|
||||||
for (Group group: workFlowGroups) {
|
for (Group group: workFlowGroups) {
|
||||||
List<EPerson> ePeople = groupService.allMembers(context, group);
|
// Get total number of unique EPerson objs who are a member of this group (or subgroup)
|
||||||
if (ePeople.size() == 1 && ePeople.contains(ePerson)) {
|
int totalMembers = groupService.countAllMembers(context, group);
|
||||||
|
// If only one EPerson is a member, then we cannot delete the last member of this group.
|
||||||
|
if (totalMembers == 1) {
|
||||||
throw new EmptyWorkflowGroupException(ePerson.getID(), group.getID());
|
throw new EmptyWorkflowGroupException(ePerson.getID(), group.getID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -179,8 +179,10 @@ public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements
|
|||||||
for (CollectionRole collectionRole : collectionRoles) {
|
for (CollectionRole collectionRole : collectionRoles) {
|
||||||
if (StringUtils.equals(collectionRole.getRoleId(), role.getId())
|
if (StringUtils.equals(collectionRole.getRoleId(), role.getId())
|
||||||
&& claimedTask.getWorkflowItem().getCollection() == collectionRole.getCollection()) {
|
&& claimedTask.getWorkflowItem().getCollection() == collectionRole.getCollection()) {
|
||||||
List<EPerson> ePeople = allMembers(context, group);
|
// Get total number of unique EPerson objs who are a member of this group (or subgroup)
|
||||||
if (ePeople.size() == 1 && ePeople.contains(ePerson)) {
|
int totalMembers = countAllMembers(context, group);
|
||||||
|
// If only one EPerson is a member, then we cannot delete the last member of this group.
|
||||||
|
if (totalMembers == 1) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Refused to remove user " + ePerson
|
"Refused to remove user " + ePerson
|
||||||
.getID() + " from workflow group because the group " + group
|
.getID() + " from workflow group because the group " + group
|
||||||
@@ -191,8 +193,10 @@ public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!poolTasks.isEmpty()) {
|
if (!poolTasks.isEmpty()) {
|
||||||
List<EPerson> ePeople = allMembers(context, group);
|
// Get total number of unique EPerson objs who are a member of this group (or subgroup)
|
||||||
if (ePeople.size() == 1 && ePeople.contains(ePerson)) {
|
int totalMembers = countAllMembers(context, group);
|
||||||
|
// If only one EPerson is a member, then we cannot delete the last member of this group.
|
||||||
|
if (totalMembers == 1) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Refused to remove user " + ePerson
|
"Refused to remove user " + ePerson
|
||||||
.getID() + " from workflow group because the group " + group
|
.getID() + " from workflow group because the group " + group
|
||||||
@@ -212,9 +216,10 @@ public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements
|
|||||||
if (!collectionRoles.isEmpty()) {
|
if (!collectionRoles.isEmpty()) {
|
||||||
List<PoolTask> poolTasks = poolTaskService.findByGroup(context, groupParent);
|
List<PoolTask> poolTasks = poolTaskService.findByGroup(context, groupParent);
|
||||||
if (!poolTasks.isEmpty()) {
|
if (!poolTasks.isEmpty()) {
|
||||||
List<EPerson> parentPeople = allMembers(context, groupParent);
|
// Count number of Groups which have this groupParent as a direct parent
|
||||||
List<EPerson> childPeople = allMembers(context, childGroup);
|
int totalChildren = countByParent(context, groupParent);
|
||||||
if (childPeople.containsAll(parentPeople)) {
|
// If only one group has this as a parent, we cannot delete the last child group
|
||||||
|
if (totalChildren == 1) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Refused to remove sub group " + childGroup
|
"Refused to remove sub group " + childGroup
|
||||||
.getID() + " from workflow group because the group " + groupParent
|
.getID() + " from workflow group because the group " + groupParent
|
||||||
|
Reference in New Issue
Block a user