diff --git a/dspace-api/src/main/java/org/dspace/content/CollectionServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/CollectionServiceImpl.java index bfc1c1093a15..276bbca6bd7f 100644 --- a/dspace-api/src/main/java/org/dspace/content/CollectionServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/CollectionServiceImpl.java @@ -318,7 +318,8 @@ public Group createWorkflowGroup(Context context, Collection collection, int ste Group g = groupService.create(context); context.restoreAuthSystemState(); - g.setName(context, "COLLECTION_" + collection.getID() + "_WORKFLOW_STEP_" + step); + groupService.setName(context, g, + "COLLECTION_" + collection.getID() + "_WORKFLOW_STEP_" + step); groupService.update(context, g); setWorkflowGroup(collection, step, g); @@ -395,7 +396,8 @@ public Group createSubmitters(Context context, Collection collection) throws SQL submitters = groupService.create(context); context.restoreAuthSystemState(); - submitters.setName(context, "COLLECTION_" + collection.getID() + "_SUBMIT"); + groupService.setName(context, submitters, + "COLLECTION_" + collection.getID() + "_SUBMIT"); groupService.update(context, submitters); } @@ -435,7 +437,7 @@ public Group createAdministrators(Context context, Collection collection) throws admins = groupService.create(context); context.restoreAuthSystemState(); - admins.setName(context, "COLLECTION_" + collection.getID() + "_ADMIN"); + groupService.setName(context, admins, "COLLECTION_" + collection.getID() + "_ADMIN"); groupService.update(context, admins); } diff --git a/dspace-api/src/main/java/org/dspace/content/CommunityServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/CommunityServiceImpl.java index eaff01ddfdbc..877d9032e2cd 100644 --- a/dspace-api/src/main/java/org/dspace/content/CommunityServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/CommunityServiceImpl.java @@ -270,7 +270,7 @@ public Group createAdministrators(Context context, Community community) throws S admins = groupService.create(context); context.restoreAuthSystemState(); - admins.setName(context, "COMMUNITY_" + community.getID() + "_ADMIN"); + groupService.setName(context, admins, "COMMUNITY_" + community.getID() + "_ADMIN"); groupService.update(context, admins); } diff --git a/dspace-api/src/main/java/org/dspace/content/packager/RoleIngester.java b/dspace-api/src/main/java/org/dspace/content/packager/RoleIngester.java index 7e7ee72e9ad5..7cfed3924649 100644 --- a/dspace-api/src/main/java/org/dspace/content/packager/RoleIngester.java +++ b/dspace-api/src/main/java/org/dspace/content/packager/RoleIngester.java @@ -356,7 +356,7 @@ else if(parent.getType()==Constants.COMMUNITY) } // Always set the name: parent.createBlop() is guessing - groupObj.setName(context, name); + groupService.setName(context, groupObj, name); log.info("Created Group {}.", groupObj.getName()); } diff --git a/dspace-api/src/main/java/org/dspace/eperson/Group.java b/dspace-api/src/main/java/org/dspace/eperson/Group.java index 9fb3baa0ae35..d61046f6d9d9 100644 --- a/dspace-api/src/main/java/org/dspace/eperson/Group.java +++ b/dspace-api/src/main/java/org/dspace/eperson/Group.java @@ -24,9 +24,8 @@ /** * 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( @@ -147,14 +150,14 @@ public List getMemberGroups() { return groups; } - + /** * Return true if other is the same Group as * this object, false otherwise - * + * * @param obj * object to compare to - * + * * @return true if object passed in represents the same group * as this object */ @@ -171,11 +174,7 @@ public boolean equals(Object obj) return false; } final Group other = (Group) obj; - if (!this.getID().equals(other.getID())) - { - return false; - } - return true; + return this.getID().equals(other.getID()); } @Override @@ -201,9 +200,11 @@ public String getName() return getGroupService().getName(this); } - public void setName(Context context, String name) throws SQLException + /** Change the name of this Group. */ + void setName(Context context, String name) throws SQLException { - getGroupService().setMetadataSingleValue(context, this, MetadataSchema.DC_SCHEMA, "title", null, null, name); + getGroupService().setMetadataSingleValue(context, this, + MetadataSchema.DC_SCHEMA, "title", null, null, name); } public boolean isGroupsChanged() { @@ -230,4 +231,27 @@ private GroupService getGroupService() { } 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(); + } } diff --git a/dspace-api/src/main/java/org/dspace/eperson/GroupServiceImpl.java b/dspace-api/src/main/java/org/dspace/eperson/GroupServiceImpl.java index 4b4cc2148e98..1bed461071c4 100644 --- a/dspace-api/src/main/java/org/dspace/eperson/GroupServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/eperson/GroupServiceImpl.java @@ -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.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 @@ */ public class GroupServiceImpl extends DSpaceObjectServiceImpl 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; @@ -93,7 +94,14 @@ public Group create(Context context) throws SQLException, AuthorizeException { @Override public void setName(Context context, Group group, String name) throws SQLException { - setMetadataSingleValue(context, group, MetadataSchema.DC_SCHEMA, "title", null, null, name); + if (group.isPermanent()) + { + log.error("Attempt to rename permanent Group {} to {}.", + group.getName(), name); + throw new SQLException("Attempt to rename a permanent Group"); + } + else + group.setName(context, name); } @Override @@ -165,7 +173,7 @@ public boolean isMember(Context context, Group group) throws SQLException { @Override public List allMemberGroups(Context context, EPerson ePerson) throws SQLException { - Set groups = new HashSet(); + Set groups = new HashSet<>(); if (ePerson != null) { @@ -210,7 +218,7 @@ public List allMembers(Context c, Group g) throws SQLException // Get all groups which are a member of this group List group2GroupCaches = group2GroupCacheDAO.findByParent(c, g); - Set groups = new HashSet(); + Set groups = new HashSet<>(); for (Group2GroupCache group2GroupCache : group2GroupCaches) { groups.add(group2GroupCache.getChild()); } @@ -296,7 +304,14 @@ public int searchResultCount(Context context, String query) throws SQLException @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(); @@ -339,7 +354,7 @@ public int getSupportsTypeConstant() { 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) { @@ -367,6 +382,7 @@ public void initDefaultGroupNames(Context context) throws SQLException, Authoriz { anonymousGroup = groupService.create(context); anonymousGroup.setName(context, Group.ANONYMOUS); + anonymousGroup.setPermanent(true); groupService.update(context, anonymousGroup); } @@ -377,6 +393,7 @@ public void initDefaultGroupNames(Context context) throws SQLException, Authoriz { adminGroup = groupService.create(context); adminGroup.setName(context, Group.ADMIN); + adminGroup.setPermanent(true); groupService.update(context, adminGroup); } } diff --git a/dspace-api/src/main/java/org/dspace/eperson/service/GroupService.java b/dspace-api/src/main/java/org/dspace/eperson/service/GroupService.java index 61806d6b87e1..c5186f8cefac 100644 --- a/dspace-api/src/main/java/org/dspace/eperson/service/GroupService.java +++ b/dspace-api/src/main/java/org/dspace/eperson/service/GroupService.java @@ -198,8 +198,10 @@ public interface GroupService extends DSpaceObjectService, 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 */ diff --git a/dspace-api/src/main/java/org/dspace/xmlworkflow/XmlWorkflowServiceImpl.java b/dspace-api/src/main/java/org/dspace/xmlworkflow/XmlWorkflowServiceImpl.java index 284ef4a8d0cf..16b9430df9fa 100644 --- a/dspace-api/src/main/java/org/dspace/xmlworkflow/XmlWorkflowServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/xmlworkflow/XmlWorkflowServiceImpl.java @@ -131,9 +131,11 @@ public Group getWorkflowRoleGroup(Context context, Collection collection, String authorizeService.authorizeAction(context, collection, Constants.WRITE); roleGroup = groupService.create(context); if(role.getScope() == Role.Scope.COLLECTION){ - roleGroup.setName(context, "COLLECTION_" + collection.getID().toString() + "_WORKFLOW_ROLE_" + roleName); + groupService.setName(context, roleGroup, + "COLLECTION_" + collection.getID().toString() + + "_WORKFLOW_ROLE_" + roleName); }else{ - roleGroup.setName(context, role.getName()); + groupService.setName(context, roleGroup, role.getName()); } groupService.update(context, roleGroup); authorizeService.addPolicy(context, collection, Constants.ADD, roleGroup); diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V6.0_2015.03.07__DS-2701_Hibernate_migration.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V6.0_2015.03.07__DS-2701_Hibernate_migration.sql index ac4cfae79bee..94c30bbf671b 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V6.0_2015.03.07__DS-2701_Hibernate_migration.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V6.0_2015.03.07__DS-2701_Hibernate_migration.sql @@ -32,6 +32,11 @@ ALTER TABLE eperson ALTER COLUMN eperson_id SET NULL; +UPDATE metadatavalue SET text_value='Administrator' + WHERE resource_type_id=6 AND resource_id=1; +UPDATE metadatavalue SET text_value='Anonymous' + WHERE resource_type_id=6 AND resource_id=0; + ALTER TABLE epersongroup ADD COLUMN uuid UUID DEFAULT random_uuid(); INSERT INTO dspaceobject (uuid) SELECT uuid FROM epersongroup; ALTER TABLE epersongroup ADD FOREIGN KEY (uuid) REFERENCES dspaceobject; diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V6.0_2016.01.03__DS-3024.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V6.0_2016.01.03__DS-3024.sql new file mode 100644 index 000000000000..bc1857241ff9 --- /dev/null +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V6.0_2016.01.03__DS-3024.sql @@ -0,0 +1,27 @@ +-- +-- The contents of this file are subject to the license and copyright +-- detailed in the LICENSE and NOTICE files at the root of the source +-- tree and available online at +-- +-- http://www.dspace.org/license/ +-- + +------------------------------------------------------ +-- DS-3024 Invent "permanent" groups +------------------------------------------------------ + +ALTER TABLE epersongroup + ADD (permanent BOOLEAN DEFAULT false); +UPDATE epersongroup SET permanent = true + WHERE uuid IN ( + SELECT dspace_object_id + FROM metadataschemaregistry AS s + JOIN metadatafieldregistry AS f + ON (s.metadata_schema_id = f.metadata_schema_id) + JOIN metadatavalue AS v + ON (f.metadata_field_id = v.metadata_field_id) + WHERE s.short_id = 'dc' + AND f.element = 'title' + AND f.qualifier IS NULL + AND v.text_value IN ('Administrator', 'Anonymous') + ); diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/oracle/V6.0_2015.03.07__DS-2701_Hibernate_migration.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/oracle/V6.0_2015.03.07__DS-2701_Hibernate_migration.sql index 16460cc3f0ef..a51dc6897a89 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/oracle/V6.0_2015.03.07__DS-2701_Hibernate_migration.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/oracle/V6.0_2015.03.07__DS-2701_Hibernate_migration.sql @@ -32,6 +32,11 @@ UPDATE eperson SET self_registered = '0' WHERE self_registered IS NULL; +UPDATE metadatavalue SET text_value='Administrator' + WHERE resource_type_id=6 AND resource_id=1; +UPDATE metadatavalue SET text_value='Anonymous' + WHERE resource_type_id=6 AND resource_id=0; + ALTER TABLE epersongroup ADD uuid RAW(16) DEFAULT SYS_GUID(); INSERT INTO dspaceobject (uuid) SELECT uuid FROM epersongroup; ALTER TABLE epersongroup ADD FOREIGN KEY (uuid) REFERENCES dspaceobject; diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/oracle/V6.0_2016.01.03__DS-3024.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/oracle/V6.0_2016.01.03__DS-3024.sql new file mode 100644 index 000000000000..09cba8447821 --- /dev/null +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/oracle/V6.0_2016.01.03__DS-3024.sql @@ -0,0 +1,25 @@ +-- +-- The contents of this file are subject to the license and copyright +-- detailed in the LICENSE and NOTICE files at the root of the source +-- tree and available online at +-- +-- http://www.dspace.org/license/ +-- + +------------------------------------------------------ +-- DS-3024 Invent "permanent" groups +------------------------------------------------------ + +ALTER TABLE epersongroup + ADD (permanent NUMBER(1) DEFAULT 0); +UPDATE epersongroup SET permanent = 1 + WHERE uuid IN ( + SELECT dspace_object_id + FROM metadataschemaregistry s + JOIN metadatafieldregistry f USING (metadata_schema_id) + JOIN metadatavalue v USING (metadata_field_id) + WHERE s.short_id = 'dc' + AND f.element = 'title' + AND f.qualifier IS NULL + AND v.text_value IN ('Administrator', 'Anonymous') + ); diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V6.0_2015.03.07__DS-2701_Hibernate_migration.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V6.0_2015.03.07__DS-2701_Hibernate_migration.sql index d38508ca1bc1..ecb5797884a7 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V6.0_2015.03.07__DS-2701_Hibernate_migration.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V6.0_2015.03.07__DS-2701_Hibernate_migration.sql @@ -35,6 +35,11 @@ UPDATE eperson SET self_registered = false WHERE self_registered IS NULL; +UPDATE metadatavalue SET text_value='Administrator' + WHERE resource_type_id=6 AND resource_id=1; +UPDATE metadatavalue SET text_value='Anonymous' + WHERE resource_type_id=6 AND resource_id=0; + ALTER TABLE epersongroup ADD COLUMN uuid UUID DEFAULT gen_random_uuid() UNIQUE; INSERT INTO dspaceobject (uuid) SELECT uuid FROM epersongroup; ALTER TABLE epersongroup ADD FOREIGN KEY (uuid) REFERENCES dspaceobject; diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V6.0_2016.01.03__DS-3024.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V6.0_2016.01.03__DS-3024.sql new file mode 100644 index 000000000000..57a57bb9e11f --- /dev/null +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V6.0_2016.01.03__DS-3024.sql @@ -0,0 +1,25 @@ +-- +-- The contents of this file are subject to the license and copyright +-- detailed in the LICENSE and NOTICE files at the root of the source +-- tree and available online at +-- +-- http://www.dspace.org/license/ +-- + +------------------------------------------------------ +-- DS-3024 Invent "permanent" groups +------------------------------------------------------ + +ALTER TABLE epersongroup + ADD COLUMN permanent BOOLEAN DEFAULT false; +UPDATE epersongroup SET permanent = true + WHERE uuid IN ( + SELECT dspace_object_id + FROM metadataschemaregistry s + JOIN metadatafieldregistry f USING (metadata_schema_id) + JOIN metadatavalue v USING (metadata_field_id) + WHERE s.short_id = 'dc' + AND f.element = 'title' + AND f.qualifier IS NULL + AND v.text_value IN ('Administrator', 'Anonymous') + ); diff --git a/dspace-api/src/test/java/org/dspace/eperson/GroupServiceImplIT.java b/dspace-api/src/test/java/org/dspace/eperson/GroupServiceImplIT.java new file mode 100644 index 000000000000..5de98ed16cb9 --- /dev/null +++ b/dspace-api/src/test/java/org/dspace/eperson/GroupServiceImplIT.java @@ -0,0 +1,660 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE and NOTICE files at the root of the source + * tree and available online at + * + * http://www.dspace.org/license/ + */ +package org.dspace.eperson; + +import java.sql.SQLException; +import org.dspace.AbstractUnitTest; +import org.dspace.eperson.factory.EPersonServiceFactory; +import org.dspace.eperson.service.GroupService; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Test integration of GroupServiceImpl. + * + * @author mwood + */ +public class GroupServiceImplIT + extends AbstractUnitTest +{ + public GroupServiceImplIT() + { + super(); + } + +/* + @BeforeClass + public static void setUpClass() + { + } +*/ + +/* + @AfterClass + public static void tearDownClass() + { + } +*/ + + @Before + @Override + public void init() + { + super.init(); + } + + @After + @Override + public void destroy() + { + super.destroy(); + } + + /** + * Test of create method, of class GroupServiceImpl. + */ +/* + @Test + public void testCreate() + throws Exception + { + System.out.println("create"); + Context context = null; + GroupServiceImpl instance = new GroupServiceImpl(); + Group expResult = null; + Group result = instance.create(context); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of setName method, of class GroupServiceImpl. + */ +/* + @Test + public void testSetName() + throws Exception + { + System.out.println("setName"); + Context context = null; + Group group = null; + String name = ""; + GroupServiceImpl instance = new GroupServiceImpl(); + instance.setName(context, group, name); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of setName method applied to a 'permanent' Group. + */ + @Test(expected = SQLException.class) + public void testSetName_permanent() + throws Exception + { + System.out.println("setName on a 'permanent' Group"); + String name = "NOTANONYMOUS"; + GroupService groupService = EPersonServiceFactory.getInstance().getGroupService(); + Group group = groupService.findByName(context, Group.ANONYMOUS); + groupService.setName(context, group, name); + } + + /** + * Test of addMember method, of class GroupServiceImpl. + */ +/* + @Test + public void testAddMember_3args_1() + { + System.out.println("addMember"); + Context context = null; + Group group = null; + EPerson e = null; + GroupServiceImpl instance = new GroupServiceImpl(); + instance.addMember(context, group, e); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of addMember method, of class GroupServiceImpl. + */ +/* + @Test + public void testAddMember_3args_2() + throws Exception + { + System.out.println("addMember"); + Context context = null; + Group groupParent = null; + Group groupChild = null; + GroupServiceImpl instance = new GroupServiceImpl(); + instance.addMember(context, groupParent, groupChild); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of removeMember method, of class GroupServiceImpl. + */ +/* + @Test + public void testRemoveMember_3args_1() + { + System.out.println("removeMember"); + Context context = null; + Group group = null; + EPerson ePerson = null; + GroupServiceImpl instance = new GroupServiceImpl(); + instance.removeMember(context, group, ePerson); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of removeMember method, of class GroupServiceImpl. + */ +/* + @Test + public void testRemoveMember_3args_2() + throws Exception + { + System.out.println("removeMember"); + Context context = null; + Group groupParent = null; + Group childGroup = null; + GroupServiceImpl instance = new GroupServiceImpl(); + instance.removeMember(context, groupParent, childGroup); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of isDirectMember method, of class GroupServiceImpl. + */ +/* + @Test + public void testIsDirectMember() + { + System.out.println("isDirectMember"); + Group group = null; + EPerson ePerson = null; + GroupServiceImpl instance = new GroupServiceImpl(); + boolean expResult = false; + boolean result = instance.isDirectMember(group, ePerson); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of isMember method, of class GroupServiceImpl. + */ +/* + @Test + public void testIsMember_Group_Group() + { + System.out.println("isMember"); + Group owningGroup = null; + Group childGroup = null; + GroupServiceImpl instance = new GroupServiceImpl(); + boolean expResult = false; + boolean result = instance.isMember(owningGroup, childGroup); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of isMember method, of class GroupServiceImpl. + */ +/* + @Test + public void testIsMember_Context_Group() + throws Exception + { + System.out.println("isMember"); + Context context = null; + Group group = null; + GroupServiceImpl instance = new GroupServiceImpl(); + boolean expResult = false; + boolean result = instance.isMember(context, group); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of allMemberGroups method, of class GroupServiceImpl. + */ +/* + @Test + public void testAllMemberGroups() + throws Exception + { + System.out.println("allMemberGroups"); + Context context = null; + EPerson ePerson = null; + GroupServiceImpl instance = new GroupServiceImpl(); + List expResult = null; + List result = instance.allMemberGroups(context, ePerson); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of allMembers method, of class GroupServiceImpl. + */ +/* + @Test + public void testAllMembers() + throws Exception + { + System.out.println("allMembers"); + Context c = null; + Group g = null; + GroupServiceImpl instance = new GroupServiceImpl(); + List expResult = null; + List result = instance.allMembers(c, g); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of find method, of class GroupServiceImpl. + */ +/* + @Test + public void testFind() + throws Exception + { + System.out.println("find"); + Context context = null; + UUID id = null; + GroupServiceImpl instance = new GroupServiceImpl(); + Group expResult = null; + Group result = instance.find(context, id); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of findByName method, of class GroupServiceImpl. + */ +/* + @Test + public void testFindByName() + throws Exception + { + System.out.println("findByName"); + Context context = null; + String name = ""; + GroupServiceImpl instance = new GroupServiceImpl(); + Group expResult = null; + Group result = instance.findByName(context, name); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of findAll method, of class GroupServiceImpl. + */ +/* + @Test + public void testFindAll() + throws Exception + { + System.out.println("findAll"); + Context context = null; + int sortField = 0; + GroupServiceImpl instance = new GroupServiceImpl(); + List expResult = null; + List result = instance.findAll(context, sortField); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of search method, of class GroupServiceImpl. + */ +/* + @Test + public void testSearch_Context_String() + throws Exception + { + System.out.println("search"); + Context context = null; + String query = ""; + GroupServiceImpl instance = new GroupServiceImpl(); + List expResult = null; + List result = instance.search(context, query); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of search method, of class GroupServiceImpl. + */ +/* + @Test + public void testSearch_4args() + throws Exception + { + System.out.println("search"); + Context context = null; + String query = ""; + int offset = 0; + int limit = 0; + GroupServiceImpl instance = new GroupServiceImpl(); + List expResult = null; + List result = instance.search(context, query, offset, limit); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of searchResultCount method, of class GroupServiceImpl. + */ +/* + @Test + public void testSearchResultCount() + throws Exception + { + System.out.println("searchResultCount"); + Context context = null; + String query = ""; + GroupServiceImpl instance = new GroupServiceImpl(); + int expResult = 0; + int result = instance.searchResultCount(context, query); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of delete method applied to a 'permanent' Group. + */ + @Test(expected = SQLException.class) + public void testDelete_permanent() + throws Exception + { + System.out.println("delete on a 'permanent' Group"); + GroupService groupService = EPersonServiceFactory.getInstance().getGroupService(); + Group group = groupService.findByName(context, Group.ANONYMOUS); + groupService.delete(context, group); + } + + /** + * Test of getSupportsTypeConstant method, of class GroupServiceImpl. + */ +/* + @Test + public void testGetSupportsTypeConstant() + { + System.out.println("getSupportsTypeConstant"); + GroupServiceImpl instance = new GroupServiceImpl(); + int expResult = 0; + int result = instance.getSupportsTypeConstant(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of isEmpty method, of class GroupServiceImpl. + */ +/* + @Test + public void testIsEmpty() + { + System.out.println("isEmpty"); + Group group = null; + GroupServiceImpl instance = new GroupServiceImpl(); + boolean expResult = false; + boolean result = instance.isEmpty(group); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of initDefaultGroupNames method, of class GroupServiceImpl. + */ +/* + @Test + public void testInitDefaultGroupNames() + throws Exception + { + System.out.println("initDefaultGroupNames"); + Context context = null; + GroupServiceImpl instance = new GroupServiceImpl(); + instance.initDefaultGroupNames(context); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of getEmptyGroups method, of class GroupServiceImpl. + */ +/* + @Test + public void testGetEmptyGroups() + throws Exception + { + System.out.println("getEmptyGroups"); + Context context = null; + GroupServiceImpl instance = new GroupServiceImpl(); + List expResult = null; + List result = instance.getEmptyGroups(context); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of update method, of class GroupServiceImpl. + */ +/* + @Test + public void testUpdate() + throws Exception + { + System.out.println("update"); + Context context = null; + Group group = null; + GroupServiceImpl instance = new GroupServiceImpl(); + instance.update(context, group); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of epersonInGroup method, of class GroupServiceImpl. + */ +/* + @Test + public void testEpersonInGroup() + throws Exception + { + System.out.println("epersonInGroup"); + Context c = null; + Group group = null; + EPerson e = null; + GroupServiceImpl instance = new GroupServiceImpl(); + boolean expResult = false; + boolean result = instance.epersonInGroup(c, group, e); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of rethinkGroupCache method, of class GroupServiceImpl. + */ +/* + @Test + public void testRethinkGroupCache() + throws Exception + { + System.out.println("rethinkGroupCache"); + Context context = null; + boolean flushQueries = false; + GroupServiceImpl instance = new GroupServiceImpl(); + instance.rethinkGroupCache(context, flushQueries); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of getParentObject method, of class GroupServiceImpl. + */ +/* + @Test + public void testGetParentObject() + throws Exception + { + System.out.println("getParentObject"); + Context context = null; + Group group = null; + GroupServiceImpl instance = new GroupServiceImpl(); + DSpaceObject expResult = null; + DSpaceObject result = instance.getParentObject(context, group); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of updateLastModified method, of class GroupServiceImpl. + */ +/* + @Test + public void testUpdateLastModified() + { + System.out.println("updateLastModified"); + Context context = null; + Group dso = null; + GroupServiceImpl instance = new GroupServiceImpl(); + instance.updateLastModified(context, dso); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of getChildren method, of class GroupServiceImpl. + */ +/* + @Test + public void testGetChildren() + { + System.out.println("getChildren"); + Map> parents = null; + UUID parent = null; + GroupServiceImpl instance = new GroupServiceImpl(); + Set expResult = null; + Set result = instance.getChildren(parents, parent); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of findByIdOrLegacyId method, of class GroupServiceImpl. + */ +/* + @Test + public void testFindByIdOrLegacyId() + throws Exception + { + System.out.println("findByIdOrLegacyId"); + Context context = null; + String id = ""; + GroupServiceImpl instance = new GroupServiceImpl(); + Group expResult = null; + Group result = instance.findByIdOrLegacyId(context, id); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of findByLegacyId method, of class GroupServiceImpl. + */ +/* + @Test + public void testFindByLegacyId() + throws Exception + { + System.out.println("findByLegacyId"); + Context context = null; + int id = 0; + GroupServiceImpl instance = new GroupServiceImpl(); + Group expResult = null; + Group result = instance.findByLegacyId(context, id); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ + + /** + * Test of countTotal method, of class GroupServiceImpl. + */ +/* + @Test + public void testCountTotal() + throws Exception + { + System.out.println("countTotal"); + Context context = null; + GroupServiceImpl instance = new GroupServiceImpl(); + int expResult = 0; + int result = instance.countTotal(context); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +*/ +} diff --git a/dspace-api/src/test/java/org/dspace/eperson/GroupTest.java b/dspace-api/src/test/java/org/dspace/eperson/GroupTest.java index 25663645c4d2..7c870cb4e5b7 100644 --- a/dspace-api/src/test/java/org/dspace/eperson/GroupTest.java +++ b/dspace-api/src/test/java/org/dspace/eperson/GroupTest.java @@ -190,8 +190,8 @@ public void findAllNameSort() throws SQLException { // Add all group names to two arraylists (arraylists are unsorted) // NOTE: we use lists here because we don't want duplicate names removed - List names = new ArrayList(); - List sortedNames = new ArrayList(); + List names = new ArrayList<>(); + List sortedNames = new ArrayList<>(); for (Group group : groups) { names.add(group.getName()); sortedNames.add(group.getName()); @@ -373,6 +373,28 @@ public void isMemberContextGroupId() throws SQLException, AuthorizeException, EP } } + @Test + public void isPermanent() + throws SQLException + { + Group anonymousGroup = groupService.findByName(context, Group.ANONYMOUS); + assertTrue("Anonymous group should be 'permanent'", anonymousGroup.isPermanent()); + assertFalse("topGroup should *not* be 'permanent'", topGroup.isPermanent()); + } + + @Test + public void setPermanent() + throws SQLException, AuthorizeException, IOException + { + Group permaGroup = new Group(); + permaGroup.setPermanent(true); + assertTrue("setPermanent(true) should be reflected in the group's state", + permaGroup.isPermanent()); + permaGroup.setPermanent(false); + assertFalse("setPermanent(false) should be reflected in the group's state", + permaGroup.isPermanent()); + } + @Test public void removeMemberEPerson() throws SQLException, AuthorizeException, EPersonDeletionException, IOException { EPerson ePerson = null; @@ -429,7 +451,7 @@ public void allMemberGroups() throws SQLException, AuthorizeException, EPersonDe @Test public void allMembers() throws SQLException, AuthorizeException, EPersonDeletionException, IOException { - List allEPeopleAdded = new ArrayList(); + List allEPeopleAdded = new ArrayList<>(); try { context.turnOffAuthorisationSystem(); allEPeopleAdded.add(createEPersonAndAddToGroup("allMemberGroups1@dspace.org", topGroup)); diff --git a/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/admin/CollectionWizardServlet.java b/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/admin/CollectionWizardServlet.java index 0ba644297310..387a05b520dd 100644 --- a/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/admin/CollectionWizardServlet.java +++ b/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/admin/CollectionWizardServlet.java @@ -400,9 +400,8 @@ private void processPermissions(Context context, g = groupService.create(context); // Name it according to our conventions - g - .setName(context, "COLLECTION_" + collection.getID() - + "_DEFAULT_ITEM_READ"); + groupService.setName(context, g, + "COLLECTION_" + collection.getID() + "_DEFAULT_ITEM_READ"); // Give it the needed permission authorizeService.addPolicy(context, collection, diff --git a/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/admin/GroupEditServlet.java b/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/admin/GroupEditServlet.java index b4411de44d7a..b995d09c4d38 100644 --- a/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/admin/GroupEditServlet.java +++ b/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/admin/GroupEditServlet.java @@ -97,7 +97,7 @@ else if (submit_group_update) if (!newName.equals(group.getName())) { - group.setName(c, newName); + groupService.setName(c, group, newName); groupService.update(c, group); } @@ -257,7 +257,7 @@ else if (submit_cancel_delete) { group = groupService.create(c); - group.setName(c, "new group" + group.getID()); + groupService.setName(c, group, "new group" + group.getID()); groupService.update(c, group); request.setAttribute("group", group); diff --git a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/FlowContainerUtils.java b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/FlowContainerUtils.java index f6973c1afecd..850857d1de25 100644 --- a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/FlowContainerUtils.java +++ b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/FlowContainerUtils.java @@ -604,7 +604,7 @@ public static UUID createCollectionDefaultReadGroup(Context context, UUID collec } Group role = groupService.create(context); - role.setName(context, "COLLECTION_"+collection.getID().toString() +"_DEFAULT_READ"); + groupService.setName(context, role, "COLLECTION_"+collection.getID().toString() +"_DEFAULT_READ"); // Remove existing privileges from the anonymous group. authorizeService.removePoliciesActionFilter(context, collection, Constants.DEFAULT_ITEM_READ); diff --git a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/FlowGroupUtils.java b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/FlowGroupUtils.java index 36f412095b46..30ba0086edab 100644 --- a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/FlowGroupUtils.java +++ b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/administrative/FlowGroupUtils.java @@ -217,7 +217,7 @@ public static FlowResult processSaveGroup(Context context, UUID groupID, String { // All good, create the new group. group = groupService.create(context); - group.setName(context, newName); + groupService.setName(context, group, newName); } else { @@ -245,7 +245,7 @@ public static FlowResult processSaveGroup(Context context, UUID groupID, String if (potentialDuplicate == null) { // All good, update the name - group.setName(context, newName); + groupService.setName(context, group, newName); } else {