Skip to content

Commit

Permalink
fix: metadata copying from selection list also for first child
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominick Leppich committed Oct 24, 2024
1 parent bb08227 commit f0c989f
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/main/java/de/sub/goobi/forms/ProzesskopieForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,8 @@ public String readMetadataFromTemplate() throws DAOException {
List<Metadata> 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);

Expand Down Expand Up @@ -776,11 +777,11 @@ private void fillTemplateFromMasterpiece(Process tempProcess) {
}
}

private void fillTemplateFromMetadata(List<Metadata> topstruct, List<Metadata> firstChild) {
List<Metadata> toRemove = new ArrayList<>(topstruct.size());
for (Metadata m : topstruct) {
private void fillTemplateFromMetadata(List<Metadata> struct, String structName) {
List<Metadata> toRemove = new ArrayList<>(struct.size());
for (Metadata m : struct) {
Optional<AdditionalField> 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()) {
Expand All @@ -789,21 +790,7 @@ private void fillTemplateFromMetadata(List<Metadata> topstruct, List<Metadata> 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> 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) {
Expand Down

0 comments on commit f0c989f

Please sign in to comment.