Skip to content

Commit

Permalink
predefined uuid in importRecord add
Browse files Browse the repository at this point in the history
  • Loading branch information
floriangantner committed Aug 21, 2023
1 parent 970daf3 commit 2c8b069
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.util.ItemUtils;
import org.dspace.util.UUIDUtils;
import org.dspace.utils.DSpace;
import org.dspace.workflow.WorkflowException;
import org.dspace.xmlworkflow.WorkflowConfigurationException;
Expand Down Expand Up @@ -549,15 +548,14 @@ private UUID addItem(Context c, Collection[] mycollections, ImpRecord impRecord,
Item myitem = null;
WorkspaceItem wsi = null;
c.setCurrentUser(myEPerson);
UUID predefineduuid = UUIDUtils.fromString(handle);
if (Objects.nonNull(predefineduuid)) {
wsi = workspaceItemService.create(c, mycollections[0], predefineduuid,false);
if (Objects.nonNull(impRecord.getUUID())) {
wsi = workspaceItemService.create(c, mycollections[0], impRecord.getUUID(),false);
} else {
wsi = workspaceItemService.create(c, mycollections[0], false);
}
myitem = wsi.getItem();

if (Objects.isNull(predefineduuid) && StringUtils.isNotEmpty(handle)) {
if (StringUtils.isNotEmpty(impRecord.getHandle())) {
identifierService.register(c, myitem, handle);
}

Expand Down
12 changes: 12 additions & 0 deletions dspace-api/src/main/java/org/dspace/batch/ImpRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public class ImpRecord {
@Column(name = "handle", length = 64)
private String handle;

@Id
@Column(name = "uuid", unique = true)
protected java.util.UUID uuid;

@Column(name = "imp_sourceref", length = 256)
private String impSourceref;

Expand Down Expand Up @@ -129,6 +133,14 @@ public String getHandle() {
return handle;
}

public UUID getUUID() {
return uuid;
}

public void setUUID(UUID uuid) {
this.uuid = uuid;
}

public void setHandle(String handle) {
this.handle = handle;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--
-- The contents of this file are subject to the license and copyright
-- detailed in the LICENSE and NOTICE files at the root of the source
-- tree and available online at
--
-- http://www.dspace.org/license/
--

-----------------------------------------------------------------------------------
-- Alter table imp_record with additional uuid for predefined uuid to set
-----------------------------------------------------------------------------------

ALTER TABLE imp_record ADD COLUMN if NOT EXISTS uuid UUID;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--
-- The contents of this file are subject to the license and copyright
-- detailed in the LICENSE and NOTICE files at the root of the source
-- tree and available online at
--
-- http://www.dspace.org/license/
--

-----------------------------------------------------------------------------------
-- Alter table imp_record with additional uuid for predefined uuid to set
-----------------------------------------------------------------------------------

ALTER TABLE imp_record ADD COLUMN if NOT EXISTS uuid UUID;
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import org.dspace.eperson.service.GroupService;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.util.UUIDUtils;
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
import org.dspace.xmlworkflow.storedcomponents.service.XmlWorkflowItemService;
Expand Down Expand Up @@ -207,6 +208,47 @@ public void createNewWorkspaceItem() throws IOException {
}
}

@Test
public void createNewWorkspaceItemWithUUID() throws IOException {
try {
// create imp_record records
int impRecordKey = 1;
UUID predefineduuid = UUIDUtils.fromString("0525aa6d-9eeb-4f05-96cc-4bb8c3cb6785");
ImpRecord impRecord = createImpRecordWithPredefinedUUID(context, impRecordKey,
ImpRecordService.SEND_BACK_TO_WORKSPACE_STATUS,
ImpRecordService.INSERT_OR_UPDATE_OPERATION, admin, collection, predefineduuid);

// create imp_metadatavalue records
createImpMetadatavalue(context, impRecord, MetadataSchemaEnum.DC.getName(), "title",
null, null, "Sample Item");

// Create a new item
String argv[] = new String[] { "-E", admin.getEmail() };

ItemImportMainOA.main(argv);

List<WorkspaceItem> wis = workspaceItemService.findAll(context);

WorkspaceItem wi = wis.get(0);
Item item = wi.getItem();

List<MetadataValue> metadata = item.getMetadata();
// one metadata is explicit the other is the cris.sourceid
assertEquals("Only two metadata found", 2, metadata.size());

String defLanguage = configurationService.getProperty("default.language");
metadata = itemService.getMetadata(item, MetadataSchemaEnum.DC.getName(), "title", null, defLanguage);
assertEquals("Only one metadata is assigned to the item", 1, metadata.size());
assertEquals("Is the new metadata value the right one?", metadata.get(0).getValue(), "Sample Item");
assertEquals("Is the predefined uuid assigned correctly?", UUIDUtils.toString(item.getID()),
UUIDUtils.toString(predefineduuid));
} catch (SQLException ex) {
throw new RuntimeException(ex);
} finally {
context.restoreAuthSystemState();
}
}

/***
* Remove an item.
*
Expand Down Expand Up @@ -1210,6 +1252,24 @@ private ImpRecord createImpRecord(Context context, int impRecordKey, Character s
return impRecordService.create(context, impRecord);
}

private ImpRecord createImpRecordWithPredefinedUUID(Context context, int impRecordKey, Character status,
String operation, EPerson eperson, Collection collection, UUID predefined)
throws SQLException {
// create imp_record records
String sourceRecordId = "" + impRecordKey;
ImpRecord impRecord = new ImpRecord();
impRecord.setImpId(impSeq++);
impRecordService.setImpCollection(impRecord, collection);
impRecordService.setImpEperson(impRecord, eperson);
impRecord.setImpRecordId(sourceRecordId);
impRecord.setImpSourceref(SOURCE_REF);
impRecord.setUUID(predefined);
impRecordService.setStatus(impRecord, status);
impRecordService.setOperation(impRecord, operation);

return impRecordService.create(context, impRecord);
}

/***
* Create a Metadata of ImpRecord
*
Expand Down

0 comments on commit 2c8b069

Please sign in to comment.