Skip to content

Commit

Permalink
Merge pull request 'Release v24.12' (#15) from release_24.12 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominick Leppich committed Jan 13, 2025
2 parents 8b4a110 + 2f662ba commit 6a78219
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 119 deletions.
4 changes: 3 additions & 1 deletion module-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
<parent>
<groupId>io.goobi.workflow.plugin</groupId>
<artifactId>plugin-workflow-hu-importer</artifactId>
<version>24.09</version>
<version>24.12</version>
</parent>
<artifactId>plugin-workflow-hu-importer-base</artifactId>
<packaging>jar</packaging>
<dependencies>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import de.sub.goobi.persistence.managers.ProcessManager;
import de.sub.goobi.persistence.managers.ProjectManager;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import ugh.dl.ContentFile;
import ugh.dl.Corporate;
import ugh.dl.DigitalDocument;
Expand All @@ -47,6 +48,7 @@
import ugh.exceptions.WriteException;
import ugh.fileformats.mets.MetsMods;

@Slf4j
public class DocumentManager {
@Getter
private Process process;
Expand All @@ -59,7 +61,7 @@ public class DocumentManager {
private DocStruct logical;
private DocStruct physical;
private ImportSet importSet;
private int PageCount = 0;
private int pageCount = 0;
private DocStruct structure;
private VariableReplacer replacer;
@Getter
Expand Down Expand Up @@ -123,7 +125,7 @@ public DocumentManager(ProcessDescription processDescription, ImportSet importSe
ff.setDigitalDocument(dd);

// add the physical basics
DocStruct physical = dd.createDocStruct(this.prefs.getDocStrctTypeByName("BoundBook"));
physical = dd.createDocStruct(this.prefs.getDocStrctTypeByName("BoundBook"));
dd.setPhysicalDocStruct(physical);

// try to use publicationtype from xlsx if it wasn't specified use fallback type from importset
Expand All @@ -139,11 +141,11 @@ public DocumentManager(ProcessDescription processDescription, ImportSet importSe
if (dstype == null) {
throw new ProcessCreationException("Couldn't find publication type: " + importSet.getPublicationType() + " in the ruleset.");
}
DocStruct logic = dd.createDocStruct(dstype);
dd.setLogicalDocStruct(logic);
logical = dd.createDocStruct(dstype);
dd.setLogicalDocStruct(logical);

// save the process
Process process = bhelp.createAndSaveNewProcess(template, processname, ff);
process = bhelp.createAndSaveNewProcess(template, processname, ff);
plugin.updateLog("Process successfully created with ID: " + process.getId(), 2);

// add some properties
Expand All @@ -163,12 +165,9 @@ public DocumentManager(ProcessDescription processDescription, ImportSet importSe
}
}

this.process = process;
// read fileformat etc. from process
this.fileformat = this.process.readMetadataFile();
this.digitalDocument = this.fileformat.getDigitalDocument();
this.logical = this.digitalDocument.getLogicalDocStruct();
this.physical = this.digitalDocument.getPhysicalDocStruct();
//initialize variable replacer
this.replacer = new VariableReplacer(this.fileformat.getDigitalDocument(), this.prefs, this.process, null);

Expand Down Expand Up @@ -203,16 +202,6 @@ private void addNodeId(DocStruct ds, String nodeId) throws MetadataTypeNotAllowe
}
}

// public void addMetaDataToTopStruct(MappingField mappingField, String cellContent, String gndUri)
// throws MetadataTypeNotAllowedException, TypeNotAllowedAsChildException {
// addMetadata(this.logical, mappingField, cellContent, gndUri);
// }

// public void addMetadataToStructure(MappingField mappingField, String cellContent, String gndUri)
// throws TypeNotAllowedForParentException, MetadataTypeNotAllowedException, TypeNotAllowedAsChildException {
// addMetadata(this.structure, mappingField, cellContent, gndUri);
// }

private DocStruct createStructure(String structType) throws TypeNotAllowedForParentException {
DocStructType dsType = this.prefs.getDocStrctTypeByName(structType);
if (dsType != null) {
Expand All @@ -235,7 +224,7 @@ protected void addMetadataFromRowToTopStruct(Row row, List<MappingField> mapping
}

public void createStructureWithMetaData(Row row, List<MappingField> mappingFields, Set<Path> imageFiles, String nodeId)
throws TypeNotAllowedForParentException, TypeNotAllowedAsChildException, IOException, InterruptedException, SwapException, DAOException {
throws TypeNotAllowedForParentException, TypeNotAllowedAsChildException, IOException, SwapException, DAOException {
// look if structureType is defined in table
MappingField mFieldStructureType =
mappingFields.stream().filter(mappingField -> "structureType".equals(mappingField.getType())).findFirst().orElse(null);
Expand Down Expand Up @@ -283,6 +272,8 @@ protected void addMetadataFromRow(DocStruct docStruct, Row row, List<MappingFiel
try {
addMetadata(docStruct, mappingField, cellContent, gndUri);
} catch (MetadataTypeNotAllowedException e) {
log.error("Invalid mapping: mappingField.type={}, mappingField.mets={}, cellContent={}", mappingField.getType(),
mappingField.getMets(), cellContent);
this.plugin.updateLogAndProcess(this.process.getId(), "Invalid Mapping for Field " + mappingField.getType()
+ " in MappingSet " + this.importSet.getMapping() + " for METs: " + mappingField.getMets(), 3);
}
Expand Down Expand Up @@ -430,7 +421,7 @@ private void addMediaFile(DocStruct structure, MappingField mappingField, String
}

private void copyFileToTarget(String target, MappingField mappingField, String cellContent, Set<Path> imageFiles)
throws IOException, SwapException, DAOException {
throws IOException {
StorageProviderInterface storageProvider = StorageProvider.getInstance();
String[] fileNames = cellContent.split(mappingField.getSeparator());
for (String fileName : fileNames) {
Expand Down Expand Up @@ -468,12 +459,12 @@ private boolean addPage(DocStruct ds, File imageFile) {
try {
DocStructType newPage = this.prefs.getDocStrctTypeByName("page");
DocStruct dsPage = this.digitalDocument.createDocStruct(newPage);
this.PageCount++;
this.pageCount++;
// physical page no
this.physical.addChild(dsPage);
MetadataType mdt = this.prefs.getMetadataTypeByName("physPageNumber");
Metadata mdTemp = new Metadata(mdt);
mdTemp.setValue(String.valueOf(this.PageCount));
mdTemp.setValue(String.valueOf(this.pageCount));
dsPage.addMetadata(mdTemp);

// logical page no
Expand All @@ -496,8 +487,8 @@ private boolean addPage(DocStruct ds, File imageFile) {
cf.setLocation("file://" + imageFile.getName());

dsPage.addContentFile(cf);
if (this.PageCount % 10 == 0) {
this.plugin.updateLog("Created " + this.PageCount + " physical Pages for Process with Id: " + this.process.getId());
if (this.pageCount % 10 == 0) {
this.plugin.updateLog("Created " + this.pageCount + " physical Pages for Process with Id: " + this.process.getId());
}
return true;
} catch (TypeNotAllowedAsChildException | TypeNotAllowedForParentException e) {
Expand All @@ -516,18 +507,16 @@ private void setAuthorityFile(Metadata metadata, String gndUri) {
String gnd = null;
int index = gndUri.lastIndexOf('/');
if (index < 0) {
// plugin.updateLogAndProcess(process.getId(), "Couldn't parse gndUri ", 3);
// better to be optimistic, maybe it's a gnd without authority uri
gnd = gndUri.trim();
} else {
gnd = gndUri.substring(index + 1);
}
if (StringUtils.isNotBlank(gnd)) {
metadata.setAutorityFile("gnd", "http://d-nb.info/gnd/", gnd);
metadata.setAuthorityFile("gnd", "http://d-nb.info/gnd/", gnd);
}
}

public void writeMetadataFile() throws WriteException, PreferencesException, IOException, InterruptedException, SwapException, DAOException {
public void writeMetadataFile() throws WriteException, PreferencesException, IOException, SwapException {
this.process.writeMetadataFile(this.fileformat);
}

Expand Down
72 changes: 30 additions & 42 deletions module-base/src/main/java/de/intranda/goobi/plugins/EadManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Row;
import org.goobi.beans.User;
import org.goobi.interfaces.IArchiveManagementAdministrationPlugin;
import org.goobi.interfaces.IEadEntry;
import org.goobi.interfaces.IFieldValue;
import org.goobi.interfaces.IMetadataField;
import org.goobi.interfaces.INodeType;
import org.goobi.production.enums.PluginType;
Expand All @@ -15,42 +16,31 @@

import de.intranda.goobi.plugins.HuImporterWorkflowPlugin.ImportSet;
import de.intranda.goobi.plugins.HuImporterWorkflowPlugin.MappingField;
import de.intranda.goobi.plugins.model.FieldValue;
import de.sub.goobi.helper.Helper;
import io.goobi.workflow.locking.LockingBean;
import lombok.Getter;

public class EadManager {
private ArchiveManagementAdministrationPlugin archivePlugin;
private IArchiveManagementAdministrationPlugin archivePlugin;
private String processName;
private String CatalogIDDigital;
private String catalogIDDigital;
private ImportSet importSet;
private boolean setNodeId;
private IEadEntry selectedNode = null;
@Getter
private boolean dbStatusOk;

public EadManager(ImportSet importSet, String processName, String CatalogIDDigital) {
public EadManager(ImportSet importSet, String processName, String catalogIDDigital) {
this.importSet = importSet;
this.processName = processName;
this.CatalogIDDigital = CatalogIDDigital;
this.catalogIDDigital = catalogIDDigital;

// find out if archive file is locked currently
IPlugin ia = PluginLoader.getPluginByTitle(PluginType.Administration, "intranda_administration_archive_management");
this.archivePlugin = (ArchiveManagementAdministrationPlugin) ia;
this.archivePlugin = (IArchiveManagementAdministrationPlugin) ia;

User user = Helper.getCurrentUser();
String username = user != null ? user.getNachVorname() : "-";
if (!LockingBean.lockObject(importSet.getEadFile(), username)) {
this.dbStatusOk = false;
return;
} else {
// prepare ArchivePlugin
this.archivePlugin.getPossibleDatabases();
this.archivePlugin.setSelectedDatabase(importSet.getEadFile());
this.archivePlugin.loadSelectedDatabase();
this.dbStatusOk = checkDB();
}
// prepare ArchivePlugin
this.archivePlugin.getPossibleDatabases();
this.archivePlugin.setDatabaseName(importSet.getEadFile());
this.archivePlugin.loadSelectedDatabase();
this.dbStatusOk = checkDB();

if (this.dbStatusOk) {
try {
Expand All @@ -67,8 +57,8 @@ public EadManager(ImportSet importSet, String processName, String CatalogIDDigit

private boolean checkDB() {
List<String> possibleDBs = this.archivePlugin.getPossibleDatabases();
return !possibleDBs.isEmpty() && StringUtils.isNotBlank(this.archivePlugin.getSelectedDatabase())
&& this.archivePlugin.getSelectedDatabase().equals(this.importSet.getEadFile());
return !possibleDBs.isEmpty() && StringUtils.isNotBlank(this.archivePlugin.getDatabaseName())
&& this.archivePlugin.getDatabaseName().equals(this.importSet.getEadFile());
}

private IEadEntry findNode(String eadNode) throws NullPointerException {
Expand Down Expand Up @@ -98,17 +88,16 @@ public String addDocumentNodeWithMetadata(Row row, List<MappingField> mappingFie
}
}
// use CatalogIDDigital as NodeID
entry.setId(this.CatalogIDDigital);
entry.setId(this.catalogIDDigital);

addMetadata(entry, row, mappingFields);
entry.setGoobiProcessTitle(entry.getId());

this.archivePlugin.createEadDocument();
this.archivePlugin.updateSingleNode();
return entry.getId();
}

public void saveArchiveAndLeave() {
this.archivePlugin.createEadDocument();
this.archivePlugin.saveArchiveAndLeave();
}

Expand Down Expand Up @@ -145,42 +134,41 @@ private IEadEntry findNode(IEadEntry parent, String id) {
* @param fieldValue
*/
private void addEadMetadata(IEadEntry entry, String fieldName, String fieldValue) {
if (addEadMetadata(entry, fieldName, fieldValue, entry.getIdentityStatementAreaList())) {
return;
}
if (addEadMetadata(entry, fieldName, fieldValue, entry.getContextAreaList())) {
if (addEadMetadata(fieldName, fieldValue, entry.getIdentityStatementAreaList())) {
return;
}
if (addEadMetadata(entry, fieldName, fieldValue, entry.getContentAndStructureAreaAreaList())) {
if (addEadMetadata(fieldName, fieldValue, entry.getContextAreaList())) {
return;
}
if (addEadMetadata(entry, fieldName, fieldValue, entry.getAccessAndUseAreaList())) {
if (addEadMetadata(fieldName, fieldValue, entry.getContentAndStructureAreaAreaList())) {
return;
}
if (addEadMetadata(entry, fieldName, fieldValue, entry.getAlliedMaterialsAreaList())) {
if (addEadMetadata(fieldName, fieldValue, entry.getAccessAndUseAreaList())) {
return;
}
if (addEadMetadata(entry, fieldName, fieldValue, entry.getNotesAreaList())) {
if (addEadMetadata(fieldName, fieldValue, entry.getAlliedMaterialsAreaList())) {
return;
}
if (addEadMetadata(entry, fieldName, fieldValue, entry.getDescriptionControlAreaList())) {
if (addEadMetadata(fieldName, fieldValue, entry.getNotesAreaList())) {
return;
}

addEadMetadata(fieldName, fieldValue, entry.getDescriptionControlAreaList());
}

/**
* iterate through all metadata fields of a specific list
*
* @param entry
* @param fieldName
* @param fieldValue
* @param list
* @return
*/
private boolean addEadMetadata(IEadEntry entry, String fieldName, String fieldValue, List<IMetadataField> list) {
private boolean addEadMetadata(String fieldName, String fieldValue, List<IMetadataField> list) {
for (IMetadataField field : list) {
if (field.getName().equals(fieldName)) {
FieldValue value = new FieldValue(field);

IFieldValue value = field.createFieldValue();
value.setValue(fieldValue.trim());
field.setValues(Arrays.asList(value));
return true;
Expand All @@ -190,17 +178,17 @@ private boolean addEadMetadata(IEadEntry entry, String fieldName, String fieldVa
}

public String addSubnodeWithMetaData(Row row, List<MappingField> mappingFields) {
String NodeType = this.importSet.getEadSubnodeType();
String nodeType = this.importSet.getEadSubnodeType();
IEadEntry parent = this.archivePlugin.getSelectedEntry();
if (StringUtils.isBlank(NodeType)) {
if (StringUtils.isBlank(nodeType)) {
return null;
}

this.archivePlugin.addNode();
IEadEntry entry = this.archivePlugin.getSelectedEntry();
// set the prefered node type for the created node
for (INodeType nt : this.archivePlugin.getConfiguredNodes()) {
if (nt.getNodeName().equals(NodeType)) {
if (nt.getNodeName().equals(nodeType)) {
entry.setNodeType(nt);
entry.setGoobiProcessTitle(this.processName);
addMetadata(entry, row, mappingFields);
Expand Down
Loading

0 comments on commit 6a78219

Please sign in to comment.