Skip to content

Commit

Permalink
finished Magazine work
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenHankiewicz committed May 19, 2024
1 parent 24a4f41 commit fbf93ab
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public static String getMetdata(DocStruct ds, String field) {
}

/**
* extremely simple translation method to convert German issue labes into pseudo english labels
* extremely simple method to remove Ausgabe or Issue Information from title of an issue
*
* @param value
* @return
*/
public static String getTranslatedIssueLabels(String value) {
public static String getCleanIssueLabel(String value) {
String copy = value;
copy = copy.replace("Ausgabe vom", "");
copy = copy.replace("Issue from", "");
copy = copy.replace("Ausgabe vom ", "");
copy = copy.replace("Issue from ", "");
return copy;
}

Expand All @@ -72,6 +72,20 @@ public static String getEnglishPartOfString(String value) {
return copy;
}

/**
* get Arabic part of a metadata that is separated from English part
*
* @param value
* @return
*/
public static String getArabicPartOfString(String value) {
String copy = value.replace("–", "-");
if (copy.contains("-")) {
copy = StringUtils.substringBefore(copy, "-").trim();
}
return copy;
}

/**
* get the language from metadata
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand All @@ -13,12 +14,14 @@
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.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;
Expand Down Expand Up @@ -131,9 +134,11 @@ public boolean startExport() {
if (process.getJournal() != null) {
Element technicalNotes = new Element("Technical_Notes");
for (JournalEntry je : process.getJournal()) {
technicalNotes.addContent(new Element("Entry").setAttribute("date", je.getFormattedCreationDate())
.setAttribute("type", je.getType().getTitle())
.setText(je.getFormattedContent()));
if (je.getType() == LogType.USER) {
technicalNotes.addContent(new Element("Entry").setAttribute("date", je.getFormattedCreationDate())
.setAttribute("type", je.getType().getTitle())
.setText(je.getFormattedContent()));
}
}
volume.addContent(technicalNotes);
} else {
Expand All @@ -147,6 +152,19 @@ public boolean startExport() {
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 all title information
String anchorTitle = AdmBsmeExportHelper.getMetdata(anchor, config.getString("/metadata/titleLabel"));
String anchorTitleEng = AdmBsmeExportHelper.getEnglishPartOfString(anchorTitle);
String anchorTitleAra = AdmBsmeExportHelper.getArabicPartOfString(anchorTitle);
String issueTitle =
AdmBsmeExportHelper.getCleanIssueLabel(AdmBsmeExportHelper.getMetdata(topStruct, config.getString("/metadata/titleLabel")));

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

issue.addContent(new Element("Open_In_Viewer").setText(viewerUrl + volumeId));
volume.addContent(new Element("Barcode").setText(volumeId));
issue.addContent(new Element("issueFile").setText(volumeId + ".pdf").setAttribute("Format", "application/pdf"));
Expand Down Expand Up @@ -240,7 +258,7 @@ public boolean startExport() {
// write the xml file
XMLOutputter xmlOutputter = new XMLOutputter();
xmlOutputter.setFormat(Format.getPrettyFormat());
File xmlfile = new File(targetFolder + volumeId + ".xml");
File xmlfile = new File(targetFolder + volumeId + "-simple.xml");
try (FileOutputStream fileOutputStream = new FileOutputStream(xmlfile)) {
xmlOutputter.output(doc, fileOutputStream);
} catch (IOException e) {
Expand All @@ -253,13 +271,31 @@ public boolean startExport() {
AdmBsmeExportHelper.copyFolderContent(process.getImagesOrigDirectory(false), "tif", fileMap, targetFolder);
AdmBsmeExportHelper.copyFolderContent(process.getOcrAltoDirectory(), "xml", fileMap, targetFolder);
AdmBsmeExportHelper.copyFolderContent(process.getOcrTxtDirectory(), "txt", fileMap, targetFolder);
StorageProviderInterface sp = StorageProvider.getInstance();

// rename the regular METS file
StorageProvider.getInstance()
.renameTo(Paths.get(targetFolder, process.getTitel() + ".xml"), Paths.get(targetFolder, volumeId + "-mets.xml").toString());
Path pmets = Paths.get(targetFolder, volumeId + "-mets.xml");
if (sp.isFileExists(pmets)) {
sp.deleteFile(pmets);
}
sp.renameTo(Paths.get(targetFolder, process.getTitel() + ".xml"), pmets.toString());

// rename the regular anchor METS file
StorageProvider.getInstance()
.renameTo(Paths.get(targetFolder, process.getTitel() + "_anchor.xml"),
Paths.get(targetFolder, volumeId + "-mets_anchor.xml").toString());
Path panchor = Paths.get(targetFolder, volumeId + "-mets_anchor.xml");
if (sp.isFileExists(panchor)) {
sp.deleteFile(panchor);
}
sp.renameTo(Paths.get(targetFolder, process.getTitel() + "_anchor.xml"),
panchor.toString());

// rename the simple xml file
Path psimple = Paths.get(targetFolder, volumeId + ".xml");
if (sp.isFileExists(psimple)) {
sp.deleteFile(psimple);
}
sp.renameTo(Paths.get(targetFolder, volumeId + "-simple.xml"),
psimple.toString());

} catch (IOException | SwapException | DAOException e) {
log.error("Error while copying the image files to export folder", e);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;
Expand Down Expand Up @@ -141,9 +142,11 @@ public boolean startExport() {
if (process.getJournal() != null) {
Element technicalNotes = new Element("Technical_Notes");
for (JournalEntry je : process.getJournal()) {
technicalNotes.addContent(new Element("Entry").setAttribute("date", je.getFormattedCreationDate())
.setAttribute("type", je.getType().getTitle())
.setText(je.getFormattedContent()));
if (je.getType() == LogType.USER) {
technicalNotes.addContent(new Element("Entry").setAttribute("date", je.getFormattedCreationDate())
.setAttribute("type", je.getType().getTitle())
.setText(je.getFormattedContent()));
}
}
volume.addContent(technicalNotes);
} else {
Expand All @@ -161,14 +164,17 @@ public boolean startExport() {
issue.addContent(new Element("issueID").setText(volumeId + "-" + simpleDate));
issue.addContent(new Element("issueFrequency").setText(frequency));

// get the anchor title and leave the english part of the title
String issueTitlePrefix = AdmBsmeExportHelper.getMetdata(anchor, config.getString("/metadata/titleLabel"));
issueTitlePrefix = AdmBsmeExportHelper.getEnglishPartOfString(issueTitlePrefix);
// get the issue title
// get all title information
String anchorTitle = AdmBsmeExportHelper.getMetdata(anchor, config.getString("/metadata/titleLabel"));
String anchorTitleEng = AdmBsmeExportHelper.getEnglishPartOfString(anchorTitle);
String anchorTitleAra = AdmBsmeExportHelper.getArabicPartOfString(anchorTitle);
String issueTitle =
AdmBsmeExportHelper.getTranslatedIssueLabels(AdmBsmeExportHelper.getMetdata(ds, config.getString("/metadata/titleLabel")));
// put prefix and title together
issue.addContent(new Element("issueTitle").setText(issueTitlePrefix + issueTitle));
AdmBsmeExportHelper.getCleanIssueLabel(AdmBsmeExportHelper.getMetdata(ds, config.getString("/metadata/titleLabel")));

// add an English title
issue.addContent(new Element("issueTitleENG").setText(anchorTitleEng + "-" + issueTitle));
// add an Arabic title
issue.addContent(new Element("issueTitleARA").setText(issueTitle + "-" + 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
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,15 @@ public boolean exportMetsFile() throws IOException, WriteException, PreferencesE

// EITHER: add the anchor label as prefix in front of each issue
String englishNewspaperName = AdmBsmeExportHelper.getEnglishPartOfString(titleLabel);
md.setValue(englishNewspaperName + " " + AdmBsmeExportHelper.getTranslatedIssueLabels(md.getValue()));
md.setValue(englishNewspaperName + " " + AdmBsmeExportHelper.getCleanIssueLabel(md.getValue()));

// OR: use original title (incl. arabic font)
// md.setValue(titleLabel + " " + getTranslatedIssueLabels(md.getValue()));

issueLabel = md.getValue();
}
if (md.getType().getName().equals(mainTitleType.getName())) {
md.setValue(AdmBsmeExportHelper.getTranslatedIssueLabels(md.getValue()));
md.setValue(AdmBsmeExportHelper.getCleanIssueLabel(md.getValue()));
issueTitle = md.getValue();
}
if (md.getType().getName().equals(issueNumberType.getName())) {
Expand Down

0 comments on commit fbf93ab

Please sign in to comment.