99200: Delete items after copies have been requested fix

This commit is contained in:
Jens Vannerum
2023-02-09 11:19:47 +01:00
parent e7f217210c
commit c2845e95aa
6 changed files with 69 additions and 0 deletions

View File

@@ -27,6 +27,8 @@ import java.util.stream.Stream;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.dspace.app.requestitem.RequestItem;
import org.dspace.app.requestitem.service.RequestItemService;
import org.dspace.app.util.AuthorizeUtil;
import org.dspace.authorize.AuthorizeConfiguration;
import org.dspace.authorize.AuthorizeException;
@@ -158,6 +160,8 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
@Autowired(required = true)
private ResearcherProfileService researcherProfileService;
@Autowired(required = true)
private RequestItemService requestItemService;
protected ItemServiceImpl() {
super();
@@ -780,6 +784,8 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
// remove version attached to the item
removeVersion(context, item);
removeRequest(context, item);
removeOrcidSynchronizationStuff(context, item);
// Also delete the item if it appears in a harvested collection.
@@ -802,6 +808,15 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
itemDAO.delete(context, item);
}
protected void removeRequest(Context context, Item item) throws SQLException {
Iterator<RequestItem> requestItems = requestItemService.findByItem(context, item);
while (requestItems.hasNext()) {
RequestItem requestItem = requestItems.next();
log.info("Remove Request Item: " + requestItem.getID());
requestItemService.delete(context, requestItem);
}
}
@Override
public void removeAllBundles(Context context, Item item) throws AuthorizeException, SQLException, IOException {
Iterator<Bundle> bundles = item.getBundles().iterator();