Skip to content

Commit

Permalink
Adress remarks from review
Browse files Browse the repository at this point in the history
  • Loading branch information
BartChris committed Oct 25, 2024
1 parent 533709a commit 652e63a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@
import java.util.Collections;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.kitodo.api.Metadata;
import org.kitodo.api.MetadataEntry;
import org.kitodo.api.dataeditor.rulesetmanagement.Domain;
import org.kitodo.api.dataeditor.rulesetmanagement.SimpleMetadataViewInterface;
import org.kitodo.api.dataformat.Division;
import org.kitodo.exceptions.InvalidMetadataValueException;
import org.kitodo.exceptions.NoSuchMetadataFieldException;

/**
* A row on the metadata panel that contains an on/off switch.
Expand Down Expand Up @@ -70,6 +66,11 @@ public String getMetadataID() {
return settings.getId();
}

@Override
public String extractSimpleValue() {
return settings.convertBoolean(active).orElse(null);
}

@Override
public String getInput() {
return "toggleSwitch";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class ProcessFieldedMetadata extends ProcessDetail implements Serializabl
* Fields the user has selected to show in addition, with no data yet.
*/
private final Collection<String> additionallySelectedFields = new ArrayList<>();
private static final Set<String> specialFields = Set.of(METADATA_KEY_LABEL, METADATA_KEY_ORDERLABEL,
METADATA_KEY_CONTENTIDS);

private boolean copy;

Expand Down Expand Up @@ -671,8 +673,6 @@ public void preserve() throws InvalidMetadataValueException, NoSuchMetadataField
division.setLabel(null);
}
metadata.clear();
Set<String> specialFields = new HashSet<>(Set.of(METADATA_KEY_LABEL, METADATA_KEY_ORDERLABEL,
METADATA_KEY_CONTENTIDS));

for (TreeNode child : treeNode.getChildren()) {
ProcessDetail row = (ProcessDetail) child.getData();
Expand Down Expand Up @@ -714,7 +714,7 @@ public void preserve() throws InvalidMetadataValueException, NoSuchMetadataField
}

private void updateDivisionFromProcessDetail(String key, ProcessSimpleMetadata processDetail) throws InvalidMetadataValueException {
String simpleValue = extractSimpleValue(processDetail);
String simpleValue = processDetail.extractSimpleValue();
if (!processDetail.getSettings().isValid(simpleValue, getListForLeadingMetadataFields())) {
throw new InvalidMetadataValueException(key, simpleValue);
};
Expand All @@ -724,15 +724,6 @@ private void updateDivisionFromProcessDetail(String key, ProcessSimpleMetadata p
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ public List<String> getSelectedItems() {
return selectedItems;
}

@Override
public String extractSimpleValue() {
return String.join(" ", getSelectedItems());
}

@Override
public boolean isValid() {
for (String selectedItem : selectedItems) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,16 @@
package org.kitodo.production.forms.createprocess;

import java.io.Serializable;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.function.BiConsumer;

import org.kitodo.api.dataeditor.rulesetmanagement.ComplexMetadataViewInterface;
import org.kitodo.api.dataeditor.rulesetmanagement.MetadataViewInterface;
import org.kitodo.api.dataeditor.rulesetmanagement.SimpleMetadataViewInterface;
import org.kitodo.api.dataeditor.rulesetmanagement.StructuralElementViewInterface;
import org.kitodo.api.dataformat.Division;
import org.kitodo.api.dataformat.LogicalDivision;
import org.kitodo.api.dataformat.PhysicalDivision;
import org.kitodo.exceptions.NoSuchMetadataFieldException;

abstract class ProcessSimpleMetadata extends ProcessDetail implements Serializable {

Expand Down Expand Up @@ -56,6 +52,8 @@ protected ProcessSimpleMetadata(ProcessFieldedMetadata container, SimpleMetadata
*/
abstract ProcessSimpleMetadata getClone();

abstract String extractSimpleValue();

public SimpleMetadataViewInterface getSettings() {
return settings;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
import java.util.function.BiConsumer;

import org.apache.commons.lang3.tuple.Pair;
import org.kitodo.api.Metadata;
import org.kitodo.api.MetadataEntry;
import org.kitodo.api.dataeditor.rulesetmanagement.Domain;
import org.kitodo.api.dataeditor.rulesetmanagement.InputType;
import org.kitodo.api.dataeditor.rulesetmanagement.SimpleMetadataViewInterface;
import org.kitodo.api.dataformat.Division;
import org.kitodo.exceptions.InvalidMetadataValueException;
import org.kitodo.exceptions.NoSuchMetadataFieldException;

public class ProcessTextMetadata extends ProcessSimpleMetadata implements Serializable {

Expand Down Expand Up @@ -121,6 +116,11 @@ public String getValue() {
return value;
}

@Override
public String extractSimpleValue() {
return getValue();
}

/**
* Sets the contents of the text input field of this process metadata.
*
Expand Down

0 comments on commit 652e63a

Please sign in to comment.