mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-14 21:43:11 +00:00
97183 ItemService: added methods to search the index for items for which the current user has editing rights
This commit is contained in:
@@ -51,8 +51,14 @@ import org.dspace.content.virtual.VirtualMetadataPopulator;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.LogHelper;
|
||||
import org.dspace.discovery.DiscoverQuery;
|
||||
import org.dspace.discovery.DiscoverResult;
|
||||
import org.dspace.discovery.SearchService;
|
||||
import org.dspace.discovery.SearchServiceException;
|
||||
import org.dspace.discovery.indexobject.IndexableItem;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.dspace.eperson.Group;
|
||||
import org.dspace.eperson.service.GroupService;
|
||||
import org.dspace.event.Event;
|
||||
import org.dspace.harvest.HarvestedItem;
|
||||
import org.dspace.harvest.service.HarvestedItemService;
|
||||
@@ -93,6 +99,8 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
||||
@Autowired(required = true)
|
||||
protected CommunityService communityService;
|
||||
@Autowired(required = true)
|
||||
protected GroupService groupService;
|
||||
@Autowired(required = true)
|
||||
protected AuthorizeService authorizeService;
|
||||
@Autowired(required = true)
|
||||
protected BundleService bundleService;
|
||||
@@ -105,6 +113,8 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
||||
@Autowired(required = true)
|
||||
protected InstallItemService installItemService;
|
||||
@Autowired(required = true)
|
||||
protected SearchService searchService;
|
||||
@Autowired(required = true)
|
||||
protected ResourcePolicyService resourcePolicyService;
|
||||
@Autowired(required = true)
|
||||
protected CollectionService collectionService;
|
||||
@@ -1065,6 +1075,51 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
||||
return collectionService.canEditBoolean(context, item.getOwningCollection(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all Indexed Items where the current user has submit rights. If the user is an Admin,
|
||||
* this is all Indexed Items. Otherwise, it includes those Items where
|
||||
* an indexed "submit" policy lists either the eperson or one of the eperson's groups
|
||||
*
|
||||
* @param context DSpace context
|
||||
* @param discoverQuery
|
||||
* @return discovery search result objects
|
||||
* @throws SQLException if something goes wrong
|
||||
* @throws SearchServiceException if search error
|
||||
*/
|
||||
private DiscoverResult retrieveItemsWithEdit(Context context, DiscoverQuery discoverQuery)
|
||||
throws SQLException, SearchServiceException {
|
||||
EPerson currentUser = context.getCurrentUser();
|
||||
if (!authorizeService.isAdmin(context)) {
|
||||
String userId = currentUser != null ? "e" + currentUser.getID().toString() : "e";
|
||||
Stream<String> groupIds = groupService.allMemberGroupsSet(context, currentUser).stream()
|
||||
.map(group -> "g" + group.getID());
|
||||
String query = Stream.concat(Stream.of(userId), groupIds)
|
||||
.collect(Collectors.joining(" OR ", "edit:(", ")"));
|
||||
discoverQuery.addFilterQueries(query);
|
||||
}
|
||||
return searchService.search(context, discoverQuery);
|
||||
}
|
||||
|
||||
public List<Item> findItemsWithEdit(Context context, int offset, int limit)
|
||||
throws SQLException, SearchServiceException {
|
||||
DiscoverQuery discoverQuery = new DiscoverQuery();
|
||||
discoverQuery.setDSpaceObjectFilter(IndexableItem.TYPE);
|
||||
discoverQuery.setStart(offset);
|
||||
discoverQuery.setMaxResults(limit);
|
||||
DiscoverResult resp = retrieveItemsWithEdit(context, discoverQuery);
|
||||
return resp.getIndexableObjects().stream()
|
||||
.map(solrItems -> ((IndexableItem) solrItems).getIndexedObject())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public int countItemsWithEdit(Context context) throws SQLException, SearchServiceException {
|
||||
DiscoverQuery discoverQuery = new DiscoverQuery();
|
||||
discoverQuery.setMaxResults(0);
|
||||
discoverQuery.setDSpaceObjectFilter(IndexableItem.TYPE);
|
||||
DiscoverResult resp = retrieveItemsWithEdit(context, discoverQuery);
|
||||
return (int) resp.getTotalSearchResults();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the item is an inprogress submission
|
||||
*
|
||||
|
Reference in New Issue
Block a user