Skip to content

Commit

Permalink
added magazine export
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenHankiewicz committed May 4, 2024
1 parent 5a61238 commit ff6b0bb
Show file tree
Hide file tree
Showing 4 changed files with 427 additions and 138 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package de.intranda.goobi.plugins;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;

import de.sub.goobi.helper.StorageProvider;
import ugh.dl.DocStruct;
import ugh.dl.Metadata;

public class AdmBsmeExportHelper {

/**
* copy files to target directory
*
* @param ds
* @throws IOException
*/
public static void copyFolderContent(String sourcefolder, String ext, Map<String, String> fileMap, String targetFolder) throws IOException {
for (Path pathIn : StorageProvider.getInstance().listFiles(sourcefolder)) {
String fileIn = pathIn.getFileName().toString();
fileIn = fileIn.substring(0, fileIn.indexOf("."));
String fileOut = fileMap.get(fileIn);
Path pathOut = Paths.get(targetFolder, fileOut + "." + ext);
// log.debug(pathIn + " ---> " + pathOut);
StorageProvider.getInstance().copyFile(pathIn, pathOut);
}
}

/**
* get a specific metadata from given docstruct
*
* @param ds
*/
public static String getMetdata(DocStruct ds, String field) {
// run through all metadata to find the right one
for (Metadata md : ds.getAllMetadata()) {
if (md.getType().getName().equals(field)) {
return md.getValue();
}
}
return "";
}

/**
* get the language from metadata
*
* @param ds
*/
public static String getLanguageFullname(DocStruct ds, String field) {
String lang = getMetdata(ds, field);
switch (lang) {
case "Arabic":
return "عربي – Arabic";
case "ara":
return "عربي – Arabic";
case "English":
return "انجليزي – English";
case "eng":
return "انجليزي – English";
case "ger":
return "German";
}
return lang;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.goobi.beans.Process;
import org.goobi.production.enums.LogType;
import org.goobi.production.enums.PluginType;
import org.goobi.production.plugin.interfaces.IExportPlugin;
import org.goobi.production.plugin.interfaces.IPlugin;

import de.sub.goobi.config.ConfigPlugins;
import de.sub.goobi.export.dms.ExportDms;
import de.sub.goobi.helper.Helper;
import de.sub.goobi.helper.exceptions.DAOException;
import de.sub.goobi.helper.exceptions.ExportFileException;
import de.sub.goobi.helper.exceptions.SwapException;
Expand All @@ -34,75 +35,84 @@
@Log4j2
public class AdmBsmeExportPlugin implements IExportPlugin, IPlugin {

@Getter
private String title = "intranda_export_adm_bsme";
@Getter
private PluginType type = PluginType.Export;

@Getter
private List<String> problems;

@Override
public void setExportFulltext(boolean arg0) {
}

@Override
public void setExportImages(boolean arg0) {
}

@Override
public boolean startExport(Process process) throws IOException, InterruptedException, DocStructHasNoTypeException,
PreferencesException, WriteException, MetadataTypeNotAllowedException, ExportFileException,
UghHelperException, ReadException, SwapException, DAOException, TypeNotAllowedForParentException {
String benutzerHome = process.getProjekt().getDmsImportImagesPath();
return startExport(process, benutzerHome);
}

/**
* Main export function
*/
@Override
public boolean startExport(Process process, String destination)
throws IOException, InterruptedException, DocStructHasNoTypeException, PreferencesException, WriteException,
MetadataTypeNotAllowedException, ExportFileException, UghHelperException, ReadException, SwapException,
DAOException, TypeNotAllowedForParentException {
problems = new ArrayList<>();

// read mets file
try {
Prefs prefs = process.getRegelsatz().getPreferences();
Fileformat ff = null;
ff = process.readMetadataFile();
DigitalDocument dd = ff.getDigitalDocument();
DocStruct topStruct = dd.getLogicalDocStruct();

// if it is a NewspaperVolume do the Newspaper-Export
if (topStruct.getType().getName().equals("Newspaper")) {
NewspaperExporter ne = new NewspaperExporter(ConfigPlugins.getPluginConfig(title), process, prefs, dd);
ne.startExport();
} else {
// do a regular export here
IExportPlugin export = new ExportDms();
export.setExportFulltext(true);
export.setExportImages(true);

// execute the export and check the success
boolean success = export.startExport(process);
if (!success) {
log.error("Export aborted for process with ID " + process.getId());
} else {
log.info("Export executed for process with ID " + process.getId());
}

}

} catch (ReadException | PreferencesException | IOException | SwapException e) {
problems.add("Cannot read metadata file.");
log.error("Export aborted for process with ID " + process.getId(), e);
return false;
}

return true;
}
@Getter
private String title = "intranda_export_adm_bsme";
@Getter
private PluginType type = PluginType.Export;

@Getter
private List<String> problems;

@Override
public void setExportFulltext(boolean arg0) {
}

@Override
public void setExportImages(boolean arg0) {
}

@Override
public boolean startExport(Process process) throws IOException, InterruptedException, DocStructHasNoTypeException,
PreferencesException, WriteException, MetadataTypeNotAllowedException, ExportFileException,
UghHelperException, ReadException, SwapException, DAOException, TypeNotAllowedForParentException {
String benutzerHome = process.getProjekt().getDmsImportImagesPath();
return startExport(process, benutzerHome);
}

/**
* Main export function
*/
@Override
public boolean startExport(Process process, String destination)
throws IOException, InterruptedException, DocStructHasNoTypeException, PreferencesException, WriteException,
MetadataTypeNotAllowedException, ExportFileException, UghHelperException, ReadException, SwapException,
DAOException, TypeNotAllowedForParentException {
problems = new ArrayList<>();
boolean success = true;

// read mets file
try {
Prefs prefs = process.getRegelsatz().getPreferences();
Fileformat ff = null;
ff = process.readMetadataFile();
DigitalDocument dd = ff.getDigitalDocument();
DocStruct topStruct = dd.getLogicalDocStruct();

if ("Newspaper".equals(topStruct.getType().getName())) {
// if it is a NewspaperVolume do the Newspaper-Export
NewspaperExporter ne = new NewspaperExporter(ConfigPlugins.getPluginConfig(title), process, prefs, dd);
success = ne.startExport();
} else {

// do a regular export
IExportPlugin export = new ExportDms();
export.setExportFulltext(false);
export.setExportImages(false);
success = export.startExport(process);

// for magazines do a specific export
if (success && "Periodical".equals(topStruct.getType().getName())) {
// if it is a Magazine
MagazineExporter me = new MagazineExporter(ConfigPlugins.getPluginConfig(title), process, prefs, dd);
success = me.startExport();
}

}

} catch (ReadException | PreferencesException | IOException | SwapException e) {
problems.add("Export aborted for process with ID: " + e.getMessage());
Helper.addMessageToProcessJournal(process.getId(), LogType.ERROR, "Export aborte because of an unexpected exception: " + e.getMessage());
log.error("Export aborted for process with ID " + process.getId(), e);
return false;
}

if (!success) {
log.error("Export aborted for process with ID " + process.getId());
} else {
log.info("Export executed for process with ID " + process.getId());
}

return success;
}

}
Loading

0 comments on commit ff6b0bb

Please sign in to comment.