|
25 | 25 | import java.time.LocalDate; |
26 | 26 | import java.time.YearMonth; |
27 | 27 | import java.time.ZoneOffset; |
| 28 | +import java.util.Collections; |
28 | 29 | import java.util.Date; |
29 | 30 | import java.util.Iterator; |
30 | 31 | import java.util.List; |
|
35 | 36 |
|
36 | 37 | import org.apache.commons.io.file.PathUtils; |
37 | 38 | import org.dspace.AbstractIntegrationTestWithDatabase; |
| 39 | +import org.dspace.app.itemimport.factory.ItemImportServiceFactory; |
38 | 40 | import org.dspace.authorize.ResourcePolicy; |
39 | 41 | import org.dspace.authorize.factory.AuthorizeServiceFactory; |
40 | 42 | import org.dspace.authorize.service.AuthorizeService; |
|
50 | 52 | import org.dspace.content.factory.ContentServiceFactory; |
51 | 53 | import org.dspace.content.service.ItemService; |
52 | 54 | import org.dspace.content.service.MetadataSchemaService; |
| 55 | +import org.dspace.content.service.WorkspaceItemService; |
53 | 56 | import org.dspace.core.Constants; |
54 | 57 | import org.dspace.eperson.EPerson; |
55 | 58 | import org.dspace.eperson.Group; |
@@ -90,6 +93,8 @@ public class EmbargoImportIT extends AbstractIntegrationTestWithDatabase { |
90 | 93 | private static final String EMBARGO_POLICY_NAME = "embargo"; |
91 | 94 |
|
92 | 95 | private ItemService itemService = ContentServiceFactory.getInstance().getItemService(); |
| 96 | + private WorkspaceItemService workspaceItemService = |
| 97 | + ContentServiceFactory.getInstance().getWorkspaceItemService(); |
93 | 98 | private ResourcePolicyService resourcePolicyService = |
94 | 99 | AuthorizeServiceFactory.getInstance().getResourcePolicyService(); |
95 | 100 | private AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService(); |
@@ -606,6 +611,37 @@ public void testBlankEmbargoEndIsRefused() throws Exception { |
606 | 611 | assertBrokenEmbargoPackageIsRefused("", "an empty dc.date.embargoend"); |
607 | 612 | } |
608 | 613 |
|
| 614 | + /** |
| 615 | + * Verifies that a refused package leaves no workspace item behind. The command line path aborts its |
| 616 | + * context, but the batch import path completes its own in a finally block, so a half built submission |
| 617 | + * left here would be committed as an orphan submission with its bitstreams. |
| 618 | + * |
| 619 | + * <p>{@code addItem} is driven directly because that is the unit that has to clean up after itself; going |
| 620 | + * through the script would only exercise the caller that aborts anyway.</p> |
| 621 | + */ |
| 622 | + @Test |
| 623 | + public void testRefusedPackageLeavesNoWorkspaceItem() throws Exception { |
| 624 | + Path itemDir = safPackage("embargoedAccess", "not-a-date", "TEST CONTENT ORPHAN"); |
| 625 | + ItemImportServiceImpl importService = |
| 626 | + (ItemImportServiceImpl) ItemImportServiceFactory.getInstance().getItemImportService(); |
| 627 | + importService.setTest(false); |
| 628 | + |
| 629 | + context.turnOffAuthorisationSystem(); |
| 630 | + try { |
| 631 | + importService.addItem(context, Collections.singletonList(collection), |
| 632 | + itemDir.getParent().toString(), itemDir.getFileName().toString(), null, false); |
| 633 | + fail("an unparseable dc.date.embargoend has to be reported instead of importing the package"); |
| 634 | + } catch (EmbargoMetadataException expected) { |
| 635 | + // the failure the operator is given |
| 636 | + } finally { |
| 637 | + context.restoreAuthSystemState(); |
| 638 | + } |
| 639 | + |
| 640 | + assertTrue("the refused package must leave no workspace item behind, the batch import path would" |
| 641 | + + " commit it as an orphan submission", |
| 642 | + workspaceItemService.findByCollection(context, collection).isEmpty()); |
| 643 | + } |
| 644 | + |
609 | 645 | /** |
610 | 646 | * Verifies that a bare year keeps the day {@code DCDate} mapped it to, 1 January; reading it as |
611 | 647 | * 31 December would extend embargoes that repositories already live with. |
|
0 commit comments