Skip to content

Commit

Permalink
Fix disappearance of the newly added metadata with empty value after …
Browse files Browse the repository at this point in the history
…editing the metadata tree table
  • Loading branch information
IkramMaalej committed Jan 11, 2022
1 parent 4afcd0a commit 9fb80da
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@

package org.kitodo.dataeditor.ruleset;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale.LanguageRange;
import java.util.Set;

import org.kitodo.api.Metadata;

Expand Down Expand Up @@ -81,7 +80,7 @@ private static <T> Collection<T> unorderedCollectionMemberByIndexAsList(Collecti
* which class these objects have, it still accepts them and provides for
* possibly necessary grouping.
*/
private Set<Metadata> metaDataObjects = new HashSet<>();
private Collection<Metadata> metaDataObjects = new ArrayList<>();

/**
* Creates a new data row object and enters a key into the table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.kitodo.api.dataformat.Division;
import org.kitodo.exceptions.InvalidMetadataValueException;
import org.kitodo.exceptions.NoSuchMetadataFieldException;
import org.kitodo.production.services.dataeditor.DataEditorService;
import org.primefaces.model.DefaultTreeNode;
import org.primefaces.model.TreeNode;

Expand Down Expand Up @@ -169,9 +170,19 @@ private ProcessFieldedMetadata(ProcessFieldedMetadata template) {
*/
private void createMetadataTable() {
// the existing metadata is passed to the rule set, which sorts it
List<MetadataViewWithValuesInterface> tableData = metadataView
.getSortedVisibleMetadata(addLabels(metadata), additionallySelectedFields);

List<MetadataViewWithValuesInterface> tableData = null;
if (Objects.nonNull(treeNode) && !treeNode.getChildren().isEmpty()) {
try {
tableData = metadataView.getSortedVisibleMetadata(
DataEditorService.getExistingMetadataRows(treeNode.getChildren()),
additionallySelectedFields);
} catch (InvalidMetadataValueException e) {
logger.error(e.getLocalizedMessage());
}
} else {
tableData = metadataView
.getSortedVisibleMetadata(addLabels(metadata), additionallySelectedFields);
}
treeNode.getChildren().clear();
hiddenMetadata = Collections.emptyList();
for (MetadataViewWithValuesInterface rowData : tableData) {
Expand Down Expand Up @@ -455,7 +466,11 @@ public Collection<Metadata> getMetadata(boolean skipEmpty) throws InvalidMetadat
} catch (NoSuchMetadataFieldException e) {
throw new IllegalStateException("never happening exception");
}
result.setGroup(metadata instanceof List ? metadata : new ArrayList<>(metadata));
if (skipEmpty) {
result.setGroup(metadata instanceof List ? metadata : new ArrayList<>(metadata));
} else {
result.setGroup(new ArrayList<>(DataEditorService.getExistingMetadataRows(treeNode.getChildren())));
}
return Collections.singletonList(result);
}

Expand Down Expand Up @@ -539,7 +554,9 @@ public void preserve() throws InvalidMetadataValueException, NoSuchMetadataField
metadata.addAll(row.getMetadata());
}
}
metadata.addAll(hiddenMetadata);
if (Objects.nonNull(hiddenMetadata)) {
metadata.addAll(hiddenMetadata);
}
} catch (InvalidMetadataValueException invalidValueException) {
if (Objects.isNull(division)) {
invalidValueException.addParent(metadataKey);
Expand Down

0 comments on commit 9fb80da

Please sign in to comment.