Skip to content

Commit

Permalink
import ead files: reduced memory consumption, faster import
Browse files Browse the repository at this point in the history
  • Loading branch information
rsehr committed Oct 1, 2024
1 parent 74e5a9b commit 991d9c7
Showing 1 changed file with 49 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -523,28 +523,34 @@ public void createNewDatabase() {
/*
* get root node from ead document
*/
public void parseEadFile(Document document) {
public void parseEadFile(Document document, Integer recordGroupId) {
Element eadElement = null;
Element collection = document.getRootElement();
if ("collection".equals(collection.getName())) {
eadElement = collection.getChild("ead", nameSpaceRead);
} else {
eadElement = collection;
}

rootElement = parseElement(0, 0, eadElement);
rootElement = parseElement(0, 0, eadElement, recordGroupId);
INodeType rootType = new NodeType("root", null, "fa fa-home", 0);
rootElement.setNodeType(rootType);
rootElement.setDisplayChildren(true);

getDuplicationConfiguration();
}

/*
* get root node from ead document
*/
public void parseEadFile(Document document) {
parseEadFile(document, null);
}

/**
* read the metadata for the current xml node. - create an {@link EadEntry} - execute the configured xpaths on the current node - add the metadata
* to one of the 7 levels - check if the node has sub nodes - call the method recursively for all sub nodes
*/
private IEadEntry parseElement(int order, int hierarchy, Element element) {
private IEadEntry parseElement(int order, int hierarchy, Element element, Integer recordGroupId) {
IEadEntry entry = new EadEntry(order, hierarchy);

for (IMetadataField emf : configuredFields) {
Expand Down Expand Up @@ -630,6 +636,30 @@ private IEadEntry parseElement(int order, int hierarchy, Element element) {
if (entry.getNodeType() == null) {
entry.setNodeType(configuredNodes.get(0));
}
// generate new id, if id is null
if (entry.getId() == null) {
entry.setId("id_" + UUID.randomUUID());
}

// generate new id, if id is null
if (entry.getId() == null) {
entry.setId("id_" + UUID.randomUUID());
}
entry.calculateFingerprint();

if (recordGroupId != null) {
// save current node
ArchiveManagementManager.saveNode(recordGroupId, entry);
// clear saved metadata to reduce memory usage
entry.getIdentityStatementAreaList().clear();
entry.getContextAreaList().clear();
entry.getContentAndStructureAreaAreaList().clear();
entry.getAccessAndUseAreaList().clear();
entry.getAlliedMaterialsAreaList().clear();
entry.getNotesAreaList().clear();
entry.getDescriptionControlAreaList().clear();
}

if (clist == null) {
clist = element.getChildren("c", nameSpaceRead);
}
Expand All @@ -638,18 +668,13 @@ private IEadEntry parseElement(int order, int hierarchy, Element element) {
int subHierarchy = hierarchy + 1;
for (Element c : clist) {

IEadEntry child = parseElement(subOrder, subHierarchy, c);
IEadEntry child = parseElement(subOrder, subHierarchy, c, recordGroupId);
entry.addSubEntry(child);
child.setParentNode(entry);
subOrder++;
}
}

// generate new id, if id is null
if (entry.getId() == null) {
entry.setId("id_" + UUID.randomUUID());
}
entry.calculateFingerprint();
return entry;
}

Expand Down Expand Up @@ -1139,27 +1164,23 @@ public void upload() {
String message = "plugin_administration_archive_notEadFile";
throw new FileNotFoundException(message);
}

parseEadFile(document);

// check, if uploaded file was used before
recordGroup = ArchiveManagementManager.getRecordGroupByTitle(uploadedFileName);
if (recordGroup == null) {
recordGroup = new RecordGroup();
recordGroup.setTitle(uploadedFileName);
} else {
// replace existing records
ArchiveManagementManager.deleteAllNodes(recordGroup.getId());
}
ArchiveManagementManager.saveRecordGroup(recordGroup);
parseEadFile(document, recordGroup.getId());
}
} catch (IOException e) {
log.error(e);
}
// check, if uploaded file was used before
recordGroup = ArchiveManagementManager.getRecordGroupByTitle(uploadedFileName);
if (recordGroup == null) {
recordGroup = new RecordGroup();
recordGroup.setTitle(uploadedFileName);
} else {
// replace existing records
ArchiveManagementManager.deleteAllNodes(recordGroup.getId());
}

// save nodes
ArchiveManagementManager.saveRecordGroup(recordGroup);
List<IEadEntry> nodes = rootElement.getAllNodes();
ArchiveManagementManager.saveNodes(recordGroup.getId(), nodes);
databaseName = recordGroup.getTitle();
displayMode = "";
// update existing process ids if the uploaded EAD file has an older version
Expand Down Expand Up @@ -2545,7 +2566,9 @@ public void updateGoobiIds() {
selected = rootElement;
}
List<String> lstNodesWithoutIds = removeInvalidProcessIds();

checkGoobiProcessesForArchiveRefs(lstNodesWithoutIds);

setSelectedEntry(selected);
}

Expand Down Expand Up @@ -2581,8 +2604,7 @@ private List<String> removeInvalidProcessIdsForChildren(IEadEntry currentEntry)
if (!currentEntry.isHasChildren() && goobiProcessTitle != null) {
try {
String strProcessTitle = currentEntry.getGoobiProcessTitle();
Process process = ProcessManager.getProcessByTitle(strProcessTitle);
if (process == null) {
if (ProcessManager.countProcessTitle(strProcessTitle, null) == 0) {
currentEntry.setGoobiProcessTitle(null);
lstNodesWithoutIds.add(currentEntry.getId());
ArchiveManagementManager.saveNode(recordGroup.getId(), currentEntry);
Expand Down

0 comments on commit 991d9c7

Please sign in to comment.