Skip to content

Commit 277b499

Browse files
committed
1 parent 0de9680 commit 277b499

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

Diff for: dspace-api/src/main/java/org/dspace/content/CollectionServiceImpl.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -920,8 +920,7 @@ public Group createDefaultReadGroup(Context context, Collection collection, Stri
920920
int defaultRead)
921921
throws SQLException, AuthorizeException {
922922
Group role = groupService.create(context);
923-
groupService.setName(role, "COLLECTION_" + collection.getID().toString() + "_" + typeOfGroupString +
924-
"_DEFAULT_READ");
923+
groupService.setName(role, getDefaultReadGroupName(collection, typeOfGroupString));
925924

926925
// Remove existing privileges from the anonymous group.
927926
authorizeService.removePoliciesActionFilter(context, collection, defaultRead);
@@ -932,6 +931,12 @@ public Group createDefaultReadGroup(Context context, Collection collection, Stri
932931
return role;
933932
}
934933

934+
@Override
935+
public String getDefaultReadGroupName(Collection collection, String typeOfGroupString) {
936+
return "COLLECTION_" + collection.getID().toString() + "_" + typeOfGroupString +
937+
"_DEFAULT_READ";
938+
}
939+
935940
@Override
936941
public List<Collection> findCollectionsWithSubmit(String q, Context context, Community community,
937942
int offset, int limit) throws SQLException, SearchServiceException {

Diff for: dspace-api/src/main/java/org/dspace/content/service/CollectionService.java

+10
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,16 @@ public List<Collection> findAuthorized(Context context, Community community, int
360360
Group createDefaultReadGroup(Context context, Collection collection, String typeOfGroupString, int defaultRead)
361361
throws SQLException, AuthorizeException;
362362

363+
/**
364+
* This method will return the name to give to the group created by the
365+
* {@link #createDefaultReadGroup(Context, Collection, String, int)} method
366+
*
367+
* @param collection The DSpace collection to use in the name generation
368+
* @param typeOfGroupString The type of group to use in the name generation
369+
* @return the name to give to the group that hold default read for the collection
370+
*/
371+
String getDefaultReadGroupName(Collection collection, String typeOfGroupString);
372+
363373
/**
364374
* Returns Collections for which the current user has 'submit' privileges.
365375
* NOTE: for better performance, this method retrieves its results from an

Diff for: dspace-api/src/main/java/org/dspace/eperson/GroupServiceImpl.java

+16-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.List;
1616
import java.util.Map;
1717
import java.util.Objects;
18+
import java.util.Optional;
1819
import java.util.Set;
1920
import java.util.UUID;
2021

@@ -735,13 +736,24 @@ public DSpaceObject getParentObject(Context context, Group group) throws SQLExce
735736
groups.add(group);
736737
List<ResourcePolicy> policies = resourcePolicyService.find(context, null, groups,
737738
Constants.DEFAULT_ITEM_READ, Constants.COLLECTION);
738-
if (policies.size() > 0) {
739-
return policies.get(0).getdSpaceObject();
739+
740+
Optional<ResourcePolicy> defaultPolicy = policies.stream().filter(p -> StringUtils.equals(
741+
collectionService.getDefaultReadGroupName((Collection) p.getdSpaceObject(), "ITEM"),
742+
group.getName())).findFirst();
743+
744+
if (defaultPolicy.isPresent()) {
745+
return defaultPolicy.get().getdSpaceObject();
740746
}
741747
policies = resourcePolicyService.find(context, null, groups,
742748
Constants.DEFAULT_BITSTREAM_READ, Constants.COLLECTION);
743-
if (policies.size() > 0) {
744-
return policies.get(0).getdSpaceObject();
749+
750+
defaultPolicy = policies.stream()
751+
.filter(p -> StringUtils.equals(collectionService.getDefaultReadGroupName(
752+
(Collection) p.getdSpaceObject(), "BITSTREAM"), group.getName()))
753+
.findFirst();
754+
755+
if (defaultPolicy.isPresent()) {
756+
return defaultPolicy.get().getdSpaceObject();
745757
}
746758
}
747759
}

0 commit comments

Comments
 (0)