Skip to content

Commit

Permalink
[app][fix] propagate debug flag
Browse files Browse the repository at this point in the history
  • Loading branch information
M3ssman committed Jan 5, 2024
1 parent c691aac commit d49f9be
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 95 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.ulb</groupId>
<artifactId>digital-derivans</artifactId>
<version>1.8.6</version>
<version>1.8.7</version>

<organization>
<name>Universität- und Landesbibliothek Sachsen-Anhalt</name>
Expand Down
111 changes: 56 additions & 55 deletions src/main/java/de/ulb/digital/derivans/Derivans.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class Derivans {

List<DerivateStep> steps;

List<IDerivateer> derivateers;
List<IDerivateer> derivateers;

private Path processDir;

Expand Down Expand Up @@ -129,24 +129,25 @@ public List<IDerivateer> init(List<DerivateStep> steps) throws DigitalDerivansEx
DigitalFooter footer = new DigitalFooter(footerLabel, getIdentifier(), pathTemplate);
Integer quality = stepFooter.getQuality();
ImageDerivateerJPGFooter d = new ImageDerivateerJPGFooter(input, output, footer, pages, quality);
if (this.optMetadataStore.isPresent()) {
var store = this.optMetadataStore.get();
var mdsPages = store.getDigitalPagesInOrder();
var storeLabel = store.usedStore();
if (isGranularIdentifierPresent(mdsPages)) {
LOGGER.debug("detected granular URN at {}", storeLabel);
var enrichedPages = enrichGranularURN(pages, mdsPages);
d = new ImageDerivateerJPGFooterGranular(d, quality);
d.setDigitalPages(enrichedPages);
}
}
if (this.optMetadataStore.isPresent()) {
var store = this.optMetadataStore.get();
var mdsPages = store.getDigitalPagesInOrder();
var storeLabel = store.usedStore();
if (isGranularIdentifierPresent(mdsPages)) {
LOGGER.debug("detected granular URN at {}", storeLabel);
var enrichedPages = enrichGranularURN(pages, mdsPages);
d = new ImageDerivateerJPGFooterGranular(d, quality);
d.setDigitalPages(enrichedPages);
}
}
d.setResolver(this.resolver);
derivateers.add(d);

} else if (type == DerivateType.PDF) {
DerivateStepPDF pdfStep = (DerivateStepPDF) step;
String pdfALevel = DefaultConfiguration.PDFA_CONFORMANCE_LEVEL;
pdfStep.setConformanceLevel(pdfALevel);
pdfStep.setDebugRender(config.isDebugPdfRender());
DescriptiveData descriptiveData = new DescriptiveData();
if (this.optMetadataStore.isPresent()) {
var store = this.optMetadataStore.get();
Expand All @@ -166,8 +167,8 @@ public List<IDerivateer> init(List<DerivateStep> steps) throws DigitalDerivansEx
Path pdfPath = resolver.calculatePDFPath(descriptiveData, step);
LOGGER.info("calculate local pdf derivate path '{}'", pdfPath);
output.setPath(pdfPath);
// required for proper resolving with kitodo2
var pdfInput = new DerivansData(input.getPath(), DerivateType.JPG);
// required for proper resolving with kitodo2
var pdfInput = new DerivansData(input.getPath(), DerivateType.JPG);
var pdfDerivateer = new PDFDerivateer(pdfInput, output, pages, pdfStep);
if (this.optMetadataStore.isPresent()) {
pdfDerivateer.setMetadataStore(optMetadataStore);
Expand All @@ -191,32 +192,32 @@ private List<DigitalPage> initDigitalPages(List<DerivateStep> steps) {
return this.resolver.resolveFromStep(step0);
}

/**
*
* Enrich page-wise URN from first matching filename
*
* @param targets
* @param sources
* @return
*/
private List<DigitalPage> enrichGranularURN(List<DigitalPage> targets, List<DigitalPage> sources) {
List<DigitalPage> enriched = new ArrayList<>();
for(DigitalPage target: targets) {
for(DigitalPage src: sources) {
var targetFile = target.getImagePath().getFileName();
var sourceFile = src.getImagePath().getFileName();
if (targetFile.equals(sourceFile)) {
Optional<String> optIdent = src.optIdentifier();
if(optIdent.isPresent()) {
target.setIdentifier(optIdent.get());
enriched.add(0, target);
break;
}
}
}
}
return enriched;
}
/**
*
* Enrich page-wise URN from first matching filename
*
* @param targets
* @param sources
* @return
*/
private List<DigitalPage> enrichGranularURN(List<DigitalPage> targets, List<DigitalPage> sources) {
List<DigitalPage> enriched = new ArrayList<>();
for (DigitalPage target : targets) {
for (DigitalPage src : sources) {
var targetFile = target.getImagePath().getFileName();
var sourceFile = src.getImagePath().getFileName();
if (targetFile.equals(sourceFile)) {
Optional<String> optIdent = src.optIdentifier();
if (optIdent.isPresent()) {
target.setIdentifier(optIdent.get());
enriched.add(0, target);
break;
}
}
}
}
return enriched;
}

public void create() throws DigitalDerivansException {
this.init(steps);
Expand Down Expand Up @@ -260,23 +261,23 @@ private String getIdentifier() throws DigitalDerivansException {
return IMetadataStore.UNKNOWN;
}

/**
*
* Access member just for testing purposes
*
* @return
*/
/**
*
* Access member just for testing purposes
*
* @return
*/
public List<DerivateStep> getSteps() {
return this.steps;
}

/**
*
* Access member just for testing purposes
*
* @return
*/
public List<IDerivateer> getDerivateers() {
return this.derivateers;
}
/**
*
* Access member just for testing purposes
*
* @return
*/
public List<IDerivateer> getDerivateers() {
return this.derivateers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class DerivansConfiguration {

private Path pathConfigFile;

private boolean debugPdfRender;

private Optional<String> paramImages = Optional.empty();

private Optional<String> paramOCR = Optional.empty();
Expand Down Expand Up @@ -82,11 +84,16 @@ public DerivansConfiguration(DerivansParameter params) throws DigitalDerivansExc
input = input.toAbsolutePath();
}

// determine if debug render fpr pdf required
if (params.getDebugPdfRender()) {
this.debugPdfRender = Boolean.TRUE;
}

// take care of args for input images/ocr
if(params.getImages() != null) {
if (params.getImages() != null) {
this.paramImages = Optional.of(params.getImages());
}
if(params.getOcr() != null) {
if (params.getOcr() != null) {
this.paramOCR = Optional.of(params.getOcr());
}

Expand Down Expand Up @@ -521,6 +528,7 @@ private static boolean isFooterDerivateSection(INIConfiguration conf, String sec

/**
* For testing purposes only
*
* @return
*/
public String getParamImages() {
Expand All @@ -533,6 +541,7 @@ public void setParamImages(String paramImage) {

/**
* For testing purposes only
*
* @return
*/
public String getParamOCR() {
Expand All @@ -555,4 +564,15 @@ public void setParamOCR(String paramOCR) {
public List<String> getDerivatePrefixes() {
return this.derivatePrefixes;
}

/**
*
* Render more information concerning
* PDF Textlayer
*
* @return
*/
public boolean isDebugPdfRender() {
return this.debugPdfRender;
}
}
63 changes: 26 additions & 37 deletions src/main/java/de/ulb/digital/derivans/config/DerivansParameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,39 @@
*/
public class DerivansParameter {

@Argument(index = 0, required = true,
usage = "Path to input data (required).\n" +
@Argument(index = 0, required = true, usage = "Path to input data (required).\n" +
"Stands for a path to metadata file (i.e., METS-file), or\n" +
"path to a locale directory with subdirectories (locale mode)\n" +
"for images (required) and fulltext data (optional)." +
"(no default: required)"
)
"(no default: required)")
private Path pathInput;

@Option(name = "-c", aliases = {"--config-path" },
required = false,
usage = "Path to Derivans configuration file.\n" +
"If not present, search configuration at default location.\n" +
"(default:'./config/" + DEFAULT_CONFIG_FILE_LABEL +"')"
)
@Option(name = "-c", aliases = {
"--config-path" }, required = false, usage = "Path to Derivans configuration file.\n" +
"If not present, search configuration at default location.\n" +
"(default:'./config/" + DEFAULT_CONFIG_FILE_LABEL + "')")
private Path pathConfig;

@Option(name = "-i", aliases = { "--images" },
required = false,
usage = "Identify images, depending on context.\n" +
@Option(name = "-i", aliases = { "--images" }, required = false, usage = "Identify images, depending on context.\n"
+
"If in local mode, stands for directory containing images.\n" +
"If metadata present, stands for required image fileGroup label.\n" +
"which defaults to '" + DEFAULT_INPUT_IMAGES + "'.\n" +
"If no metadata present, defaults to '" + DEFAULT_INPUT_IMAGES + "'.\n"
)
"If metadata present, stands for required image fileGroup label.\n" +
"which defaults to '" + DEFAULT_INPUT_IMAGES + "'.\n" +
"If no metadata present, defaults to '" + DEFAULT_INPUT_IMAGES + "'.\n")
private String images;

@Option(name = "-o", aliases = { "--ocr" },
required = false,
usage = "Identify OCR-Data, depending on context.\n" +

@Option(name = "-o", aliases = { "--ocr" }, required = false, usage = "Identify OCR-Data, depending on context.\n" +
"If in local mode, stands for directory containing ocr files.\n" +
"If metadata present, stands for required ocr fileGroup label,\n" +
"which defaults otherwise to '" + DEFAULT_INPUT_FULLTEXT + "'.\n" +
"If no metadata present, defaults to '" + DEFAULT_INPUT_FULLTEXT + "'.\n"
)
"If metadata present, stands for required ocr fileGroup label,\n" +
"which defaults otherwise to '" + DEFAULT_INPUT_FULLTEXT + "'.\n" +
"If no metadata present, defaults to '" + DEFAULT_INPUT_FULLTEXT + "'.\n")
private String ocr;

@Option(name = "-d", aliases = {"--debug-render" },
required = false,
usage = "Render PDF-Layers for debugging if OCR-Data present.\n" +
"(default: false)"
)
private Boolean debugRender;


@Option(name = "-d", aliases = {
"--debug-pdf-render" }, required = false, usage = "Render PDF-Layers for debugging if OCR-Data present.\n" +
"(default: false)")
private Boolean debugPdfRender;

/**
*
* Set specific Parser Information
Expand Down Expand Up @@ -108,10 +97,10 @@ public String getOcr() {
return this.ocr;
}

public Boolean getDebugRender() {
if (debugRender == null) {
debugRender = Boolean.FALSE;
public Boolean getDebugPdfRender() {
if (debugPdfRender == null) {
debugPdfRender = Boolean.FALSE;
}
return debugRender;
return debugPdfRender;
}
}

0 comments on commit d49f9be

Please sign in to comment.