diff --git a/pom.xml b/pom.xml index e274d4f..ffc039d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 de.ulb digital-derivans - 1.9.8 + 1.10.8 Universität- und Landesbibliothek Sachsen-Anhalt diff --git a/src/main/java/de/ulb/digital/derivans/Derivans.java b/src/main/java/de/ulb/digital/derivans/Derivans.java index 181a394..b0b5357 100644 --- a/src/main/java/de/ulb/digital/derivans/Derivans.java +++ b/src/main/java/de/ulb/digital/derivans/Derivans.java @@ -148,7 +148,6 @@ public List init(List steps) throws DigitalDerivansEx String pdfALevel = DefaultConfiguration.PDFA_CONFORMANCE_LEVEL; pdfStep.setConformanceLevel(pdfALevel); pdfStep.setDebugRender(config.isDebugPdfRender()); - pdfStep.setNamePDF(this.config.getNamePDF()); DescriptiveData descriptiveData = new DescriptiveData(); if (this.optMetadataStore.isPresent()) { var store = this.optMetadataStore.get(); diff --git a/src/main/java/de/ulb/digital/derivans/config/DerivansConfiguration.java b/src/main/java/de/ulb/digital/derivans/config/DerivansConfiguration.java index 1ac5a80..c9543bd 100644 --- a/src/main/java/de/ulb/digital/derivans/config/DerivansConfiguration.java +++ b/src/main/java/de/ulb/digital/derivans/config/DerivansConfiguration.java @@ -55,8 +55,6 @@ public class DerivansConfiguration { private Optional paramOCR = Optional.empty(); - private Optional paramNamePDF = Optional.empty(); - private Integer quality = DefaultConfiguration.DEFAULT_QUALITY; private Integer poolsize = DefaultConfiguration.DEFAULT_POOLSIZE; @@ -109,7 +107,7 @@ public DerivansConfiguration(DerivansParameter params) throws DigitalDerivansExc this.pathDir = input.getParent(); } - // set configuration file for later examination + // set configuration file if (params.getPathConfig() != null) { LOGGER.debug("inspect cli config file {}", params.getPathConfig()); this.pathConfigFile = params.getPathConfig(); @@ -126,18 +124,43 @@ public DerivansConfiguration(DerivansParameter params) throws DigitalDerivansExc this.initConfigurationFromFile(); } } - // inspect pdf name present - if(params.getNamePDF() != null) { - this.paramNamePDF = Optional.of(params.getNamePDF()); - } - - // take care if no config provided + + // take care if no configuration file provided if (derivateSteps.isEmpty()) { provideDefaultSteps(); LOGGER.warn("no config read, use fallback with {} steps", this.derivateSteps.size()); } LOGGER.info("use config with {} steps", this.derivateSteps.size()); LOGGER.debug("first step inputs from '{}'", this.derivateSteps.get(0).getInputPath()); + + // inspect parameters which *might* override + // any previously configured settings + if(params.getNamePDF() != null) { + var pdfStep = this.pick(DerivateType.PDF); + var pdfName = params.getNamePDF(); + if(pdfStep.isPresent()) { + ((DerivateStepPDF) pdfStep.get()).setNamePDF(pdfName); + LOGGER.info("force PDF name {}", pdfName); + } else { + LOGGER.warn("refuse to set {} - no PDF step present", pdfName); + } + } + if(params.getPathFooter() != null) { + var newTemplate = params.getPathFooter(); + var theStep = this.pick(DerivateType.JPG_FOOTER); + if (theStep.isPresent()) { + if (!newTemplate.isAbsolute()) { + newTemplate = this.pathConfigFile.getParent().resolve(newTemplate); + } + DerivateStepImageFooter footerStep = (DerivateStepImageFooter) theStep.get(); + var footerPrev = footerStep.getPathTemplate(); + LOGGER.info("force footer template {} with {}", + footerPrev, newTemplate); + footerStep.setPathTemplate(newTemplate); + } else { + LOGGER.warn("refuse to set {} - no footer step present", newTemplate); + } + } } private void initConfigurationFromFile() throws DigitalDerivansException { @@ -582,7 +605,15 @@ public boolean isDebugPdfRender() { return this.debugPdfRender; } - public Optional getNamePDF() { - return this.paramNamePDF; + /** + * + * Pick first step with matching {@link DerivateType} + * + * @param type + * @return + */ + private Optional pick(DerivateType type) { + return this.derivateSteps.stream() + .filter(s -> s.getDerivateType() == type).findFirst(); } } diff --git a/src/main/java/de/ulb/digital/derivans/config/DerivansParameter.java b/src/main/java/de/ulb/digital/derivans/config/DerivansParameter.java index 7c13a81..2862546 100644 --- a/src/main/java/de/ulb/digital/derivans/config/DerivansParameter.java +++ b/src/main/java/de/ulb/digital/derivans/config/DerivansParameter.java @@ -11,9 +11,7 @@ /** * - * Application Parameters. - * - * Can be set global on CLI-level. + * Application Parameters on CLI-level. * * @author hartwig * @@ -57,6 +55,13 @@ public class DerivansParameter { "(No default).\n") private String namePDF; + + @Option(name = "-f", aliases = { "--footer" }, required = false, usage = "Path to footer template file.\n" + + "Determine absolute path to used footer image file.\n" + + "Overwrites default footer setting if exists.\n" + + "(No default).\n") + private Path pathFooter; + /** * * Set specific Parser Information @@ -115,4 +120,12 @@ public Boolean getDebugPdfRender() { } return debugPdfRender; } + + public Path getPathFooter(){ + return this.pathFooter; + } + + public void setPathFooter(Path pathFooter) { + this.pathFooter = pathFooter; + } } diff --git a/src/main/java/de/ulb/digital/derivans/model/step/DerivateStepPDF.java b/src/main/java/de/ulb/digital/derivans/model/step/DerivateStepPDF.java index e3396f1..bca446b 100644 --- a/src/main/java/de/ulb/digital/derivans/model/step/DerivateStepPDF.java +++ b/src/main/java/de/ulb/digital/derivans/model/step/DerivateStepPDF.java @@ -157,8 +157,8 @@ public Optional getNamePDF() { return this.optNamePDF; } - public void setNamePDF(Optional optNamePDF) { - this.optNamePDF = optNamePDF; + public void setNamePDF(String optNamePDF) { + this.optNamePDF = Optional.of(optNamePDF); } /** diff --git a/src/test/java/de/ulb/digital/derivans/TestDerivansArguments.java b/src/test/java/de/ulb/digital/derivans/TestDerivansArguments.java index 8e71f75..85f93a7 100644 --- a/src/test/java/de/ulb/digital/derivans/TestDerivansArguments.java +++ b/src/test/java/de/ulb/digital/derivans/TestDerivansArguments.java @@ -1,13 +1,13 @@ package de.ulb.digital.derivans; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.StandardOpenOption; import java.util.Comparator; import java.util.List; @@ -22,6 +22,9 @@ import de.ulb.digital.derivans.config.DerivansParameter; import de.ulb.digital.derivans.derivate.IDerivateer; import de.ulb.digital.derivans.model.step.DerivateStep; +import de.ulb.digital.derivans.model.step.DerivateStepImageFooter; +import de.ulb.digital.derivans.model.step.DerivateStepPDF; +import de.ulb.digital.derivans.model.step.DerivateType; /** * @@ -40,8 +43,11 @@ public class TestDerivansArguments { private static final String NAME_PDF = "the-name-of-the"; + private static final String NAME_PDF_FILE = NAME_PDF + ".pdf"; + private static final String NAME_TEMPLATE = "footer_template_without_dfg_logo.png"; + @TempDir static Path tempDir; @@ -74,17 +80,18 @@ public static void setupBeforeClass() throws Exception { dp.setPathConfig(configTargetDir.resolve("derivans-5steps.ini")); dp.setPathInput(workDir.resolve("737429.xml")); dp.setNamePDF(NAME_PDF); + dp.setPathFooter(configTargetDir.resolve(NAME_TEMPLATE)); DerivansConfiguration dc = new DerivansConfiguration(dp); Derivans derivans = new Derivans(dc); // act derivans.create(); derivateers = derivans.getDerivateers(); - // steps = derivans.getSteps(); + steps = derivans.getSteps(); } @Test - void testPDFWritten() throws Exception { + void testPDFWritten() { Path pdfWritten = workDir.resolve(NAME_PDF_FILE); assertTrue(Files.exists(pdfWritten)); } @@ -110,4 +117,103 @@ void testMETSUpdateSuccess() throws Exception { assertEquals(pdfMark, firstChild.getAttribute("FILEID").getValue()); } + @Test + void testStepPDFLabel() { + DerivateStep theStep = steps.stream() + .filter(s -> s.getDerivateType() == DerivateType.PDF) + .findFirst() + .get(); + assertEquals(DerivateType.PDF, theStep.getDerivateType()); + var footerStep = (DerivateStepPDF) theStep; + assertEquals(NAME_PDF, footerStep.getNamePDF().get()); + } + + @Test + void testStepFooter() { + DerivateStep theStep = steps.stream() + .filter(s -> s.getDerivateType() == DerivateType.JPG_FOOTER) + .findFirst() + .get(); + assertEquals(DerivateType.JPG_FOOTER, theStep.getDerivateType()); + var footerStep = (DerivateStepImageFooter) theStep; + assertEquals(NAME_TEMPLATE, footerStep.getPathTemplate().getFileName().toString()); + } + + /** + * + * Simulate scenario with condfigured XPath identifier + * which preceedes default ULB PDF label (from mods:identifier@type=gbv) + * + */ + @Test + void testConfiguredXPathUsed(@TempDir Path tmpDir) throws Exception { + var thisRoot = tmpDir.resolve("forceNameXPath"); + Files.createDirectories(thisRoot); + var thisDir = TestHelper.fixturePrint737429(thisRoot); + + // arrange configuration + // migration configuration with extended derivates + Path configSourceDir = Path.of("src/test/resources/config"); + Path configTargetDir = thisDir.resolve("config"); + TestHelper.copyTree(configSourceDir, configTargetDir); + + // alter config + var pathConfig = configTargetDir.resolve("derivans.ini"); + var identConfLine = "mods_identifier_xpath = //mods:mods/mods:titleInfo/mods:title"; + Files.writeString(pathConfig, identConfLine + System.lineSeparator(), StandardOpenOption.APPEND); + + DerivansParameter dp = new DerivansParameter(); + dp.setPathConfig(pathConfig); + dp.setPathInput(thisDir.resolve("737429.xml")); + DerivansConfiguration dc = new DerivansConfiguration(dp); + Derivans derivans = new Derivans(dc); + + // act + derivans.create(); + + // assert + var optPdf = Files.list(thisDir) + .filter(p -> p.getFileName().toString().endsWith(".pdf")).findFirst(); + assertTrue(optPdf.isPresent()); + assertTrue(optPdf.get().getFileName().toString().startsWith("Ode_In_Solemni_")); + } + + /** + * + * Simulate scenario with condfigured XPath identifier and + * additional param fpr PDF name => ensure the value from + * CLI overrides configured value + * + */ + @Test + void testConfiguredXPathCollidesWithParam(@TempDir Path tmpDir) throws Exception { + var thisRoot = tmpDir.resolve("forceNameCLI"); + Files.createDirectories(thisRoot); + var thisDir = TestHelper.fixturePrint737429(thisRoot); + + // arrange configuration + // migration configuration with extended derivates + Path configSourceDir = Path.of("src/test/resources/config"); + Path configTargetDir = thisDir.resolve("config"); + TestHelper.copyTree(configSourceDir, configTargetDir); + + // alter config + var pathConfig = configTargetDir.resolve("derivans.ini"); + var identConfLine = "mods_identifier_xpath = //mods:mods/mods:titleInfo/mods:title"; + Files.writeString(pathConfig, identConfLine + System.lineSeparator(), StandardOpenOption.APPEND); + + DerivansParameter dp = new DerivansParameter(); + dp.setPathConfig(pathConfig); + dp.setPathInput(thisDir.resolve("737429.xml")); + dp.setNamePDF(NAME_PDF); + DerivansConfiguration dc = new DerivansConfiguration(dp); + Derivans derivans = new Derivans(dc); + + // act + derivans.create(); + + // assert + Path pdfWritten = thisDir.resolve(NAME_PDF_FILE); + assertTrue(Files.exists(pdfWritten)); + } } diff --git a/src/test/resources/config/footer_template_without_dfg_logo.png b/src/test/resources/config/footer_template_without_dfg_logo.png new file mode 100644 index 0000000..ad093b4 Binary files /dev/null and b/src/test/resources/config/footer_template_without_dfg_logo.png differ