diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessBooleanMetadata.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessBooleanMetadata.java index b006b43764f..30556432a3c 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessBooleanMetadata.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessBooleanMetadata.java @@ -96,19 +96,6 @@ public Collection getMetadata(boolean skipEmpty) throws InvalidMetadat return Collections.emptyList(); } - @Override - Pair, String>, String> getStructureFieldValue() - throws InvalidMetadataValueException, NoSuchMetadataFieldException { - - if (settings.getDomain().orElse(Domain.DESCRIPTION).equals(Domain.METS_DIV)) { - if (!isValid()) { - throw new InvalidMetadataValueException(label, settings.convertBoolean(active).orElse("")); - } - return Pair.of(super.getStructureFieldSetters(settings), settings.convertBoolean(active).orElse(null)); - } else { - return null; - } - } /** * Returns whether the switch is on. diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessDetail.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessDetail.java index a1d64bf6859..927b1374eb9 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessDetail.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessDetail.java @@ -123,21 +123,6 @@ public String getLabel() { */ public abstract Collection getMetadata(boolean skipEmpty) throws InvalidMetadataValueException; - /** - * If the metadata entry addresses a property of the structure, returns a - * pair of the setter and the value to set; else {@code null}. This method - * it to be called when saving the data. - * - * @return if data is to be written a pair of the setter of the - * {@link LogicalDivision} and the value to set, else null - * @throws InvalidMetadataValueException - * if the metadata form contains syntactically wrong input - * @throws NoSuchMetadataFieldException - * if the field configured in the rule set does not exist - */ - abstract Pair, String>, String> getStructureFieldValue() - throws InvalidMetadataValueException, NoSuchMetadataFieldException; - /** * Returns whether this metadata entry is leading for options of other * metadata entries. If true, the application must refresh the metadata diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessFieldedMetadata.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessFieldedMetadata.java index 0dabe513dc3..38dedd5e6f6 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessFieldedMetadata.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessFieldedMetadata.java @@ -24,11 +24,10 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.Optional; -import java.util.function.BiConsumer; +import java.util.Set; import java.util.stream.Collectors; import org.apache.commons.collections4.list.UnmodifiableList; -import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -60,6 +59,7 @@ public class ProcessFieldedMetadata extends ProcessDetail implements Serializabl public static final ProcessFieldedMetadata EMPTY = new ProcessFieldedMetadata(); public static final String METADATA_KEY_LABEL = "LABEL"; public static final String METADATA_KEY_ORDERLABEL = "ORDERLABEL"; + public static final String METADATA_KEY_CONTENTIDS = "CONTENTIDS"; /** * Fields the user has selected to show in addition, with no data yet. @@ -612,11 +612,6 @@ public List getRows() { return new UnmodifiableList<>(rows); } - @Override - Pair, String>, String> getStructureFieldValue() { - return null; - } - public TreeNode getTreeNode() { return treeNode; } @@ -676,16 +671,29 @@ public void preserve() throws InvalidMetadataValueException, NoSuchMetadataField division.setLabel(null); } metadata.clear(); + Set specialFields = new HashSet<>(Set.of(METADATA_KEY_LABEL, METADATA_KEY_ORDERLABEL, + METADATA_KEY_CONTENTIDS)); + for (TreeNode child : treeNode.getChildren()) { ProcessDetail row = (ProcessDetail) child.getData(); - Pair, String>, String> metsFieldValue = row.getStructureFieldValue(); - if (Objects.nonNull(metsFieldValue)) { - metsFieldValue.getKey().accept(division, metsFieldValue.getValue()); + String id = row.getMetadataID(); + if (row instanceof ProcessSimpleMetadata && specialFields.contains(id) + && ((ProcessSimpleMetadata) row).getSettings() + .getDomain().orElse(Domain.DESCRIPTION).equals(Domain.METS_DIV)) { + updateDivisionFromProcessDetail(id, (ProcessSimpleMetadata) row); } else { metadata.addAll(row.getMetadataWithFilledValues()); } } if (Objects.nonNull(hiddenMetadata)) { + if (!hiddenMetadata.isEmpty()) { + for (Metadata hiddenmetadatum : hiddenMetadata) { + if (hiddenmetadatum instanceof MetadataEntry + && specialFields.contains(hiddenmetadatum.getKey())) { + updateDivision(hiddenmetadatum.getKey(), ((MetadataEntry) hiddenmetadatum).getValue()); + } + } + } metadata.addAll(hiddenMetadata); } } catch (InvalidMetadataValueException invalidValueException) { @@ -705,6 +713,42 @@ public void preserve() throws InvalidMetadataValueException, NoSuchMetadataField } } + private void updateDivisionFromProcessDetail(String key, ProcessSimpleMetadata processDetail) throws InvalidMetadataValueException { + String simpleValue = extractSimpleValue(processDetail); + if (processDetail.getSettings().isValid(simpleValue, getListForLeadingMetadataFields())) { + throw new InvalidMetadataValueException(key, simpleValue); + }; + if (simpleValue == null) { + return; + } + updateDivision(key, simpleValue); + } + + private String extractSimpleValue(ProcessDetail value) { + if (value instanceof ProcessTextMetadata) { + return ((ProcessTextMetadata) value).getValue(); + } else if (value instanceof ProcessSelectMetadata) { + return String.join(" ", ((ProcessSelectMetadata) value).getSelectedItems()); + } + return null; + } + + private void updateDivision(String key, String value) { + switch (key) { + case METADATA_KEY_LABEL: + division.setLabel(value); + break; + case METADATA_KEY_ORDERLABEL: + division.setOrderlabel(value); + break; + case METADATA_KEY_CONTENTIDS: + division.getContentIds().add(URI.create(value)); + break; + default: + break; + } + } + /** * Removes a process detail. * diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessSelectMetadata.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessSelectMetadata.java index 1f29530712c..aa61bf09e7b 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessSelectMetadata.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessSelectMetadata.java @@ -191,20 +191,6 @@ public List getSelectedItems() { return selectedItems; } - @Override - Pair, String>, String> getStructureFieldValue() - throws InvalidMetadataValueException, NoSuchMetadataFieldException { - if (settings.getDomain().orElse(Domain.DESCRIPTION).equals(Domain.METS_DIV)) { - String value = String.join(" ", selectedItems); - if (!settings.isValid(value, container.getListForLeadingMetadataFields())) { - throw new InvalidMetadataValueException(label, value); - } - return Pair.of(super.getStructureFieldSetters(settings), value); - } else { - return null; - } - } - @Override public boolean isValid() { for (String selectedItem : selectedItems) { diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessSimpleMetadata.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessSimpleMetadata.java index e5afcc3c0ae..72ede6d41c9 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessSimpleMetadata.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessSimpleMetadata.java @@ -72,6 +72,10 @@ protected BiConsumer, String> getStructureFieldSetters(MetadataViewI } } + public SimpleMetadataViewInterface getSettings() { + return settings; + } + /** * Returns if the field may be edited. Some fields may be disallowed to be * edit from the rule set. diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessTextMetadata.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessTextMetadata.java index 549c36ae4c5..eb0c6f7a6f8 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessTextMetadata.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessTextMetadata.java @@ -104,20 +104,6 @@ public Collection getMetadataWithFilledValues() { return getMetadata(true); } - @Override - Pair, String>, String> getStructureFieldValue() - throws InvalidMetadataValueException, NoSuchMetadataFieldException { - - if (settings.getDomain().orElse(Domain.DESCRIPTION).equals(Domain.METS_DIV)) { - if (!settings.isValid(value, container.getListForLeadingMetadataFields())) { - throw new InvalidMetadataValueException(label, value); - } - return Pair.of(super.getStructureFieldSetters(settings), value); - } else { - return null; - } - } - @Override public boolean isValid() { if (Objects.isNull(value) || value.isEmpty()) {