Skip to content

Commit

Permalink
Fixed the importing of the Item - if the Item has pre-registered PID …
Browse files Browse the repository at this point in the history
…it should be unbound (#659)
  • Loading branch information
milanmajchrak authored May 20, 2024
1 parent 6c67510 commit e343e98
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<Handle> createdHandles = item.getHandles();
assertEquals(createdHandles.size(), 1);

// check `dc.description.provenance` - there should be just one value
List<MetadataValue> provenanceValues =
itemService.getMetadata(item, "dc", "description", "provenance", "en_US");
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e343e98

Please sign in to comment.