From 9144bb317c33bc2d6a8ca2d28b2964f5e40e0f6f Mon Sep 17 00:00:00 2001 From: Robert Sehr Date: Wed, 4 Dec 2024 10:01:16 +0100 Subject: [PATCH] changed validation checks, updated documentation --- docs/index_de.md | 4 +- docs/index_en.md | 3 +- .../plugin_intranda_step_tif_validation.xml | 141 +++++++++++++++--- .../plugins/TifValidationConfiguration.java | 5 +- .../checks/TifValidationResolutionCheck.java | 23 ++- .../checks/TifValidationSimpleXpathCheck.java | 3 +- 6 files changed, 149 insertions(+), 30 deletions(-) diff --git a/docs/index_de.md b/docs/index_de.md index 5846999..0003aa1 100644 --- a/docs/index_de.md +++ b/docs/index_de.md @@ -59,4 +59,6 @@ Parameter | Erläuterung `openStepOnError` | Dieser Parameter legt fest, welcher Arbeitsschritt des Workflows erneut geöffnet werden soll, wenn ein Fehler innerhalb der Validierung auftritt. Wird dieser Parameter nicht verwendet, so aktiviert das Plugin stattdessen einfach den vorherigen Arbeitsschritt des Validierungsschritts. `lockAllStepsBetween` | Mit diesem Parameter wird festgelegt, ob die Arbeitsschritte des Workflows zwischen dem Validierungsschritt und demjenigen, der innerhalb des Parameters `openStepOnError` angegeben wurde, wieder auf auf den Status gesperrt gesetzt werden sollen, so dass diese Arbeitsschritte ein erneutes Mal durchlaufen (`true`) werden müssen. Wird der Wert hingegen auf `false` gesetzt, so wird der Status der dazwischen liegenden Schritte nicht verändert, so dass die Arbeitsschritte auch nicht noch einmal durchlaufen werden. `jhoveConfiguration` | Mit diesem Parameter wird angegeben, wo sich die Konfigurationsdatei für JHove befindet. -`check` | Innerhalb eines jeden Elements check wird festgelegt, was JHove genau validieren soll. Hier wird beispielsweise festgelegt, welches Dateiformat erwartet wird. Für den erwarteten Wert kann innerhalb des Elements `` eine direkte Eingabe auch als Bereich erfasst werden. Ebenso ist es hier auch möglich, eine Variable zu verwenden, die durch den Variablen-Replacer ersetzt wird (z.B. `{process.Resolution}`. Zugehörig ist hierbei ebenso, welche Fehlermeldung im Falle einer fehlerhaften Validierung ausgegeben werden soll. In der Fehlermeldung können folgende Variablen genutzt werden: `${wanted}` für den exakten Inhalt aus dem Feld ``, `${expected}` für den aufgelösten erwarteten Wert, `${found}` für den gefundenen Wert und `${image}` für den Dateinamen. Das Feld `` kann wiederholt und mit dem Unterlement `` versehen werden. Dann wird der Check nur ausgeführt, wenn die konfigurierte Bedingung zutrifft. +`check` | Innerhalb eines jeden Elements check wird festgelegt, was JHove genau validieren soll. Hier wird beispielsweise festgelegt, welches Dateiformat erwartet wird. Für den erwarteten Wert kann innerhalb des Elements `` eine direkte Eingabe auch als Bereich erfasst werden. Ebenso ist es hier auch möglich, eine Variable zu verwenden, die durch den Variablen-Replacer ersetzt wird (z.B. `{process.Resolution}`. Zugehörig ist hierbei ebenso, welche Fehlermeldung im Falle einer fehlerhaften Validierung ausgegeben werden soll. In der Fehlermeldung können folgende Variablen genutzt werden: `${wanted}` für den exakten Inhalt aus dem Feld ``, `${expected}` für den aufgelösten erwarteten Wert, `${found}` für den gefundenen Wert und `${image}` für den Dateinamen. Das Feld `` kann wiederholt und mit dem Unterlement `` versehen werden. Dann wird der Check nur ausgeführt, wenn die konfigurierte Bedingung zutrifft. Im Feld `` kann angegeben werden, wie genau die Prüfung ausgeführt wird. Der Defaultwert ist dabei `equals`, der gefundene Wert muss exakt mit dem konfigurierten Wert übereinstimmen. Die Option `multiple` prüft, ob der gefundene Wert ein vielfaches der konfigurierten Zahl ist. Bei `lesser` oder `greater` muss der gefundene Wert größer bzw. kleiner als der konfiguriert Wert sein, `exists` und `not exists` prüft auf die Existenz eines beliebigen Wertes und `same` prüft, ob der Wert mit einem anderen Wert übereinstimmt. Hierzu muss der andere Wert in `otherXpath` angegeben werden. + + diff --git a/docs/index_en.md b/docs/index_en.md index 4bbcb22..b491936 100644 --- a/docs/index_en.md +++ b/docs/index_en.md @@ -56,5 +56,6 @@ Parameter | Explanation `openStepOnError` | This parameter determines which step of the workflow should be reopened if an error occurs within the validation. If this parameter is not used, the plugin simply activates the previous step of the validation step instead. `lockAllStepsBetween` | This parameter is used to determine whether the work steps of the workflow between the validation step and the one specified within the parameter openStepOnError are to be set back to the status locked so that these work steps have to be run through again (`true`). If, on the other hand, the value is set to `false`, the status of the steps in between is not changed, so that these steps are not run through again. `jhoveConfiguration` | This parameter specifies where the configuration file for JHove is located. -`check` | Within each element check is defined what exactly JHove should validate. For example, here you define which file format is expected. For the expected value, a direct input can also be entered as a range within the `` element. It is also possible to use a variable here, which is replaced by the variable replacer (e.g. `{process.Resolution}`. Also included is which error message should be issued in case of an incorrect validation. The following variables can be used in the error message: `${wanted}` for the exact content from the `` field, `${expected}` for the resolved expected value, `${found}` for the found value and `${image}` for the file name. The field `` can be repeated and can contain the sub-element ``. The check is then only executed if the configured condition applies. +`check` | Within each element check is defined what exactly JHove should validate. For example, here you define which file format is expected. For the expected value, a direct input can also be entered as a range within the `` element. It is also possible to use a variable here, which is replaced by the variable replacer (e.g. `{process.Resolution}`. Also included is which error message should be issued in case of an incorrect validation. The following variables can be used in the error message: `${wanted}` for the exact content from the `` field, `${expected}` for the resolved expected value, `${found}` for the found value and `${image}` for the file name. The field `` can be repeated and can contain the sub-element ``. The check is then only executed if the configured condition applies. The `` field can be used to specify how exactly the check is to be carried out. The default value is `equals`, the value found must match the configured value exactly. The `multiple` option checks whether the value found is a multiple of the configured number. With `lesser` or `greater`, the value found must be greater or smaller than the configured value, `exists` and `not exists` checks for the existence of any value and `same` checks whether the value matches another value. To do this, the other value must be specified in `otherXpath`. + diff --git a/install/plugin_intranda_step_tif_validation.xml b/install/plugin_intranda_step_tif_validation.xml index 961ebcb..6328ed2 100644 --- a/install/plugin_intranda_step_tif_validation.xml +++ b/install/plugin_intranda_step_tif_validation.xml @@ -8,37 +8,124 @@ true /opt/digiverso/goobi/config/jhove/jhove.conf - - - - count(//jhove:repInfo/jhove:format) - 1.0 - Check format count for "${image}": Expected value "${expected}", but found value "${found}". - + + + string(//jhove:repInfo/jhove:format) TIFF Check format for "${image}": Expected value "${expected}", but found value "${found}". - + + //jhove:repInfo/jhove:status - Well-Formed and valid + Check status for "${image}": Expected value "${expected}", but found value "${found}". + + + + + //mix:Compression/mix:compressionScheme + Uncompressed + Check compression scheme for "${image}": Expected value "${expected}", but found value "${found}". - + + - string(//mix:iccProfileName) - Adobe RGB (1998) - Check color profile for "${image}": Expected value "${expected}", but found value "${found}". + //jhove:property[jhove:name='PlanarConfiguration']/jhove:values/jhove:value + 1 + Check planar configuration for "${image}": Expected value "${expected}", but found value "${found}". - + + - string(//mix:bitsPerSampleValue[1]) - 16 + //jhove:property[jhove:name='ByteOrder']/jhove:values/jhove:value + little-endian + Check compression scheme for "${image}": Expected value "${expected}", but found value "${found}". + + + + + //jhove:property[jhove:name='FillOrder']/jhove:values/jhove:value + 1 + Check compression scheme for "${image}": Expected value "${expected}", but found value "${found}". + + + + + //mix:PhotometricInterpretation/mix:colorSpace + RGB + Check compression scheme for "${image}": Expected value "${expected}", but found value "${found}". + + + + + string(//mix:samplesPerPixel[1]) + 3 Check color depth for "${image}": Expected value "${expected}", but found value "${found}". - + + string(//mix:bitsPerSampleValue[1]) + 8|16 + Check color depth for "${image}": Expected value is 8 or 16 but found value "${found}". + + + string(//mix:bitsPerSampleValue[2]) + 8|16 + Check color depth for "${image}": Expected value is 8 or 16 but found value "${found}". + + + string(//mix:bitsPerSampleValue[2]) + 8|16 + Check color depth for "${image}": Expected value is 8 or 16 but found value "${found}". + + + + + + + //mix:ImageAssessmentMetadata//mix:SpatialMetrics/mix:xSamplingFrequency/mix:numerator + exists + Check x-axis resolution": value not found". + exists + + + + //mix:ImageAssessmentMetadata//mix:SpatialMetrics/mix:ySamplingFrequency/mix:numerator + exists + Check y-axis resolution": value not found". + exists + + + //mix:ImageAssessmentMetadata//mix:SpatialMetrics/mix:samplingFrequencyUnit + exists + Check resolution unit": value not found". + exists + + + + //mix:ImageAssessmentMetadata//mix:SpatialMetrics/mix:xSamplingFrequency/mix:numerator + + Check resolution for "${image}": X- and Y-resolution differ. + same + //mix:ImageAssessmentMetadata//mix:SpatialMetrics/mix:ySamplingFrequency/mix:numerator + + + + //mix:ImageAssessmentMetadata//mix:SpatialMetrics/mix:xSamplingFrequency/mix:numerator + 300 + Check x-axis resolution": Expected value at least "${expected}", but found value "${found}". + greater + + + //mix:ImageAssessmentMetadata//mix:SpatialMetrics/mix:ySamplingFrequency/mix:numerator + 300 + Check y-axis resolution": Expected value at least "${expected}", but found value "${found}"". + greater + + + http://www.loc.gov/mix/v20 @@ -51,9 +138,27 @@ + If no default configuration exists and no condition applies, the check is not executed. + Can be a fixed value or a range. --> 100.0-899.23 Check resolution for "${image}": Expected value "${expected}", but found value "${found}". + + + + http://www.loc.gov/mix/v20 + 1 + Check resolution for "${image}": x-axis and y-axis differ. + same + + + + + http://www.loc.gov/mix/v20 + 300 + Check resolution for "${image}": must be at least "${expected}" dpi, but found value "${found}". + greater + + \ No newline at end of file diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/TifValidationConfiguration.java b/module-base/src/main/java/de/intranda/goobi/plugins/TifValidationConfiguration.java index 222ada0..b01ab49 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/TifValidationConfiguration.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/TifValidationConfiguration.java @@ -124,7 +124,10 @@ private void readChecks() { } } if (match) { - this.checks.add(new TifValidationResolutionCheck(wantedValue, errorMessage, mixUri)); + + TifValidationResolutionCheck check = new TifValidationResolutionCheck(wantedValue, errorMessage, mixUri); + check.setCheckType(hc.getString("/checkType", "equals")); + this.checks.add(check); break; } } diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/checks/TifValidationResolutionCheck.java b/module-base/src/main/java/de/intranda/goobi/plugins/checks/TifValidationResolutionCheck.java index 9c36795..69c2867 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/checks/TifValidationResolutionCheck.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/checks/TifValidationResolutionCheck.java @@ -57,6 +57,7 @@ public TifValidationResolutionCheck(String expectedValue, String errorMessage, S private void createReplaceMap() { this.replaceMap = new HashMap<>(); this.replaceMap.put("wanted", this.expectedValue); + this.replaceMap.put("expected", this.expectedValue); } @Override @@ -83,13 +84,21 @@ public boolean check(Document doc) { compressionValueX = resolutionXnum.intValue(); compressionValueY = resolutionYnum.intValue(); } - ValueRange range = ValueRangeFactory.create(expectedValue); - - if (range.contains(compressionValueX) && range.contains(compressionValueY)) { - return true; - } else { - this.replaceMap.put("found", compressionValueX + "," + compressionValueY); - return false; + this.replaceMap.put("found", compressionValueX + "," + compressionValueY); + int expected = Integer.parseInt(expectedValue); + switch (checkType) { + case "equals": { + ValueRange range = ValueRangeFactory.create(expectedValue); + return range.contains(compressionValueX) && range.contains(compressionValueY); + } + case "same": + return compressionValueX.equals(compressionValueY); + case "greater": + return expected <= compressionValueX.intValue() && expected <= compressionValueY.intValue(); + case "lesser": + return expected >= compressionValueX.intValue() && expected >= compressionValueY.intValue(); + default: + throw new IllegalArgumentException("Unexpected value: " + checkType); } } } diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/checks/TifValidationSimpleXpathCheck.java b/module-base/src/main/java/de/intranda/goobi/plugins/checks/TifValidationSimpleXpathCheck.java index 6cd851e..1f3a689 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/checks/TifValidationSimpleXpathCheck.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/checks/TifValidationSimpleXpathCheck.java @@ -70,13 +70,12 @@ public boolean check(Document doc) { } else if (!(value instanceof String)) { value = value.toString(); } - this.replaceMap.put("found", (String) value); String val = (String) value; + this.replaceMap.put("found", val); switch (checkType) { case "exists": return true; case "greater": - if (NumberUtils.isCreatable(val)) { if (val.contains(".")) { double expected = Double.parseDouble(expectedValue);