mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Adds check for whether source and target collections are the same when moving an item. (#8055)
This commit is contained in:
@@ -911,6 +911,12 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
||||
@Override
|
||||
public void move(Context context, Item item, Collection from, Collection to)
|
||||
throws SQLException, AuthorizeException, IOException {
|
||||
|
||||
// If the two collections are the same, do nothing.
|
||||
if (from.equals(to)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Use the normal move method, and default to not inherit permissions
|
||||
this.move(context, item, from, to, false);
|
||||
}
|
||||
|
@@ -19,6 +19,8 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.File;
|
||||
@@ -41,6 +43,7 @@ import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.BitstreamFormatService;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.content.service.MetadataFieldService;
|
||||
import org.dspace.content.service.MetadataSchemaService;
|
||||
import org.dspace.core.Constants;
|
||||
@@ -1410,6 +1413,27 @@ public class ItemTest extends AbstractDSpaceObjectTest {
|
||||
assertThat("testMove 1", it.getOwningCollection(), equalTo(to));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of move method, of class Item, where both Collections are the same.
|
||||
*/
|
||||
@Test
|
||||
public void testMoveSameCollection() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
while (it.getCollections().size() > 1) {
|
||||
it.removeCollection(it.getCollections().get(0));
|
||||
}
|
||||
|
||||
Collection collection = it.getCollections().get(0);
|
||||
it.setOwningCollection(collection);
|
||||
ItemService itemServiceSpy = spy(itemService);
|
||||
|
||||
itemService.move(context, it, collection, collection);
|
||||
context.restoreAuthSystemState();
|
||||
assertThat("testMoveSameCollection 0", it.getOwningCollection(), notNullValue());
|
||||
assertThat("testMoveSameCollection 1", it.getOwningCollection(), equalTo(collection));
|
||||
verify(itemServiceSpy, times(0)).delete(context, it);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of hasUploadedFiles method, of class Item.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user