diff --git a/src/main/java/de/sub/goobi/forms/ProzesskopieForm.java b/src/main/java/de/sub/goobi/forms/ProzesskopieForm.java index a4991bb99..d20bedad5 100644 --- a/src/main/java/de/sub/goobi/forms/ProzesskopieForm.java +++ b/src/main/java/de/sub/goobi/forms/ProzesskopieForm.java @@ -721,7 +721,8 @@ public String readMetadataFromTemplate() throws DAOException { List firstChildMetadata = colStruct.getAllChildren() == null || colStruct.getAllChildren().isEmpty() ? Collections.emptyList() : colStruct.getAllChildren().get(0).getAllMetadata(); - fillTemplateFromMetadata(colStruct.getAllMetadata(), firstChildMetadata); + fillTemplateFromMetadata(colStruct.getAllMetadata(), "topstruct"); + fillTemplateFromMetadata(firstChildMetadata, "firstchild"); removeCollections(colStruct); @@ -776,11 +777,11 @@ private void fillTemplateFromMasterpiece(Process tempProcess) { } } - private void fillTemplateFromMetadata(List topstruct, List firstChild) { - List toRemove = new ArrayList<>(topstruct.size()); - for (Metadata m : topstruct) { + private void fillTemplateFromMetadata(List struct, String structName) { + List toRemove = new ArrayList<>(struct.size()); + for (Metadata m : struct) { Optional additionalField = this.additionalFields.stream() - .filter(f -> "topstruct".equals(f.getDocstruct())) + .filter(f -> structName.equals(f.getDocstruct())) .filter(f -> f.getMetadata() != null && f.getMetadata().equals(m.getType().getName())) .findFirst(); if (additionalField.isPresent()) { @@ -789,21 +790,7 @@ private void fillTemplateFromMetadata(List topstruct, List f } } // We need to remove all metadata that are saved into additional fields, because they would be possibly added twice in the end - toRemove.forEach(topstruct::remove); - - toRemove = new ArrayList<>(firstChild.size()); - for (Metadata m : firstChild) { - Optional additionalField = this.additionalFields.stream() - .filter(f -> "firstchild".equals(f.getDocstruct())) - .filter(f -> f.getMetadata() != null && f.getMetadata().equals(m.getType().getName())) - .findFirst(); - if (additionalField.isPresent()) { - setFieldValue(additionalField.get(), m.getValue()); - toRemove.add(m); - } - } - // We need to remove all metadata that are saved into additional fields, because they would be possibly added twice in the end - toRemove.forEach(topstruct::remove); + toRemove.forEach(struct::remove); } private void setFieldValue(AdditionalField field, String value) {