From 5289095cb06067977de96c7c8b9b91c5fcae08e5 Mon Sep 17 00:00:00 2001 From: Release-Tool Date: Mon, 10 Jun 2024 08:57:12 +0200 Subject: [PATCH 1/7] Change project version to 24.06-SNAPSHOT --- module-base/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/module-base/pom.xml b/module-base/pom.xml index fb9636c..5366731 100644 --- a/module-base/pom.xml +++ b/module-base/pom.xml @@ -3,7 +3,7 @@ io.goobi.workflow.plugin plugin-export-adm-bsme - 24.05 + 24.06-SNAPSHOT plugin-export-adm-bsme-base jar diff --git a/pom.xml b/pom.xml index 3601dc5..ec182cd 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ io.goobi.workflow workflow-base - 24.05 + 24.06-SNAPSHOT io.goobi.workflow.plugin From 49ba9bf375ded267316f82df058bbb7a87d9efb4 Mon Sep 17 00:00:00 2001 From: Steffen Hankiewicz Date: Wed, 19 Jun 2024 17:15:08 +0200 Subject: [PATCH 2/7] added generic export --- .../goobi/plugins/AdmBsmeExportPlugin.java | 11 + .../plugins/exporters/GenericExporter.java | 245 ++++++++++++++++++ .../{ => exporters}/MagazineExporter.java | 4 +- .../{ => exporters}/NegativeExporter.java | 5 +- .../{ => exporters}/NewspaperExporter.java | 4 +- .../{ => exporters}/NewspaperMetsCreator.java | 3 +- .../{ => exporters}/SlideExporter.java | 3 +- 7 files changed, 269 insertions(+), 6 deletions(-) create mode 100644 module-base/src/main/java/de/intranda/goobi/plugins/exporters/GenericExporter.java rename module-base/src/main/java/de/intranda/goobi/plugins/{ => exporters}/MagazineExporter.java (99%) rename module-base/src/main/java/de/intranda/goobi/plugins/{ => exporters}/NegativeExporter.java (98%) rename module-base/src/main/java/de/intranda/goobi/plugins/{ => exporters}/NewspaperExporter.java (99%) rename module-base/src/main/java/de/intranda/goobi/plugins/{ => exporters}/NewspaperMetsCreator.java (99%) rename module-base/src/main/java/de/intranda/goobi/plugins/{ => exporters}/SlideExporter.java (99%) diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/AdmBsmeExportPlugin.java b/module-base/src/main/java/de/intranda/goobi/plugins/AdmBsmeExportPlugin.java index d030689..39b3b98 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/AdmBsmeExportPlugin.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/AdmBsmeExportPlugin.java @@ -10,6 +10,11 @@ import org.goobi.production.plugin.interfaces.IExportPlugin; import org.goobi.production.plugin.interfaces.IPlugin; +import de.intranda.goobi.plugins.exporters.GenericExporter; +import de.intranda.goobi.plugins.exporters.MagazineExporter; +import de.intranda.goobi.plugins.exporters.NegativeExporter; +import de.intranda.goobi.plugins.exporters.NewspaperExporter; +import de.intranda.goobi.plugins.exporters.SlideExporter; import de.sub.goobi.config.ConfigPlugins; import de.sub.goobi.export.dms.ExportDms; import de.sub.goobi.helper.Helper; @@ -113,6 +118,12 @@ public boolean startExport(Process process, String destination) success = ex.startExport(); } + if ("AdmGeneric".equals(topStruct.getType().getName())) { + // if it is a Generic + GenericExporter ex = new GenericExporter(ConfigPlugins.getPluginConfig(title), process, prefs, dd); + success = ex.startExport(); + } + } } catch (ReadException | PreferencesException | IOException | SwapException e) { diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/exporters/GenericExporter.java b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/GenericExporter.java new file mode 100644 index 0000000..a8b0ed3 --- /dev/null +++ b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/GenericExporter.java @@ -0,0 +1,245 @@ +package de.intranda.goobi.plugins.exporters; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.configuration.XMLConfiguration; +import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine; +import org.goobi.beans.JournalEntry; +import org.goobi.beans.Process; +import org.goobi.production.enums.LogType; +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.output.Format; +import org.jdom2.output.XMLOutputter; + +import de.intranda.goobi.plugins.AdmBsmeExportHelper; +import de.sub.goobi.helper.StorageProvider; +import de.sub.goobi.helper.StorageProviderInterface; +import de.sub.goobi.helper.VariableReplacer; +import de.sub.goobi.helper.exceptions.DAOException; +import de.sub.goobi.helper.exceptions.SwapException; +import de.unigoettingen.sub.commons.contentlib.exceptions.ImageManagerException; +import de.unigoettingen.sub.commons.contentlib.imagelib.ImageInterpreter; +import de.unigoettingen.sub.commons.contentlib.imagelib.ImageManager; +import lombok.Getter; +import lombok.extern.log4j.Log4j2; +import net.xeoh.plugins.base.annotations.PluginImplementation; +import ugh.dl.DigitalDocument; +import ugh.dl.DocStruct; +import ugh.dl.Prefs; +import ugh.dl.Reference; + +@PluginImplementation +@Log4j2 +public class GenericExporter { + + private XMLConfiguration config; + private Process process; + private Prefs prefs; + private DigitalDocument dd; + private String targetFolder; + + // keep a list of all image files as they need to be renamed + private Map fileMap; + private int fileCounter; + private VariableReplacer vr; + + @Getter + private List problems; + + /** + * Constructor + * + * @param config + * @param process + * @param prefs + * @param dd + */ + public GenericExporter(XMLConfiguration config, Process process, Prefs prefs, DigitalDocument dd) { + this.config = config; + config.setExpressionEngine(new XPathExpressionEngine()); + this.process = process; + this.prefs = prefs; + this.dd = dd; + targetFolder = config.getString("targetDirectoryGeneric", "/opt/digiverso/goobi/output/"); + } + + /** + * Do the actual export for a newspaper volume + * + * @param process + * @param destination + * @return + */ + public boolean startExport() { + vr = new VariableReplacer(dd, prefs, process, null); + problems = new ArrayList<>(); + fileMap = new HashMap(); + fileCounter = 0; + log.debug("Export directory for AdmBsmeExportPlugin: " + targetFolder); + DocStruct topStruct = dd.getLogicalDocStruct(); + + // prepare xml document + Document doc = new Document(); + doc.setRootElement(new Element("image")); + + // add volume information + Element info = new Element("ImageInfo"); + doc.getRootElement().addContent(info); + String identifier = AdmBsmeExportHelper.getMetdata(topStruct, config.getString("/metadata/identifier")); + + String rightsToUse = vr.replace(config.getString("/rightsToUse")); + String rightsDetails = vr.replace(config.getString("/rightsDetails")); + String source = vr.replace(config.getString("/source")); + String mediaType = vr.replace(config.getString("/mediaType")); + String mediaGroup = vr.replace(config.getString("/mediaGroup")); + String sourceOrganisation = vr.replace(config.getString("/sourceOrganisation")); + String eventDate = vr.replace(config.getString("/eventDate")); + String eventName = vr.replace(config.getString("/eventName")); + String subject = vr.replace(config.getString("/subject")); + String photographer = vr.replace(config.getString("/photographer")); + String personsInImage = vr.replace(config.getString("/personsInImage")); + String locations = vr.replace(config.getString("/locations")); + String description = vr.replace(config.getString("/description")); + String editorInChief = vr.replace(config.getString("/editorInChief")); + String format = vr.replace(config.getString("/format")); + + info.addContent(new Element("Rights_to_Use").setText(rightsToUse)); + info.addContent(new Element("Right_Details").setText(rightsDetails)); + info.addContent(new Element("Media_Source").setText(source)); + info.addContent(new Element("Media_Type").setText(mediaType)); + info.addContent(new Element("Publication_Name") + .setText(AdmBsmeExportHelper.getMetdata(topStruct, config.getString("/metadata/titleLabel")))); + info.addContent( + new Element("Source_Organization").setText(sourceOrganisation)); + info.addContent(new Element("Event_Date").setText(eventDate)); + info.addContent(new Element("Event_Name").setText(eventName)); + info.addContent(new Element("Photographer").setText(photographer)); + info.addContent(new Element("Format").setText(format)); + info.addContent(new Element("Persons_in_Image").setText(personsInImage)); + info.addContent(new Element("location").setText(locations)); + info.addContent(new Element("Description").setText(description)); + + // info.addContent(new Element("Media_Group").setText(mediaGroup)); + + // add all journal entries as technical notes + if (process.getJournal() != null) { + Element technicalNotes = new Element("Technical_Notes"); + for (JournalEntry je : process.getJournal()) { + if (je.getType() == LogType.USER) { + technicalNotes.addContent(new Element("Entry").setAttribute("date", je.getFormattedCreationDate()) + .setAttribute("type", je.getType().getTitle()) + .setText(je.getFormattedContent())); + } + } + info.addContent(technicalNotes); + } else { + info.addContent(new Element("Technical_Notes").setText("- no entry available -")); + } + + // add file information + Element files = new Element("Files"); + doc.getRootElement().addContent(files); + + List refs = topStruct.getAllToReferences("logical_physical"); + if (refs != null) { + for (Reference ref : refs) { + DocStruct page = ref.getTarget(); + String realFileName = page.getImageName(); + String realFileNameWithoutExtension = realFileName.substring(0, realFileName.indexOf(".")); + + // get the new file name for the image and reuse if created previously + String exportFileName = fileMap.get(realFileNameWithoutExtension); + if (exportFileName == null) { + String counter = String.format("%04d", ++fileCounter); + exportFileName = identifier + "-" + counter; + fileMap.put(realFileNameWithoutExtension, exportFileName); + } + + // add file element + Element master = new Element("master"); + + // add image information + try { + File realFile = new File(process.getImagesOrigDirectory(false), + realFileNameWithoutExtension + ".tif"); + try (ImageManager sourcemanager = new ImageManager(realFile.toURI())) { + ImageInterpreter si = sourcemanager.getMyInterpreter(); + + // MimeType + // master.setAttribute("Format", si.getFormatType().getFormat().getMimeType()); + master.addContent(new Element("Format").setText(si.getFormatType().getFormat().getMimeType())); + + // Unit for the resolution, always ppi + // master.setAttribute("ResolutionUnit", "PPI"); + master.addContent(new Element("ResolutionUnit").setText("PPI")); + + // Resolution + // master.setAttribute("Resolution", String.valueOf(si.getOriginalImageXResolution())); + master.addContent(new Element("Resolution").setText(String.valueOf(si.getOriginalImageXResolution()))); + + // ColorDepth + // master.setAttribute("BitDepth", String.valueOf(si.getColordepth())); + master.addContent(new Element("BitDepth").setText(String.valueOf(si.getColordepth()))); + + // bitonal, grey, "color" + // master.setAttribute("ColorSpace", si.getFormatType().getColortype().getLabel()); + master.addContent(new Element("ColorSpace").setText(si.getFormatType().getColortype().getLabel())); + + // Scanning device + master.addContent(new Element("ScanningDevice").setText(vr.replace("${process.Capturing device}"))); + + // Scanning device id + String scanningDeviceId = "- no serial number available -"; //si.getMetadata().toString(); + master.addContent(new Element("ScanningDeviceID").setText(scanningDeviceId)); + + // Width + master.addContent(new Element("Width").setText(String.valueOf(si.getOriginalImageWidth()))); + + // Height + master.addContent(new Element("Height").setText(String.valueOf(si.getOriginalImageHeight()))); + sourcemanager.close(); + } + } catch (IOException | SwapException | DAOException | ImageManagerException e) { + log.error("Error while reading image metadata", e); + return false; + } + + master.addContent(new Element("file").setText(exportFileName + ".tif")); + files.addContent(master); + files.addContent(new Element("text").setText(exportFileName + ".txt").setAttribute("Format", "text/plain")); + + } + } + + // write the xml file + XMLOutputter xmlOutputter = new XMLOutputter(); + xmlOutputter.setFormat(Format.getPrettyFormat()); + File xmlfile = new File(targetFolder + identifier + ".xml"); + try (FileOutputStream fileOutputStream = new FileOutputStream(xmlfile)) { + xmlOutputter.output(doc, fileOutputStream); + } catch (IOException e) { + log.error("Error writing the simple xml file", e); + return false; + } + + try { + // copy all important files to target folder + AdmBsmeExportHelper.copyFolderContent(process.getImagesOrigDirectory(false), "tif", fileMap, targetFolder); + StorageProviderInterface sp = StorageProvider.getInstance(); + + } catch (IOException | SwapException | DAOException e) { + log.error("Error while copying the image files to export folder", e); + return false; + } + + return true; + } + +} \ No newline at end of file diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/MagazineExporter.java b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/MagazineExporter.java similarity index 99% rename from module-base/src/main/java/de/intranda/goobi/plugins/MagazineExporter.java rename to module-base/src/main/java/de/intranda/goobi/plugins/exporters/MagazineExporter.java index 70024d0..2877fd5 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/MagazineExporter.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/MagazineExporter.java @@ -1,4 +1,4 @@ -package de.intranda.goobi.plugins; +package de.intranda.goobi.plugins.exporters; import java.io.File; import java.io.FileOutputStream; @@ -21,6 +21,8 @@ import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; +import de.intranda.goobi.plugins.AdmBsmeExportHelper; +import de.intranda.goobi.plugins.PdfIssue; import de.sub.goobi.helper.StorageProvider; import de.sub.goobi.helper.StorageProviderInterface; import de.sub.goobi.helper.VariableReplacer; diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/NegativeExporter.java b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/NegativeExporter.java similarity index 98% rename from module-base/src/main/java/de/intranda/goobi/plugins/NegativeExporter.java rename to module-base/src/main/java/de/intranda/goobi/plugins/exporters/NegativeExporter.java index c96d0dc..374a7a4 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/NegativeExporter.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/NegativeExporter.java @@ -1,4 +1,4 @@ -package de.intranda.goobi.plugins; +package de.intranda.goobi.plugins.exporters; import java.io.File; import java.io.FileOutputStream; @@ -18,6 +18,7 @@ import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; +import de.intranda.goobi.plugins.AdmBsmeExportHelper; import de.sub.goobi.helper.StorageProvider; import de.sub.goobi.helper.StorageProviderInterface; import de.sub.goobi.helper.VariableReplacer; @@ -112,7 +113,7 @@ public boolean startExport() { info.addContent(new Element("Rights_to_Use").setText(rightsToUse)); info.addContent(new Element("Right_Details").setText(rightsDetails)); info.addContent(new Element("Media_Source").setText(source)); - info.addContent(new Element("Media_type").setText(mediaType)); + info.addContent(new Element("Media_Type").setText(mediaType)); info.addContent(new Element("Envelope_Barcode").setText(identifier)); info.addContent(new Element("Publication_Name") .setText(AdmBsmeExportHelper.getMetdata(topStruct, config.getString("/metadata/titleLabel")))); diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/NewspaperExporter.java b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/NewspaperExporter.java similarity index 99% rename from module-base/src/main/java/de/intranda/goobi/plugins/NewspaperExporter.java rename to module-base/src/main/java/de/intranda/goobi/plugins/exporters/NewspaperExporter.java index dc82852..c1288c0 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/NewspaperExporter.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/NewspaperExporter.java @@ -1,4 +1,4 @@ -package de.intranda.goobi.plugins; +package de.intranda.goobi.plugins.exporters; import java.io.File; import java.io.FileOutputStream; @@ -20,6 +20,8 @@ import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; +import de.intranda.goobi.plugins.AdmBsmeExportHelper; +import de.intranda.goobi.plugins.PdfIssue; import de.sub.goobi.helper.Helper; import de.sub.goobi.helper.StorageProvider; import de.sub.goobi.helper.VariableReplacer; diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/NewspaperMetsCreator.java b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/NewspaperMetsCreator.java similarity index 99% rename from module-base/src/main/java/de/intranda/goobi/plugins/NewspaperMetsCreator.java rename to module-base/src/main/java/de/intranda/goobi/plugins/exporters/NewspaperMetsCreator.java index 545960b..a405414 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/NewspaperMetsCreator.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/NewspaperMetsCreator.java @@ -1,4 +1,4 @@ -package de.intranda.goobi.plugins; +package de.intranda.goobi.plugins.exporters; import java.io.FileOutputStream; import java.io.IOException; @@ -23,6 +23,7 @@ import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; +import de.intranda.goobi.plugins.AdmBsmeExportHelper; import de.sub.goobi.helper.StorageProvider; import de.sub.goobi.helper.VariableReplacer; import de.sub.goobi.helper.XmlTools; diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/SlideExporter.java b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/SlideExporter.java similarity index 99% rename from module-base/src/main/java/de/intranda/goobi/plugins/SlideExporter.java rename to module-base/src/main/java/de/intranda/goobi/plugins/exporters/SlideExporter.java index 4c5b7d1..9798bd2 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/SlideExporter.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/SlideExporter.java @@ -1,4 +1,4 @@ -package de.intranda.goobi.plugins; +package de.intranda.goobi.plugins.exporters; import java.io.File; import java.io.FileOutputStream; @@ -18,6 +18,7 @@ import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; +import de.intranda.goobi.plugins.AdmBsmeExportHelper; import de.sub.goobi.helper.StorageProvider; import de.sub.goobi.helper.StorageProviderInterface; import de.sub.goobi.helper.VariableReplacer; From 80b7db6987d095ffe5a5cb4b8871f2bf5fdd880a Mon Sep 17 00:00:00 2001 From: Steffen Hankiewicz Date: Tue, 2 Jul 2024 11:11:17 +0200 Subject: [PATCH 3/7] more progress --- .../intranda/goobi/plugins/exporters/NegativeExporter.java | 2 ++ .../de/intranda/goobi/plugins/exporters/SlideExporter.java | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/exporters/NegativeExporter.java b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/NegativeExporter.java index 374a7a4..30fb5a0 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/exporters/NegativeExporter.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/NegativeExporter.java @@ -109,12 +109,14 @@ public boolean startExport() { String description = vr.replace(config.getString("/description")); String editorInChief = vr.replace(config.getString("/editorInChief")); String format = vr.replace(config.getString("/format")); + String envelopeNumber = vr.replace(config.getString("/envelopeNumber")); info.addContent(new Element("Rights_to_Use").setText(rightsToUse)); info.addContent(new Element("Right_Details").setText(rightsDetails)); info.addContent(new Element("Media_Source").setText(source)); info.addContent(new Element("Media_Type").setText(mediaType)); info.addContent(new Element("Envelope_Barcode").setText(identifier)); + info.addContent(new Element("Envelope_Number").setText(envelopeNumber)); info.addContent(new Element("Publication_Name") .setText(AdmBsmeExportHelper.getMetdata(topStruct, config.getString("/metadata/titleLabel")))); info.addContent( diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/exporters/SlideExporter.java b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/SlideExporter.java index 9798bd2..92964a3 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/exporters/SlideExporter.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/SlideExporter.java @@ -102,7 +102,8 @@ public boolean startExport() { String sourceOrganisation = vr.replace(config.getString("/sourceOrganisation")); String eventDate = vr.replace(config.getString("/eventDate")); String eventName = vr.replace(config.getString("/eventName")); - String subject = vr.replace(config.getString("/subject")); + String subjectEng = vr.replace(config.getString("/subjectEnglish")); + String subjectAra = vr.replace(config.getString("/subjectArabic")); String photographer = vr.replace(config.getString("/photographer")); String personsInImage = vr.replace(config.getString("/personsInImage")); String locations = vr.replace(config.getString("/locations")); @@ -121,6 +122,8 @@ public boolean startExport() { info.addContent(new Element("Barcode").setText(identifier)); info.addContent(new Element("Event_Date").setText(eventDate)); info.addContent(new Element("Event_Name").setText(eventName)); + info.addContent(new Element("Subject_ENG").setText(subjectEng)); + info.addContent(new Element("Subject_ARA").setText(subjectAra)); info.addContent(new Element("Photographer").setText(photographer)); info.addContent(new Element("Format").setText(format)); info.addContent(new Element("Persons_in_Image").setText(personsInImage)); @@ -129,7 +132,6 @@ public boolean startExport() { // info.addContent(new Element("Editor_in_Chief").setText(editorInChief)); // info.addContent(new Element("Media_Group").setText(mediaGroup)); - // info.addContent(new Element("Subject").setText(subject)); // add all journal entries as technical notes if (process.getJournal() != null) { From d4b754e77af405f93df4cb1cea1621659f4183a5 Mon Sep 17 00:00:00 2001 From: Steffen Hankiewicz Date: Thu, 4 Jul 2024 15:13:07 +0200 Subject: [PATCH 4/7] updated to newest reference files --- install/plugin_intranda_export_adm_bsme.xml | 35 +++++++++++-------- .../plugins/exporters/GenericExporter.java | 8 +++-- .../plugins/exporters/NegativeExporter.java | 2 +- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/install/plugin_intranda_export_adm_bsme.xml b/install/plugin_intranda_export_adm_bsme.xml index b63adef..6fa79ab 100644 --- a/install/plugin_intranda_export_adm_bsme.xml +++ b/install/plugin_intranda_export_adm_bsme.xml @@ -18,22 +18,27 @@ - $(template.Rights to Use) - $(template.Rights Details) + $(meta.AdmRightToUse) + $(meta.AdmRightDetails) Goobi - $(template.Media Type) - $(template.Media Group) - $(template.Source Organization) - $(template.Issue Frequency) - $(template.Event Name) - $(template.Event Date) - $(template.Subject) - $(template.Photographer) - $(template.Persons in Image) - $(template.Locations) - $(template.Description) - $(template.Editor in Chief) - $(template.Format) + $(meta.AdmMediaType) + $(meta.AdmMediaGroup) + $(meta.AdmSourceOrganization) + $(meta.AdmIssueFrequency) + $(meta.AdmEventName) + $(meta.AdmEventDate) + $(meta.AdmEventTime) + $(meta.Subject) + $(meta.AdmSubjectArabic) + $(meta.AdmSubjectEnglish) + $(meta.AdmPhotographer) + $(meta.AdmPersonsInImage) + $(meta.AdmEventLocations) + $(meta.Description) + $(meta.AdmEditorInChief) + $(meta.Format) + $(meta.AdmEnvelopeNumber) + $(meta.AdmBackprint) diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/exporters/GenericExporter.java b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/GenericExporter.java index a8b0ed3..b637278 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/exporters/GenericExporter.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/GenericExporter.java @@ -98,7 +98,7 @@ public boolean startExport() { String rightsDetails = vr.replace(config.getString("/rightsDetails")); String source = vr.replace(config.getString("/source")); String mediaType = vr.replace(config.getString("/mediaType")); - String mediaGroup = vr.replace(config.getString("/mediaGroup")); + // String mediaGroup = vr.replace(config.getString("/mediaGroup")); String sourceOrganisation = vr.replace(config.getString("/sourceOrganisation")); String eventDate = vr.replace(config.getString("/eventDate")); String eventName = vr.replace(config.getString("/eventName")); @@ -107,8 +107,9 @@ public boolean startExport() { String personsInImage = vr.replace(config.getString("/personsInImage")); String locations = vr.replace(config.getString("/locations")); String description = vr.replace(config.getString("/description")); - String editorInChief = vr.replace(config.getString("/editorInChief")); + // String editorInChief = vr.replace(config.getString("/editorInChief")); String format = vr.replace(config.getString("/format")); + String backprint = vr.replace(config.getString("/backprint")); info.addContent(new Element("Rights_to_Use").setText(rightsToUse)); info.addContent(new Element("Right_Details").setText(rightsDetails)); @@ -118,6 +119,8 @@ public boolean startExport() { .setText(AdmBsmeExportHelper.getMetdata(topStruct, config.getString("/metadata/titleLabel")))); info.addContent( new Element("Source_Organization").setText(sourceOrganisation)); + info.addContent(new Element("Barcode").setText(identifier)); + info.addContent(new Element("Subject").setText(subject)); info.addContent(new Element("Event_Date").setText(eventDate)); info.addContent(new Element("Event_Name").setText(eventName)); info.addContent(new Element("Photographer").setText(photographer)); @@ -125,6 +128,7 @@ public boolean startExport() { info.addContent(new Element("Persons_in_Image").setText(personsInImage)); info.addContent(new Element("location").setText(locations)); info.addContent(new Element("Description").setText(description)); + info.addContent(new Element("Backprint").setText(backprint)); // info.addContent(new Element("Media_Group").setText(mediaGroup)); diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/exporters/NegativeExporter.java b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/NegativeExporter.java index 30fb5a0..c97f282 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/exporters/NegativeExporter.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/NegativeExporter.java @@ -98,7 +98,7 @@ public boolean startExport() { String rightsDetails = vr.replace(config.getString("/rightsDetails")); String source = vr.replace(config.getString("/source")); String mediaType = vr.replace(config.getString("/mediaType")); - String mediaGroup = vr.replace(config.getString("/mediaGroup")); + //String mediaGroup = vr.replace(config.getString("/mediaGroup")); String sourceOrganisation = vr.replace(config.getString("/sourceOrganisation")); String eventDate = vr.replace(config.getString("/eventDate")); String eventName = vr.replace(config.getString("/eventName")); From db1f0723a4309bb0d595dd968776be1f58eb8ebd Mon Sep 17 00:00:00 2001 From: Steffen Hankiewicz Date: Thu, 4 Jul 2024 15:35:23 +0200 Subject: [PATCH 5/7] first draft for positives, still wip --- .../goobi/plugins/AdmBsmeExportPlugin.java | 6 + .../plugins/exporters/PositiveExporter.java | 253 ++++++++++++++++++ 2 files changed, 259 insertions(+) create mode 100644 module-base/src/main/java/de/intranda/goobi/plugins/exporters/PositiveExporter.java diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/AdmBsmeExportPlugin.java b/module-base/src/main/java/de/intranda/goobi/plugins/AdmBsmeExportPlugin.java index 39b3b98..304c831 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/AdmBsmeExportPlugin.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/AdmBsmeExportPlugin.java @@ -14,6 +14,7 @@ import de.intranda.goobi.plugins.exporters.MagazineExporter; import de.intranda.goobi.plugins.exporters.NegativeExporter; import de.intranda.goobi.plugins.exporters.NewspaperExporter; +import de.intranda.goobi.plugins.exporters.PositiveExporter; import de.intranda.goobi.plugins.exporters.SlideExporter; import de.sub.goobi.config.ConfigPlugins; import de.sub.goobi.export.dms.ExportDms; @@ -111,6 +112,11 @@ public boolean startExport(Process process, String destination) NegativeExporter ex = new NegativeExporter(ConfigPlugins.getPluginConfig(title), process, prefs, dd); success = ex.startExport(); } + if ("AdmPositive".equals(topStruct.getType().getName())) { + // if it is a Negative + PositiveExporter ex = new PositiveExporter(ConfigPlugins.getPluginConfig(title), process, prefs, dd); + success = ex.startExport(); + } if ("AdmSlide".equals(topStruct.getType().getName())) { // if it is a Slide diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/exporters/PositiveExporter.java b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/PositiveExporter.java new file mode 100644 index 0000000..0c299ff --- /dev/null +++ b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/PositiveExporter.java @@ -0,0 +1,253 @@ +package de.intranda.goobi.plugins.exporters; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.configuration.XMLConfiguration; +import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine; +import org.goobi.beans.JournalEntry; +import org.goobi.beans.Process; +import org.goobi.production.enums.LogType; +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.output.Format; +import org.jdom2.output.XMLOutputter; + +import de.intranda.goobi.plugins.AdmBsmeExportHelper; +import de.sub.goobi.helper.StorageProvider; +import de.sub.goobi.helper.StorageProviderInterface; +import de.sub.goobi.helper.VariableReplacer; +import de.sub.goobi.helper.exceptions.DAOException; +import de.sub.goobi.helper.exceptions.SwapException; +import de.unigoettingen.sub.commons.contentlib.exceptions.ImageManagerException; +import de.unigoettingen.sub.commons.contentlib.imagelib.ImageInterpreter; +import de.unigoettingen.sub.commons.contentlib.imagelib.ImageManager; +import lombok.Getter; +import lombok.extern.log4j.Log4j2; +import net.xeoh.plugins.base.annotations.PluginImplementation; +import ugh.dl.DigitalDocument; +import ugh.dl.DocStruct; +import ugh.dl.Prefs; +import ugh.dl.Reference; + +@PluginImplementation +@Log4j2 +public class PositiveExporter { + + private XMLConfiguration config; + private Process process; + private Prefs prefs; + private DigitalDocument dd; + private String targetFolder; + + // keep a list of all image files as they need to be renamed + private Map fileMap; + private int fileCounter; + private VariableReplacer vr; + + @Getter + private List problems; + + /** + * Constructor + * + * @param config + * @param process + * @param prefs + * @param dd + */ + public PositiveExporter(XMLConfiguration config, Process process, Prefs prefs, DigitalDocument dd) { + this.config = config; + config.setExpressionEngine(new XPathExpressionEngine()); + this.process = process; + this.prefs = prefs; + this.dd = dd; + targetFolder = config.getString("targetDirectoryPositives", "/opt/digiverso/goobi/output/"); + } + + /** + * Do the actual export for a newspaper volume + * + * @param process + * @param destination + * @return + */ + public boolean startExport() { + vr = new VariableReplacer(dd, prefs, process, null); + problems = new ArrayList<>(); + fileMap = new HashMap(); + fileCounter = 0; + log.debug("Export directory for AdmBsmeExportPlugin: " + targetFolder); + DocStruct topStruct = dd.getLogicalDocStruct(); + + // prepare xml document + Document doc = new Document(); + doc.setRootElement(new Element("Envelope")); + + // add volume information + Element info = new Element("envelopeInfo"); + doc.getRootElement().addContent(info); + String identifier = AdmBsmeExportHelper.getMetdata(topStruct, config.getString("/metadata/identifier")); + + String rightsToUse = vr.replace(config.getString("/rightsToUse")); + String rightsDetails = vr.replace(config.getString("/rightsDetails")); + String source = vr.replace(config.getString("/source")); + String mediaType = vr.replace(config.getString("/mediaType")); + //String mediaGroup = vr.replace(config.getString("/mediaGroup")); + String sourceOrganisation = vr.replace(config.getString("/sourceOrganisation")); + String eventDate = vr.replace(config.getString("/eventDate")); + String eventName = vr.replace(config.getString("/eventName")); + String subject = vr.replace(config.getString("/subject")); + String photographer = vr.replace(config.getString("/photographer")); + String personsInImage = vr.replace(config.getString("/personsInImage")); + String locations = vr.replace(config.getString("/locations")); + String description = vr.replace(config.getString("/description")); + String editorInChief = vr.replace(config.getString("/editorInChief")); + //String format = vr.replace(config.getString("/format")); + String envelopeNumber = vr.replace(config.getString("/envelopeNumber")); + String backprint = vr.replace(config.getString("/backprint")); + + info.addContent(new Element("Rights_to_Use").setText(rightsToUse)); + info.addContent(new Element("Right_Details").setText(rightsDetails)); + info.addContent(new Element("Media_Source").setText(source)); + info.addContent(new Element("Media_Type").setText(mediaType)); + info.addContent(new Element("Envelope_Barcode").setText(identifier)); + info.addContent(new Element("Envelope_Number").setText(envelopeNumber)); + info.addContent(new Element("Publication_Name") + .setText(AdmBsmeExportHelper.getMetdata(topStruct, config.getString("/metadata/titleLabel")))); + info.addContent( + new Element("Source_Organization").setText(sourceOrganisation)); + info.addContent(new Element("Event_Date").setText(eventDate)); + info.addContent(new Element("Event_Name").setText(eventName)); + info.addContent(new Element("Subject").setText(subject)); + info.addContent(new Element("Photographer").setText(photographer)); + info.addContent(new Element("Persons_in_Image").setText(personsInImage)); + info.addContent(new Element("Editor_in_Chief").setText(editorInChief)); + info.addContent(new Element("location").setText(locations)); + info.addContent(new Element("Description").setText(description)); + + // info.addContent(new Element("Media_Group").setText(mediaGroup)); + + // add all journal entries as technical notes + if (process.getJournal() != null) { + Element technicalNotes = new Element("Technical_Notes"); + for (JournalEntry je : process.getJournal()) { + if (je.getType() == LogType.USER) { + technicalNotes.addContent(new Element("Entry").setAttribute("date", je.getFormattedCreationDate()) + .setAttribute("type", je.getType().getTitle()) + .setText(je.getFormattedContent())); + } + } + info.addContent(technicalNotes); + } else { + info.addContent(new Element("Technical_Notes").setText("- no entry available -")); + } + + // add file information + Element files = new Element("Images"); + doc.getRootElement().addContent(files); + + List refs = topStruct.getAllToReferences("logical_physical"); + if (refs != null) { + for (Reference ref : refs) { + DocStruct page = ref.getTarget(); + String realFileName = page.getImageName(); + String realFileNameWithoutExtension = realFileName.substring(0, realFileName.indexOf(".")); + + // get the new file name for the image and reuse if created previously + String exportFileName = fileMap.get(realFileNameWithoutExtension); + if (exportFileName == null) { + String counter = String.format("%03d", ++fileCounter); + exportFileName = identifier + "-" + counter; + fileMap.put(realFileNameWithoutExtension, exportFileName); + } + + // add file element + Element file = new Element("Image"); + file.setAttribute("id", String.format("%03d", fileCounter)); + file.addContent(new Element("Barcode").setText(identifier + "-" + String.format("%03d", fileCounter))); + file.addContent(new Element("Backprint").setText(backprint)); + Element master = new Element("master"); + + // add image information + try { + File realFile = new File(process.getImagesOrigDirectory(false), + realFileNameWithoutExtension + ".tif"); + try (ImageManager sourcemanager = new ImageManager(realFile.toURI())) { + ImageInterpreter si = sourcemanager.getMyInterpreter(); + + // MimeType + // master.setAttribute("Format", si.getFormatType().getFormat().getMimeType()); + master.addContent(new Element("Format").setText(si.getFormatType().getFormat().getMimeType())); + + // Unit for the resolution, always ppi + // master.setAttribute("ResolutionUnit", "PPI"); + master.addContent(new Element("ResolutionUnit").setText("PPI")); + + // Resolution + // master.setAttribute("Resolution", String.valueOf(si.getOriginalImageXResolution())); + master.addContent(new Element("Resolution").setText(String.valueOf(si.getOriginalImageXResolution()))); + + // ColorDepth + // master.setAttribute("BitDepth", String.valueOf(si.getColordepth())); + master.addContent(new Element("BitDepth").setText(String.valueOf(si.getColordepth()))); + + // bitonal, grey, "color" + // master.setAttribute("ColorSpace", si.getFormatType().getColortype().getLabel()); + master.addContent(new Element("ColorSpace").setText(si.getFormatType().getColortype().getLabel())); + + // Scanning device + master.addContent(new Element("ScanningDevice").setText(vr.replace("${process.Capturing device}"))); + + // Scanning device id + String scanningDeviceId = "- no serial number available -"; //si.getMetadata().toString(); + master.addContent(new Element("ScanningDeviceID").setText(scanningDeviceId)); + + // Width + master.addContent(new Element("Width").setText(String.valueOf(si.getOriginalImageWidth()))); + + // Height + master.addContent(new Element("Height").setText(String.valueOf(si.getOriginalImageHeight()))); + sourcemanager.close(); + } + } catch (IOException | SwapException | DAOException | ImageManagerException e) { + log.error("Error while reading image metadata", e); + return false; + } + + master.addContent(new Element("file").setText(exportFileName + ".tif")); + file.addContent(master); + files.addContent(file); + } + } + + // write the xml file + XMLOutputter xmlOutputter = new XMLOutputter(); + xmlOutputter.setFormat(Format.getPrettyFormat()); + File xmlfile = new File(targetFolder + identifier + ".xml"); + try (FileOutputStream fileOutputStream = new FileOutputStream(xmlfile)) { + xmlOutputter.output(doc, fileOutputStream); + } catch (IOException e) { + log.error("Error writing the simple xml file", e); + return false; + } + + try { + // copy all important files to target folder + AdmBsmeExportHelper.copyFolderContent(process.getImagesOrigDirectory(false), "tif", fileMap, targetFolder); + StorageProviderInterface sp = StorageProvider.getInstance(); + + } catch (IOException | SwapException | DAOException e) { + log.error("Error while copying the image files to export folder", e); + return false; + } + + return true; + } + +} \ No newline at end of file From 5faaf8fab38db326fb785f927a4c5d2a9f3c5559 Mon Sep 17 00:00:00 2001 From: Steffen Hankiewicz Date: Fri, 5 Jul 2024 09:26:57 +0200 Subject: [PATCH 6/7] export for positives finished --- .../plugins/exporters/PositiveExporter.java | 82 ++++++++++++------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/exporters/PositiveExporter.java b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/PositiveExporter.java index 0c299ff..971333b 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/exporters/PositiveExporter.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/exporters/PositiveExporter.java @@ -3,6 +3,8 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -20,7 +22,6 @@ import de.intranda.goobi.plugins.AdmBsmeExportHelper; import de.sub.goobi.helper.StorageProvider; -import de.sub.goobi.helper.StorageProviderInterface; import de.sub.goobi.helper.VariableReplacer; import de.sub.goobi.helper.exceptions.DAOException; import de.sub.goobi.helper.exceptions.SwapException; @@ -85,13 +86,8 @@ public boolean startExport() { log.debug("Export directory for AdmBsmeExportPlugin: " + targetFolder); DocStruct topStruct = dd.getLogicalDocStruct(); - // prepare xml document - Document doc = new Document(); - doc.setRootElement(new Element("Envelope")); - - // add volume information + // prepare process information Element info = new Element("envelopeInfo"); - doc.getRootElement().addContent(info); String identifier = AdmBsmeExportHelper.getMetdata(topStruct, config.getString("/metadata/identifier")); String rightsToUse = vr.replace(config.getString("/rightsToUse")); @@ -148,13 +144,23 @@ public boolean startExport() { info.addContent(new Element("Technical_Notes").setText("- no entry available -")); } - // add file information - Element files = new Element("Images"); - doc.getRootElement().addContent(files); - List refs = topStruct.getAllToReferences("logical_physical"); if (refs != null) { + + // EACH IMAGE - START for (Reference ref : refs) { + + // prepare xml document + Document doc = new Document(); + doc.setRootElement(new Element("Envelope")); + info.detach(); + doc.getRootElement().addContent(info); + + // add file information + Element files = new Element("Images"); + doc.getRootElement().addContent(files); + + // Image details DocStruct page = ref.getTarget(); String realFileName = page.getImageName(); String realFileNameWithoutExtension = realFileName.substring(0, realFileName.indexOf(".")); @@ -222,29 +228,45 @@ public boolean startExport() { master.addContent(new Element("file").setText(exportFileName + ".tif")); file.addContent(master); + + try { + // copy image file to target folder + Path in = Paths.get(process.getImagesOrigDirectory(false), realFileNameWithoutExtension + ".tif"); + Path out = Paths.get(targetFolder, exportFileName + ".tif"); + StorageProvider.getInstance().copyFile(in, out); + + // copy plaintext file to target folder and add it to xml + Path ocrPlaintextPath = Paths.get(process.getOcrTxtDirectory(), realFileNameWithoutExtension + ".txt"); + if (StorageProvider.getInstance().isFileExists(ocrPlaintextPath)) { + file.addContent(new Element("text").setText(exportFileName + ".txt").setAttribute("Format", "text/plain")); + out = Paths.get(targetFolder, exportFileName + ".txt"); + StorageProvider.getInstance().copyFile(ocrPlaintextPath, out); + } else { + file.addContent(new Element("text").setAttribute("Format", "text/plain")); + } + + } catch (IOException | SwapException | DAOException e) { + log.error("Error while copying the image and ocr files to export folder", e); + return false; + } + files.addContent(file); - } - } - // write the xml file - XMLOutputter xmlOutputter = new XMLOutputter(); - xmlOutputter.setFormat(Format.getPrettyFormat()); - File xmlfile = new File(targetFolder + identifier + ".xml"); - try (FileOutputStream fileOutputStream = new FileOutputStream(xmlfile)) { - xmlOutputter.output(doc, fileOutputStream); - } catch (IOException e) { - log.error("Error writing the simple xml file", e); - return false; - } + // write the xml file + XMLOutputter xmlOutputter = new XMLOutputter(); + xmlOutputter.setFormat(Format.getPrettyFormat()); - try { - // copy all important files to target folder - AdmBsmeExportHelper.copyFolderContent(process.getImagesOrigDirectory(false), "tif", fileMap, targetFolder); - StorageProviderInterface sp = StorageProvider.getInstance(); + File xmlfile = new File(targetFolder + identifier + "-" + String.format("%03d", fileCounter) + ".xml"); + try (FileOutputStream fileOutputStream = new FileOutputStream(xmlfile)) { + xmlOutputter.output(doc, fileOutputStream); + } catch (IOException e) { + log.error("Error writing the simple xml file", e); + return false; + } + + } + // EACH IMAGE - END - } catch (IOException | SwapException | DAOException e) { - log.error("Error while copying the image files to export folder", e); - return false; } return true; From 0ab1225be5c11898d5b3f1a44e78c9533333ad13 Mon Sep 17 00:00:00 2001 From: Release-Tool Date: Wed, 10 Jul 2024 10:31:22 +0200 Subject: [PATCH 7/7] Change project version to 24.06 --- module-base/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/module-base/pom.xml b/module-base/pom.xml index 5366731..4dd3113 100644 --- a/module-base/pom.xml +++ b/module-base/pom.xml @@ -3,7 +3,7 @@ io.goobi.workflow.plugin plugin-export-adm-bsme - 24.06-SNAPSHOT + 24.06 plugin-export-adm-bsme-base jar diff --git a/pom.xml b/pom.xml index ec182cd..5920a35 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ io.goobi.workflow workflow-base - 24.06-SNAPSHOT + 24.06 io.goobi.workflow.plugin