Skip to content

Commit

Permalink
additional pdf export and adaptions for date generation
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenHankiewicz committed May 26, 2024
1 parent 6a9e64a commit f94e124
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 27 deletions.
55 changes: 31 additions & 24 deletions install/plugin_intranda_export_adm_bsme.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
<config_plugin>

<!-- directories where to export to -->
<targetDirectoryMagazines>/opt/digiverso/viewer/hotfolderMagazines/</targetDirectoryMagazines>
<targetDirectoryNewspapers>/opt/digiverso/viewer/hotfolderNewspapers/</targetDirectoryNewspapers>
<targetDirectoryNewspapers>/opt/digiverso/export/bsme/mnt/export/Newspapers/</targetDirectoryNewspapers>
<targetDirectoryMagazines>/opt/digiverso/export/bsme/mnt/export/Magazines/</targetDirectoryMagazines>
<targetDirectoryPositives>/opt/digiverso/export/bsme/mnt/export/Positives/</targetDirectoryPositives>
<targetDirectoryNegatives>/opt/digiverso/export/bsme/mnt/export/Negatives/</targetDirectoryNegatives>
<targetDirectorySlides>/opt/digiverso/iexport/bsme/mnt/export/Slides/</targetDirectorySlides>
<targetDirectoryGeneric>/opt/digiverso/export/bsme/mnt/export/Generic/</targetDirectoryGeneric>

<!-- additional PDF copy directory, leave empty if not needed -->
<pdfCopyNewspapers>/opt/digiverso/export/bsme/mnt/pdf/Newspapers/</pdfCopyNewspapers>
<pdfCopyMagazines>/opt/digiverso/export/bsme/mnt/pdf/Magazines/</pdfCopyMagazines>

<!-- main viewer url -->
<viewerUrl>https://adm.goobi.cloud/viewer/</viewerUrl>>

<!-- configured values to be used inside of the export xml,
can use variable replacer expressions here like e.g.:
- $(meta.CatalogIDDigital)
- $(meta.topstruct.TitleDocMain)
<viewerUrl>https://adm.goobi.cloud/viewer/</viewerUrl>

<!-- 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>
<source>Goobi</source>
<mediaType>$(template.Media Type)</mediaType>
<mediaGroup>$(template.Media Group)</mediaGroup>
<sourceOrganisation>$(template.Source Organization)</sourceOrganisation>
<frequency>$(template.Issue Frequency)</frequency>


<rightsToUse>$(template.Rights to Use)</rightsToUse>
<rightsDetails>$(template.Rights Details)</rightsDetails>
<source>Goobi</source>
<mediaType>$(template.Media Type)</mediaType>
<mediaGroup>$(template.Media Group)</mediaGroup>
<sourceOrganisation>$(template.Source Organization)</sourceOrganisation>
<frequency>$(template.Issue Frequency)</frequency>

<!-- mets parameter -->
<!-- if a field is empty or missing, project configuration is used -->
<metsUrl addFileExtension="true">https://adm.goobi.cloud/viewer/sourcefile?id=</metsUrl>
<resolverUrl>https://adm.goobi.cloud/viewer/piresolver?id=</resolverUrl>
<metsUrl addFileExtension="true">https://adm.goobi.cloud/viewer/sourcefile?id=
</metsUrl>
<resolverUrl>https://adm.goobi.cloud/viewer/piresolver?id=
</resolverUrl>
<metsPointerPath>https://adm.goobi.cloud/viewer/sourcefile?id=$(meta.topstruct.CatalogIDDigital).xml
</metsPointerPath>
<metsPointerPathAnchor>https://adm.goobi.cloud/viewer/sourcefile?id=$(meta.CatalogIDDigital).xml
Expand Down Expand Up @@ -65,11 +72,11 @@
<anchorId>AnchorID</anchorId>
<anchorTitle>AnchorTitle</anchorTitle>
<accessConditionUse>AccessConditionUse</accessConditionUse>
<accessConditionDetails>AccessConditionDetails</accessConditionDetails>
<accessConditionDetails>AccessConditionDetails
</accessConditionDetails>
<frequency>Frequency</frequency>

</metadata>

<docstruct>
<newspaper>Newspaper</newspaper>
<year>Year</year>
Expand All @@ -78,5 +85,5 @@
<issue>NewspaperIssue</issue>
<newspaperStub>NewspaperStub</newspaperStub>
</docstruct>
</config_plugin>

</config_plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -107,4 +109,42 @@ public static String getLanguageFullname(DocStruct ds, String field) {
}
return lang;
}

/**
* convert the date from dd-mm-yyyy to format yyyy-mm-dd and give it back
*
* @param inputDate
* @return
*/
public static String convertDateFormatToDayMonthYear(String inputDate) {
return convertDateFormat(inputDate, "yyyy-MM-dd", "dd-MM-yyyy");
}

/**
* convert the date from yyyy-mm-dd to format dd-mm-yyyy and give it back
*
* @param inputDate
* @return
*/
public static String convertDateFormatToYearMonthDay(String inputDate) {
return convertDateFormat(inputDate, "dd-MM-yyyy", "yyyy-MM-dd");
}

/**
* convert the date from one format to the other
*
* @param inputDate
* @return
*/
private static String convertDateFormat(String inputDate, String inFormat, String outFormat) {
SimpleDateFormat inputFormatter = new SimpleDateFormat(inFormat);
SimpleDateFormat outputFormatter = new SimpleDateFormat(outFormat);

try {
Date date = inputFormatter.parse(inputDate);
return outputFormatter.format(date);
} catch (Exception e) {
return inputDate;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
import org.apache.commons.lang.StringUtils;
import org.goobi.beans.JournalEntry;
import org.goobi.beans.Process;
import org.goobi.production.enums.LogType;
Expand Down Expand Up @@ -49,6 +50,7 @@ public class MagazineExporter {
private DigitalDocument dd;
private String viewerUrl;
private String targetFolder;
private String pdfCopyFolder;

// keep a list of all image files as they need to be renamed
private Map<String, String> fileMap;
Expand All @@ -74,6 +76,7 @@ public MagazineExporter(XMLConfiguration config, Process process, Prefs prefs, D
this.dd = dd;
viewerUrl = config.getString("viewerUrl", "https://viewer.goobi.io");
targetFolder = config.getString("targetDirectoryMagazines", "/opt/digiverso/goobi/output/");
pdfCopyFolder = config.getString("pdfCopyMagazines");
}

/**
Expand Down Expand Up @@ -151,7 +154,11 @@ public boolean startExport() {
issue.addContent(
new Element("issueNumber").setText(AdmBsmeExportHelper.getMetdata(topStruct, config.getString("/metadata/issueNumber"))));
issue.addContent(new Element("issueID").setText(volumeId));
issue.addContent(new Element("issueDate").setText(AdmBsmeExportHelper.getMetdata(topStruct, config.getString("/metadata/dateOfOrigin"))));

// get the date and transform it from dd-mm-yyyy to yyyy-mm-dd
String date = AdmBsmeExportHelper.getMetdata(topStruct, config.getString("/metadata/dateOfOrigin"));
date = AdmBsmeExportHelper.convertDateFormatToYearMonthDay(date);
issue.addContent(new Element("issueDate").setText(date));

// get all title information
String anchorTitle = AdmBsmeExportHelper.getMetdata(anchor, config.getString("/metadata/titleLabel"));
Expand Down Expand Up @@ -309,6 +316,12 @@ public boolean startExport() {
fout = new FileOutputStream(pdfi.getName());
new GetPdfAction().writePdf(map, ContentServerConfiguration.getInstance(), fout);
fout.close();

// if a separate PDF copy shall be stored
if (StringUtils.isNotBlank(pdfCopyFolder)) {
StorageProvider.getInstance().copyFile(Paths.get(pdfi.getName()), Paths.get(pdfCopyFolder, volumeId + ".pdf"));
}

} catch (IOException | ContentLibException e) {
log.error("Error while generating PDF files", e);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Paths;
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.apache.commons.lang.StringUtils;
import org.goobi.beans.JournalEntry;
import org.goobi.beans.Process;
import org.goobi.production.enums.LogType;
Expand All @@ -19,6 +21,7 @@
import org.jdom2.output.XMLOutputter;

import de.sub.goobi.helper.Helper;
import de.sub.goobi.helper.StorageProvider;
import de.sub.goobi.helper.VariableReplacer;
import de.sub.goobi.helper.exceptions.DAOException;
import de.sub.goobi.helper.exceptions.SwapException;
Expand Down Expand Up @@ -50,6 +53,7 @@ public class NewspaperExporter {
private DigitalDocument dd;
private String viewerUrl;
private String targetFolder;
private String pdfCopyFolder;

// keep a list of all image files as they need to be renamed
private Map<String, String> fileMap;
Expand All @@ -76,6 +80,7 @@ public NewspaperExporter(XMLConfiguration config, Process process, Prefs prefs,
this.dd = dd;
viewerUrl = config.getString("viewerUrl", "https://viewer.goobi.io");
targetFolder = config.getString("targetDirectoryNewspapers", "/opt/digiverso/goobi/output/");
pdfCopyFolder = config.getString("pdfCopyNewspapers");
pdfIssues = new ArrayList<>();
}

Expand Down Expand Up @@ -171,10 +176,14 @@ public boolean startExport() {
String issueTitle =
AdmBsmeExportHelper.getCleanIssueLabel(AdmBsmeExportHelper.getMetdata(ds, config.getString("/metadata/titleLabel")));

// convert date from from yyyy-mm-dd to dd-mm-yyyy
String date = AdmBsmeExportHelper.getMetdata(ds, config.getString("/metadata/issueDate"));
date = AdmBsmeExportHelper.convertDateFormatToDayMonthYear(date);

// add an English title
issue.addContent(new Element("issueTitleENG").setText(anchorTitleEng + "-" + issueTitle));
issue.addContent(new Element("issueTitleENG").setText(anchorTitleEng + "-" + date));
// add an Arabic title
issue.addContent(new Element("issueTitleARA").setText(issueTitle + "-" + anchorTitleAra));
issue.addContent(new Element("issueTitleARA").setText(date + "-" + anchorTitleAra));

issue.addContent(new Element("issueDate").setText(AdmBsmeExportHelper.getMetdata(ds, config.getString("/metadata/issueDate"))));
issue.addContent(new Element("Open_In_Viewer").setText(viewerUrl + volumeId + "-" + simpleDate));
Expand Down Expand Up @@ -320,6 +329,13 @@ public boolean startExport() {
fout = new FileOutputStream(pi.getName());
new GetPdfAction().writePdf(map, ContentServerConfiguration.getInstance(), fout);
fout.close();

// if a separate PDF copy shall be stored
if (StringUtils.isNotBlank(pdfCopyFolder)) {
StorageProvider.getInstance()
.copyFile(Paths.get(pi.getName()), Paths.get(pdfCopyFolder, Paths.get(pi.getName()).getFileName().toString()));
}

} catch (IOException | ContentLibException e) {
log.error("Error while generating PDF files", e);
return false;
Expand Down

0 comments on commit f94e124

Please sign in to comment.