Skip to content

Commit

Permalink
changed export configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rsehr committed Aug 22, 2024
1 parent 3f5d192 commit 1fe2aef
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 37 deletions.
17 changes: 7 additions & 10 deletions install/plugin_intranda_administration_archive_management.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<config_plugin>
<export>
<!-- export folder -->
<folder>/opt/digiverso/viewer/hotfolder</folder>

<!-- record group to export. Use the database names.
The generated file name is the same as the name in goobi, spaces are replaced with underscore,
'.xml' is added, if extensiion is missing.
-->
<file>112236_hub_edit.xml</file>
<file>2215.xml</file>
<file>EAD_Export_Koch_Foto_DDB_EAD.XML.xml</file>
<file name="112236_hub_edit.xml">
<folder>/opt/digiverso/sammlungen-digital/hotfolder/</folder>
</file>
<file name="2215.xml">
<folder>/opt/digiverso/sammlungen-digital/hotfolder/</folder>
<folder>/opt/digiverso/archiv-viewer/hotfolder/</folder>
</file>
</export>

<backup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import de.sub.goobi.helper.Helper;
import de.sub.goobi.helper.ProcessTitleGenerator;
import de.sub.goobi.helper.ScriptThreadWithoutHibernate;
import de.sub.goobi.helper.StorageProvider;
import de.sub.goobi.helper.XmlTools;
import de.sub.goobi.helper.enums.ManipulationType;
import de.sub.goobi.helper.enums.StepStatus;
Expand Down Expand Up @@ -301,7 +302,7 @@ public class ArchiveManagementAdministrationPlugin implements IArchiveManagement
private List<String> inventoryList = new ArrayList<>();

@Getter
private String exportFolder;
private Map<String, List<String>> exportConfiguration;

private transient VocabularyAPIManager vocabularyAPI = null;

Expand Down Expand Up @@ -393,6 +394,7 @@ public String checkDBConnection() {

@Override
public List<String> getPossibleDatabases() {
readConfiguration();
List<IRecordGroup> allRecordGroups = getRecordGroups();

List<String> databases = new ArrayList<>();
Expand Down Expand Up @@ -788,7 +790,15 @@ public void readConfiguration() {
}
}

exportFolder = xmlConfig.getString("/export/folder");
exportConfiguration = new HashMap<>();

List<HierarchicalConfiguration> subconfig = xmlConfig.configurationsAt("/export/file");

for (HierarchicalConfiguration hc : subconfig) {
String filename = hc.getString("@name");
List<String> exportFolders = Arrays.asList(hc.getStringArray("/folder"));
exportConfiguration.put(filename, exportFolders);
}

nameSpaceRead = Namespace.getNamespace("ead", config.getString("/eadNamespaceRead", "urn:isbn:1-931666-22-9"));
nameSpaceWrite = Namespace.getNamespace("ead", config.getString("/eadNamespaceWrite", "urn:isbn:1-931666-22-9"));
Expand Down Expand Up @@ -3062,22 +3072,38 @@ public boolean isReadOnlyModus() {
}

public void eadExport() {
if (StringUtils.isBlank(exportFolder)) {
List<String> exportFolders = exportConfiguration.get(databaseName);
if (exportFolders == null || exportFolders.isEmpty()) {
Helper.setFehlerMeldung("plugin_administration_archive_eadExportNotConfigured");
databaseName = null;
return;
}

Path downloadFile = Paths.get(exportFolder, databaseName.replace(" ", "_"));
Document document = createEadFile();
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
try {
outputter.output(document, Files.newOutputStream(downloadFile));
} catch (IOException e) {
log.error(e);

for (String exportFolder : exportFolders) {
Path folder = Paths.get(exportFolder);
if (!StorageProvider.getInstance().isFileExists(folder)) {
try {
StorageProvider.getInstance().createDirectories(folder);
} catch (IOException e) {
log.error(e);
}
}

Path downloadFile = Paths.get(exportFolder, databaseName.replace(" ", "_"));
try {
outputter.output(document, Files.newOutputStream(downloadFile));
} catch (IOException e) {
log.error(e);
}
}
}

public void eadExportFrommOverview() {
readConfiguration();
recordGroup = ArchiveManagementManager.getRecordGroupByTitle(databaseName);
eadExport();
databaseName = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
</h:commandLink>
<h:commandLink
rendered="#{!AdministrationForm.administrationPlugin.readOnlyModus}"
styleClass="btn btn-blank #{AdministrationForm.administrationPlugin.readOnlyModus ? 'disabled' : ''}"
styleClass="btn btn-blank #{AdministrationForm.administrationPlugin.getExportConfiguration().get(db) == null ? 'disabled' : ''}"
type="submit"
action="#{AdministrationForm.administrationPlugin.eadExportFrommOverview}"
disabled="#{AdministrationForm.administrationPlugin.readOnlyModus}">
Expand Down
44 changes: 26 additions & 18 deletions module-job/src/main/java/io/goobi/api/job/ExportEadFileJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
Expand All @@ -26,9 +30,7 @@
@Log4j2
public class ExportEadFileJob extends AbstractGoobiJob {

private String exportFolder;

private List<String> filesToExport;
private Map<String, List<String>> exportConfiguration;

/**
* When called, this method gets executed
Expand All @@ -44,24 +46,26 @@ public void execute() {

log.debug("Export configured ead files");

if (filesToExport != null && !filesToExport.isEmpty()) {
for (Entry<String, List<String>> entry : exportConfiguration.entrySet()) {

// initialize plugin

IPlugin p = PluginLoader.getPluginByTitle(PluginType.Administration, "intranda_administration_archive_management");
IArchiveManagementAdministrationPlugin archive = (IArchiveManagementAdministrationPlugin) p;

for (String file : filesToExport) {
// load record from database
archive.setDatabaseName(file);
archive.loadSelectedDatabase();
String file = entry.getKey();
// load record from database
archive.setDatabaseName(file);
archive.loadSelectedDatabase();

// write document to servlet output stream
if (!file.endsWith(".xml")) {
file = file + ".xml";
}
// write document to servlet output stream
if (!file.endsWith(".xml")) {
file = file + ".xml";
}
Document document = archive.createEadFile();
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
for (String exportFolder : entry.getValue()) {
Path downloadFile = Paths.get(exportFolder, file.replace(" ", "_"));
Document document = archive.createEadFile();
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
try {
outputter.output(document, Files.newOutputStream(downloadFile));
} catch (IOException e) {
Expand Down Expand Up @@ -96,11 +100,15 @@ public void parseConfiguration() {
xmlConfig.setReloadingStrategy(new FileChangedReloadingStrategy());
xmlConfig.setExpressionEngine(new XPathExpressionEngine());

// get folder from configuration file
exportFolder = xmlConfig.getString("/export/folder");
exportConfiguration = new HashMap<>();

List<HierarchicalConfiguration> subconfig = xmlConfig.configurationsAt("/export/file");

// check which files shall be exported
filesToExport = Arrays.asList(xmlConfig.getStringArray("/export/file"));
for (HierarchicalConfiguration hc : subconfig) {
String filename = hc.getString("@name");
List<String> exportFolders = Arrays.asList(hc.getStringArray("/folder"));
exportConfiguration.put(filename, exportFolders);
}

} catch (ConfigurationException e2) {
log.error(e2);
Expand Down

0 comments on commit 1fe2aef

Please sign in to comment.