From e343e987408a2080faf6dc752902e2acf657edb1 Mon Sep 17 00:00:00 2001 From: milanmajchrak <90026355+milanmajchrak@users.noreply.github.com> Date: Mon, 20 May 2024 15:01:09 +0200 Subject: [PATCH] Fixed the importing of the Item - if the Item has pre-registered PID it should be unbound (#659) --- .../repository/ClarinItemImportController.java | 13 +++++++++++-- .../app/rest/ClarinItemImportControllerIT.java | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinItemImportController.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinItemImportController.java index d37b54ab708c..02ce099dfe97 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinItemImportController.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinItemImportController.java @@ -53,6 +53,7 @@ import org.dspace.identifier.IdentifierException; import org.dspace.identifier.service.IdentifierService; import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; import org.dspace.util.UUIDUtils; import org.dspace.workflow.WorkflowException; import org.dspace.xmlworkflow.service.XmlWorkflowService; @@ -317,11 +318,19 @@ public ItemRest importItem(HttpServletRequest request) throws SQLException, Auth context.setCurrentUser(eperson); context.turnOffAuthorisationSystem(); WorkspaceItem workspaceItem = workspaceItemService.create(context, collection, false); + // created item + Item item = workspaceItem.getItem(); + // if the created item has pre-registered PID and the importing Item has handle which must be imported, the + // pre-registered PID must be unbound from the created Item, otherwise the Item will have two handles. + if (DSpaceServicesFactory.getInstance().getConfigurationService() + .getBooleanProperty("identifiers.submission.register", false) && + StringUtils.isNotEmpty(itemRest.getHandle())) { + handleService.unbindHandle(context, item); + } + context.restoreAuthSystemState(); context.setCurrentUser(currUser); - //created item - Item item = workspaceItem.getItem(); item.setOwningCollection(collection); //the method set withdraw to true and isArchived to false if (itemRest.getWithdrawn()) { diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinItemImportControllerIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinItemImportControllerIT.java index b561433b48c5..d11ddaa5a260 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinItemImportControllerIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinItemImportControllerIT.java @@ -41,6 +41,8 @@ import org.dspace.content.service.ItemService; import org.dspace.content.service.WorkspaceItemService; import org.dspace.eperson.EPerson; +import org.dspace.handle.Handle; +import org.dspace.handle.service.HandleService; import org.dspace.services.ConfigurationService; import org.dspace.workflow.WorkflowItem; import org.dspace.workflow.WorkflowItemService; @@ -63,6 +65,8 @@ public class ClarinItemImportControllerIT extends AbstractControllerIntegrationT private ItemService itemService; @Autowired private ConfigurationService configurationService; + @Autowired + private HandleService handleService; private Collection col; private EPerson submitter; @@ -227,15 +231,19 @@ public void importWithdrawnItemTest() throws Exception { @Test public void importArchivedItemTest() throws Exception { + boolean preRegisterPID = configurationService.getBooleanProperty("identifiers.submission.register", false); + // enable submission's PID to be pre-registered + configurationService.setProperty("identifiers.submission.register", true); String PROVENANCE_VALUE = "first provenance metadata value"; String DATE_VALUE = "2014-07-30T21:26:36Z"; - String IDENTIFIER_VALUE = "some handle url"; + String IDENTIFIER_VALUE = configurationService.getProperty("handle.canonical.prefix") + "/123456789/99985"; context.turnOffAuthorisationSystem(); ObjectNode node = jsonNodeFactory.objectNode(); node.set("withdrawn", jsonNodeFactory.textNode("false")); node.set("inArchive", jsonNodeFactory.textNode("true")); node.set("discoverable", jsonNodeFactory.textNode("false")); + node.set("handle", jsonNodeFactory.textNode(IDENTIFIER_VALUE)); // Metadata which should be kept after installing the new Item. ObjectNode metadataNode = jsonNodeFactory.objectNode(); @@ -301,6 +309,10 @@ public void importArchivedItemTest() throws Exception { assertEquals(item.getSubmitter().getID(), submitter.getID()); assertEquals(item.getOwningCollection().getID(), col.getID()); + // When the Item has pre-registered PID - it could have two handles + List createdHandles = item.getHandles(); + assertEquals(createdHandles.size(), 1); + // check `dc.description.provenance` - there should be just one value List provenanceValues = itemService.getMetadata(item, "dc", "description", "provenance", "en_US"); @@ -329,6 +341,7 @@ public void importArchivedItemTest() throws Exception { context.turnOffAuthorisationSystem(); ItemBuilder.deleteItem(uuid); context.restoreAuthSystemState(); + configurationService.setProperty("identifiers.submission.register", preRegisterPID); } // Fix of this issue: https://github.com/dataquest-dev/DSpace/issues/409