[DS-3024] Add a 'permanent' attribute to Groups.

This commit is contained in:
Mark H. Wood
2016-02-02 17:07:17 -05:00
parent 717e95eed1
commit 8fc324e9f3
3 changed files with 53 additions and 17 deletions

View File

@@ -8,7 +8,6 @@
package org.dspace.eperson;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.dspace.authorize.AuthorizeConfiguration;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.service.AuthorizeService;
@@ -29,10 +28,12 @@ import org.dspace.eperson.service.GroupService;
import org.dspace.event.Event;
import org.springframework.beans.factory.annotation.Autowired;
import java.nio.ByteBuffer;
import java.sql.SQLException;
import java.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Service implementation for the Group object.
* This class is responsible for all business logic calls for the Group object and is autowired by spring.
@@ -42,7 +43,7 @@ import java.util.*;
*/
public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements GroupService
{
private static final Logger log = Logger.getLogger(GroupServiceImpl.class);
private static final Logger log = LoggerFactory.getLogger(GroupServiceImpl.class);
@Autowired(required = true)
protected GroupDAO groupDAO;
@@ -89,7 +90,7 @@ public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements
@Override
public void setName(Context context, Group group, String name) throws SQLException {
setMetadataSingleValue(context, group, MetadataSchema.DC_SCHEMA, "title", null, null, name);
group.setName(context, name);
}
@Override
@@ -161,7 +162,7 @@ public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements
@Override
public List<Group> allMemberGroups(Context context, EPerson ePerson) throws SQLException {
Set<Group> groups = new HashSet<Group>();
Set<Group> groups = new HashSet<>();
if (ePerson != null)
{
@@ -206,7 +207,7 @@ public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements
// Get all groups which are a member of this group
List<Group2GroupCache> group2GroupCaches = group2GroupCacheDAO.findByParent(c, g);
Set<Group> groups = new HashSet<Group>();
Set<Group> groups = new HashSet<>();
for (Group2GroupCache group2GroupCache : group2GroupCaches) {
groups.add(group2GroupCache.getChild());
}
@@ -292,7 +293,14 @@ public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements
@Override
public void delete(Context context, Group group) throws SQLException {
context.addEvent(new Event(Event.DELETE, Constants.GROUP, group.getID(), group.getName(), getIdentifiers(context, group)));
if (group.isPermanent())
{
log.error("Attempt to delete permanent Group $", group.getName());
throw new SQLException("Attempt to delete a permanent Group");
}
context.addEvent(new Event(Event.DELETE, Constants.GROUP, group.getID(),
group.getName(), getIdentifiers(context, group)));
//Remove the supervised group from any workspace items linked to us.
group.getSupervisedItems().clear();
@@ -335,7 +343,7 @@ public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements
public boolean isEmpty(Group group)
{
// the only fast check available is on epeople...
boolean hasMembers = (group.getMembers().size() != 0);
boolean hasMembers = (!group.getMembers().isEmpty());
if (hasMembers)
{
@@ -363,6 +371,7 @@ public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements
{
anonymousGroup = groupService.create(context);
anonymousGroup.setName(context, Group.ANONYMOUS);
anonymousGroup.setPermanent(true);
groupService.update(context, anonymousGroup);
}
@@ -373,6 +382,7 @@ public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements
{
adminGroup = groupService.create(context);
adminGroup.setName(context, Group.ADMIN);
adminGroup.setPermanent(true);
groupService.update(context, adminGroup);
}
}