Skip to content

Commit

Permalink
Merge pull request 'Release v24.06' (#5) from release_24.06 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
janvonde committed Jul 10, 2024
2 parents 043a97b + 0ab1225 commit 4873aed
Show file tree
Hide file tree
Showing 11 changed files with 583 additions and 26 deletions.
35 changes: 20 additions & 15 deletions install/plugin_intranda_export_adm_bsme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,27 @@
<!-- configured values to be used inside of the export xml, can use variable
replacer expressions here like e.g.: - $(meta.CatalogIDDigital) - $(meta.topstruct.TitleDocMain)
- $(process.Template) -->
<rightsToUse>$(template.Rights to Use)</rightsToUse>
<rightsDetails>$(template.Rights Details)</rightsDetails>
<rightsToUse>$(meta.AdmRightToUse)</rightsToUse>
<rightsDetails>$(meta.AdmRightDetails)</rightsDetails>
<source>Goobi</source>
<mediaType>$(template.Media Type)</mediaType>
<mediaGroup>$(template.Media Group)</mediaGroup>
<sourceOrganisation>$(template.Source Organization)</sourceOrganisation>
<frequency>$(template.Issue Frequency)</frequency>
<eventName>$(template.Event Name)</eventName>
<eventDate>$(template.Event Date)</eventDate>
<subject>$(template.Subject)</subject>
<photographer>$(template.Photographer)</photographer>
<personsInImage>$(template.Persons in Image)</personsInImage>
<locations>$(template.Locations)</locations>
<description>$(template.Description)</description>
<editorInChief>$(template.Editor in Chief)</editorInChief>
<format>$(template.Format)</format>
<mediaType>$(meta.AdmMediaType)</mediaType>
<mediaGroup>$(meta.AdmMediaGroup)</mediaGroup>
<sourceOrganisation>$(meta.AdmSourceOrganization)</sourceOrganisation>
<frequency>$(meta.AdmIssueFrequency)</frequency>
<eventName>$(meta.AdmEventName)</eventName>
<eventDate>$(meta.AdmEventDate)</eventDate>
<eventTime>$(meta.AdmEventTime)</eventTime>
<subject>$(meta.Subject)</subject>
<subjectArabic>$(meta.AdmSubjectArabic)</subjectArabic>
<subjectEnglish>$(meta.AdmSubjectEnglish)</subjectEnglish>
<photographer>$(meta.AdmPhotographer)</photographer>
<personsInImage>$(meta.AdmPersonsInImage)</personsInImage>
<locations>$(meta.AdmEventLocations)</locations>
<description>$(meta.Description)</description>
<editorInChief>$(meta.AdmEditorInChief)</editorInChief>
<format>$(meta.Format)</format>
<envelopeNumber>$(meta.AdmEnvelopeNumber)</envelopeNumber>
<backprint>$(meta.AdmBackprint)</backprint>

<!-- mets parameter -->
<!-- if a field is empty or missing, project configuration is used -->
Expand Down
2 changes: 1 addition & 1 deletion module-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>io.goobi.workflow.plugin</groupId>
<artifactId>plugin-export-adm-bsme</artifactId>
<version>24.05</version>
<version>24.06</version>
</parent>
<artifactId>plugin-export-adm-bsme-base</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
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.PositiveExporter;
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;
Expand Down Expand Up @@ -106,13 +112,24 @@ 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
SlideExporter ex = new SlideExporter(ConfigPlugins.getPluginConfig(title), process, prefs, dd);
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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
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<String, String> fileMap;
private int fileCounter;
private VariableReplacer vr;

@Getter
private List<String> 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<String, String>();
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"));
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("Publication_Name")
.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));
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("Backprint").setText(backprint));

// 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<Reference> 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;
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.intranda.goobi.plugins;
package de.intranda.goobi.plugins.exporters;

import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.intranda.goobi.plugins;
package de.intranda.goobi.plugins.exporters;

import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -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;
Expand Down Expand Up @@ -97,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"));
Expand All @@ -108,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("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(
Expand Down
Loading

0 comments on commit 4873aed

Please sign in to comment.