diff --git a/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java b/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java index 1360b51274f..5a41273c9dd 100644 --- a/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java +++ b/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java @@ -392,20 +392,7 @@ private String determineReplacementForMetadata(Matcher variableFinder) { switch (metadataLevel) { case ALL: - List allChildren = workpiece.getLogicalStructure().getChildren(); - String allFirstchildValue = null; - if (!allChildren.isEmpty()) { - allFirstchildValue = MetadataEditor.getMetadataValue(allChildren.get(0), variableFinder.group(5)); - if (Objects.isNull(allFirstchildValue)) { - allFirstchildValue = determineReplacementForTopstruct(variableFinder, dollarSignIfToKeep); - } - if (Objects.isNull(allFirstchildValue) || StringUtils.isEmpty(allFirstchildValue)) { - List firstChildChildren = allChildren.get(0).getChildren(); - if (!firstChildChildren.isEmpty()) { - allFirstchildValue = MetadataEditor.getMetadataValue(firstChildChildren.get(0), variableFinder.group(5)); - } - } - } + String allFirstchildValue = determinateReplacementForAll(variableFinder, dollarSignIfToKeep); if (Objects.nonNull(allFirstchildValue)) { return allFirstchildValue; @@ -423,6 +410,24 @@ private String determineReplacementForMetadata(Matcher variableFinder) { } } + private String determinateReplacementForAll(Matcher variableFinder, String dollarSignIfToKeep) { + List allChildren = workpiece.getLogicalStructure().getChildren(); + String allFirstchildValue = null; + if (!allChildren.isEmpty()) { + allFirstchildValue = MetadataEditor.getMetadataValue(allChildren.get(0), variableFinder.group(5)); + if (Objects.isNull(allFirstchildValue)) { + allFirstchildValue = determineReplacementForTopstruct(variableFinder, dollarSignIfToKeep); + } + if (StringUtils.isEmpty(allFirstchildValue)) { + List firstChildChildren = allChildren.get(0).getChildren(); + if (!firstChildChildren.isEmpty()) { + allFirstchildValue = MetadataEditor.getMetadataValue(firstChildChildren.get(0), variableFinder.group(5)); + } + } + } + return allFirstchildValue; + } + private String determineReplacementForTopstruct(Matcher variableFinder, String failureResult) { String value = MetadataEditor.getMetadataValue(workpiece.getLogicalStructure(), variableFinder.group(5)); if (Objects.isNull(value)) {