[CST-5294] FIxed NBEventRestRepositoryIT test

This commit is contained in:
Luca Giamminonni
2022-02-16 15:48:28 +01:00
parent 75d9d6747e
commit 2340a44e96
3 changed files with 85 additions and 2 deletions

View File

@@ -1017,6 +1017,58 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
return resp;
}
@Override
public Collection retrieveCollectionByEntityType(Context context, Item item, String entityType)
throws SQLException {
Collection ownCollection = item.getOwningCollection();
return retrieveCollectionByEntityType(context, ownCollection.getCommunities(), entityType);
}
private Collection retrieveCollectionByEntityType(Context context, List<Community> communities, String entityType) {
for (Community community : communities) {
Collection collection = retrieveCollectionByCommunityAndEntityType(context, community, entityType);
if (collection != null) {
return collection;
}
}
for (Community community : communities) {
List<Community> parentCommunities = community.getParentCommunities();
Collection collection = retrieveCollectionByEntityType(context, parentCommunities, entityType);
if (collection != null) {
return collection;
}
}
return retrieveCollectionByCommunityAndEntityType(context, null, entityType);
}
@Override
public Collection retrieveCollectionByCommunityAndEntityType(Context context, Community community,
String entityType) {
context.turnOffAuthorisationSystem();
List<Collection> collections;
try {
collections = findCollectionsWithSubmit(null, context, community, entityType, 0, 1);
} catch (SQLException | SearchServiceException e) {
throw new RuntimeException(e);
}
context.restoreAuthSystemState();
if (collections != null && collections.size() > 0) {
return collections.get(0);
}
if (community != null) {
for (Community subCommunity : community.getSubcommunities()) {
Collection collection = retrieveCollectionByCommunityAndEntityType(context, subCommunity, entityType);
if (collection != null) {
return collection;
}
}
}
return null;
}
@Override
public List<Collection> findCollectionsWithSubmit(String q, Context context, Community community, String entityType,
int offset, int limit) throws SQLException, SearchServiceException {