mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
[DS-3024] Add a 'permanent' attribute to Groups.
This commit is contained in:
@@ -26,7 +26,6 @@ import java.util.List;
|
||||
* Class representing a group of e-people.
|
||||
*
|
||||
* @author David Stuve
|
||||
* @version $Revision$
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "epersongroup" )
|
||||
@@ -45,6 +44,10 @@ public class Group extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
@Column(name="eperson_group_id", insertable = false, updatable = false)
|
||||
private Integer legacyId;
|
||||
|
||||
/** This Group may not be deleted or renamed. */
|
||||
@Column
|
||||
private Boolean permanent = false;
|
||||
|
||||
/** lists of epeople and groups in the group */
|
||||
@ManyToMany(fetch = FetchType.LAZY)
|
||||
@JoinTable(
|
||||
@@ -171,11 +174,7 @@ public class Group extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
return false;
|
||||
}
|
||||
final Group other = (Group) obj;
|
||||
if (!this.getID().equals(other.getID()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return this.getID().equals(other.getID());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -203,7 +202,9 @@ public class Group extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
|
||||
public void setName(Context context, String name) throws SQLException
|
||||
{
|
||||
getGroupService().setMetadataSingleValue(context, this, MetadataSchema.DC_SCHEMA, "title", null, null, name);
|
||||
if (!permanent)
|
||||
getGroupService().setMetadataSingleValue(context, this,
|
||||
MetadataSchema.DC_SCHEMA, "title", null, null, name);
|
||||
}
|
||||
|
||||
public boolean isGroupsChanged() {
|
||||
@@ -230,4 +231,27 @@ public class Group extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
}
|
||||
return groupService;
|
||||
}
|
||||
|
||||
/**
|
||||
* May this Group be renamed or deleted? (The content of any group may be
|
||||
* changed.)
|
||||
*
|
||||
* @return true if this Group may not be renamed or deleted.
|
||||
*/
|
||||
public Boolean isPermanent()
|
||||
{
|
||||
return permanent;
|
||||
}
|
||||
|
||||
/**
|
||||
* May this Group be renamed or deleted? (The content of any group may be
|
||||
* changed.)
|
||||
*
|
||||
* @param permanence true if this group may not be renamed or deleted.
|
||||
*/
|
||||
void setPermanent(boolean permanence)
|
||||
{
|
||||
permanent = permanence;
|
||||
setModified();
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -198,8 +198,10 @@ public interface GroupService extends DSpaceObjectService<Group>, DSpaceObjectLe
|
||||
public boolean isEmpty(Group group);
|
||||
|
||||
/**
|
||||
* Initializes the group names for anymous & administrator
|
||||
* @param context the dspace context
|
||||
* Initializes the group names for anonymous & administrator, and marks them
|
||||
* "permanent".
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @throws SQLException database exception
|
||||
* @throws AuthorizeException
|
||||
*/
|
||||
|
Reference in New Issue
Block a user