mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-13 04:53:16 +00:00
99200: Delete items after copies have been requested fix
This commit is contained in:
@@ -9,6 +9,7 @@ package org.dspace.app.requestitem;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@@ -90,6 +91,11 @@ public class RequestItemServiceImpl implements RequestItemService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<RequestItem> findByItem(Context context, Item item) throws SQLException {
|
||||||
|
return requestItemDAO.findByItem(context, item);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Context context, RequestItem requestItem) {
|
public void update(Context context, RequestItem requestItem) {
|
||||||
try {
|
try {
|
||||||
|
@@ -8,8 +8,10 @@
|
|||||||
package org.dspace.app.requestitem.dao;
|
package org.dspace.app.requestitem.dao;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.dspace.app.requestitem.RequestItem;
|
import org.dspace.app.requestitem.RequestItem;
|
||||||
|
import org.dspace.content.Item;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.core.GenericDAO;
|
import org.dspace.core.GenericDAO;
|
||||||
|
|
||||||
@@ -32,4 +34,6 @@ public interface RequestItemDAO extends GenericDAO<RequestItem> {
|
|||||||
* @throws SQLException passed through.
|
* @throws SQLException passed through.
|
||||||
*/
|
*/
|
||||||
public RequestItem findByToken(Context context, String token) throws SQLException;
|
public RequestItem findByToken(Context context, String token) throws SQLException;
|
||||||
|
|
||||||
|
public Iterator<RequestItem> findByItem(Context context, Item item) throws SQLException;
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,8 @@
|
|||||||
package org.dspace.app.requestitem.dao.impl;
|
package org.dspace.app.requestitem.dao.impl;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import javax.persistence.Query;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
@@ -15,6 +17,7 @@ import javax.persistence.criteria.Root;
|
|||||||
import org.dspace.app.requestitem.RequestItem;
|
import org.dspace.app.requestitem.RequestItem;
|
||||||
import org.dspace.app.requestitem.RequestItem_;
|
import org.dspace.app.requestitem.RequestItem_;
|
||||||
import org.dspace.app.requestitem.dao.RequestItemDAO;
|
import org.dspace.app.requestitem.dao.RequestItemDAO;
|
||||||
|
import org.dspace.content.Item;
|
||||||
import org.dspace.core.AbstractHibernateDAO;
|
import org.dspace.core.AbstractHibernateDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
|
|
||||||
@@ -39,4 +42,10 @@ public class RequestItemDAOImpl extends AbstractHibernateDAO<RequestItem> implem
|
|||||||
criteriaQuery.where(criteriaBuilder.equal(requestItemRoot.get(RequestItem_.token), token));
|
criteriaQuery.where(criteriaBuilder.equal(requestItemRoot.get(RequestItem_.token), token));
|
||||||
return uniqueResult(context, criteriaQuery, false, RequestItem.class);
|
return uniqueResult(context, criteriaQuery, false, RequestItem.class);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public Iterator<RequestItem> findByItem(Context context, Item item) throws SQLException {
|
||||||
|
Query query = createQuery(context, "FROM RequestItem WHERE item_id= :uuid");
|
||||||
|
query.setParameter("uuid", item.getID());
|
||||||
|
return iterate(query);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
package org.dspace.app.requestitem.service;
|
package org.dspace.app.requestitem.service;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.dspace.app.requestitem.RequestItem;
|
import org.dspace.app.requestitem.RequestItem;
|
||||||
@@ -62,6 +63,14 @@ public interface RequestItemService {
|
|||||||
*/
|
*/
|
||||||
public RequestItem findByToken(Context context, String token);
|
public RequestItem findByToken(Context context, String token);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a request based on the item.
|
||||||
|
* @param context current DSpace session.
|
||||||
|
* @param item the item to find requests for.
|
||||||
|
* @return the matching requests, or null if not found.
|
||||||
|
*/
|
||||||
|
public Iterator<RequestItem> findByItem(Context context, Item item) throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save updates to the record. Only accept_request, and decision_date are set-able.
|
* Save updates to the record. Only accept_request, and decision_date are set-able.
|
||||||
*
|
*
|
||||||
|
@@ -27,6 +27,8 @@ import java.util.stream.Stream;
|
|||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.logging.log4j.Logger;
|
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.app.util.AuthorizeUtil;
|
||||||
import org.dspace.authorize.AuthorizeConfiguration;
|
import org.dspace.authorize.AuthorizeConfiguration;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
@@ -158,6 +160,8 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
|||||||
|
|
||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
private ResearcherProfileService researcherProfileService;
|
private ResearcherProfileService researcherProfileService;
|
||||||
|
@Autowired(required = true)
|
||||||
|
private RequestItemService requestItemService;
|
||||||
|
|
||||||
protected ItemServiceImpl() {
|
protected ItemServiceImpl() {
|
||||||
super();
|
super();
|
||||||
@@ -780,6 +784,8 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
|||||||
// remove version attached to the item
|
// remove version attached to the item
|
||||||
removeVersion(context, item);
|
removeVersion(context, item);
|
||||||
|
|
||||||
|
removeRequest(context, item);
|
||||||
|
|
||||||
removeOrcidSynchronizationStuff(context, item);
|
removeOrcidSynchronizationStuff(context, item);
|
||||||
|
|
||||||
// Also delete the item if it appears in a harvested collection.
|
// 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);
|
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
|
@Override
|
||||||
public void removeAllBundles(Context context, Item item) throws AuthorizeException, SQLException, IOException {
|
public void removeAllBundles(Context context, Item item) throws AuthorizeException, SQLException, IOException {
|
||||||
Iterator<Bundle> bundles = item.getBundles().iterator();
|
Iterator<Bundle> bundles = item.getBundles().iterator();
|
||||||
|
@@ -10,8 +10,11 @@ package org.dspace.content.service;
|
|||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -19,8 +22,10 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.AbstractIntegrationTestWithDatabase;
|
import org.dspace.AbstractIntegrationTestWithDatabase;
|
||||||
|
import org.dspace.app.requestitem.RequestItem;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.authorize.ResourcePolicy;
|
import org.dspace.authorize.ResourcePolicy;
|
||||||
|
import org.dspace.builder.BitstreamBuilder;
|
||||||
import org.dspace.builder.CollectionBuilder;
|
import org.dspace.builder.CollectionBuilder;
|
||||||
import org.dspace.builder.CommunityBuilder;
|
import org.dspace.builder.CommunityBuilder;
|
||||||
import org.dspace.builder.EntityTypeBuilder;
|
import org.dspace.builder.EntityTypeBuilder;
|
||||||
@@ -28,7 +33,9 @@ import org.dspace.builder.GroupBuilder;
|
|||||||
import org.dspace.builder.ItemBuilder;
|
import org.dspace.builder.ItemBuilder;
|
||||||
import org.dspace.builder.RelationshipBuilder;
|
import org.dspace.builder.RelationshipBuilder;
|
||||||
import org.dspace.builder.RelationshipTypeBuilder;
|
import org.dspace.builder.RelationshipTypeBuilder;
|
||||||
|
import org.dspace.builder.RequestItemBuilder;
|
||||||
import org.dspace.builder.ResourcePolicyBuilder;
|
import org.dspace.builder.ResourcePolicyBuilder;
|
||||||
|
import org.dspace.content.Bitstream;
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
import org.dspace.content.Community;
|
import org.dspace.content.Community;
|
||||||
import org.dspace.content.EntityType;
|
import org.dspace.content.EntityType;
|
||||||
@@ -554,6 +561,25 @@ public class ItemServiceTest extends AbstractIntegrationTestWithDatabase {
|
|||||||
assertThat(result.size(), equalTo(1));
|
assertThat(result.size(), equalTo(1));
|
||||||
assertThat(count, equalTo(1));
|
assertThat(count, equalTo(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveItemThatHasRequests() throws Exception {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
Item item = ItemBuilder.createItem(context, collection1)
|
||||||
|
.withTitle("Test")
|
||||||
|
.build();
|
||||||
|
InputStream is = new ByteArrayInputStream(new byte[0]);
|
||||||
|
Bitstream bitstream = BitstreamBuilder.createBitstream(context, item, is)
|
||||||
|
.build();
|
||||||
|
RequestItem requestItem = RequestItemBuilder.createRequestItem(context, item, bitstream)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
itemService.delete(context, item);
|
||||||
|
context.dispatchEvents();
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
assertNull(itemService.find(context, item.getID()));
|
||||||
|
}
|
||||||
private void assertMetadataValue(String authorQualifier, String contributorElement, String dcSchema, String value,
|
private void assertMetadataValue(String authorQualifier, String contributorElement, String dcSchema, String value,
|
||||||
String authority, int place, MetadataValue metadataValue) {
|
String authority, int place, MetadataValue metadataValue) {
|
||||||
assertThat(metadataValue.getValue(), equalTo(value));
|
assertThat(metadataValue.getValue(), equalTo(value));
|
||||||
|
Reference in New Issue
Block a user