Skip to content

Commit

Permalink
Prevent NPE when creating unknown metadata group and metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
solth committed Mar 4, 2024
1 parent 25d1d7f commit a56d6fc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -578,16 +578,18 @@ public Collection<Metadata> getMetadata(boolean skipEmpty) throws InvalidMetadat
assert division == null;
MetadataGroup result = new MetadataGroup();
result.setKey(metadataKey);
result.setDomain(DOMAIN_TO_MDSEC.get(metadataView.getDomain().orElse(Domain.DESCRIPTION)));
try {
this.preserve();
} catch (NoSuchMetadataFieldException e) {
throw new IllegalStateException("never happening exception");
}
if (skipEmpty) {
result.setMetadata(metadata instanceof List ? metadata : new HashSet<>(metadata));
} else {
result.setMetadata(new HashSet<>(DataEditorService.getExistingMetadataRows(treeNode.getChildren())));
if (Objects.nonNull(metadataView)) {
result.setDomain(DOMAIN_TO_MDSEC.get(metadataView.getDomain().orElse(Domain.DESCRIPTION)));
try {
this.preserve();
} catch (NoSuchMetadataFieldException e) {
throw new IllegalStateException("never happening exception");
}
if (skipEmpty) {
result.setMetadata(metadata instanceof List ? metadata : new HashSet<>(metadata));
} else {
result.setMetadata(new HashSet<>(DataEditorService.getExistingMetadataRows(treeNode.getChildren())));
}
}
return result.getMetadata().isEmpty() ? Collections.emptyList() : Collections.singletonList(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public ProcessTextMetadata(ProcessTextMetadata template) {
}

private String addLeadingZeros(String value) {
if (Objects.equals(super.settings.getInputType(), InputType.INTEGER)) {
if (Objects.nonNull(super.settings) && InputType.INTEGER.equals(super.settings.getInputType())) {
int valueLength = value.length();
int minDigits = super.settings.getMinDigits();
return valueLength >= minDigits ? value : "0".repeat(minDigits - valueLength).concat(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,15 @@ public static List<SelectItem> getAddableMetadataForGroup(Ruleset ruleset, TreeN
ProcessFieldedMetadata fieldedMetadata = ((ProcessFieldedMetadata) metadataNode.getData());
ComplexMetadataViewInterface metadataView = fieldedMetadata.getMetadataView();
List<SelectItem> addableMetadata = new ArrayList<>();
for (MetadataViewInterface keyView : metadataView.getAddableMetadata(fieldedMetadata.getChildMetadata(),
fieldedMetadata.getAdditionallySelectedFields())) {
addableMetadata.add(
new SelectItem(keyView.getId(), keyView.getLabel(),
keyView instanceof SimpleMetadataViewInterface
? ((SimpleMetadataViewInterface) keyView).getInputType().toString()
: "dataTable"));
if (Objects.nonNull(metadataView)) {
for (MetadataViewInterface keyView : metadataView.getAddableMetadata(fieldedMetadata.getChildMetadata(),
fieldedMetadata.getAdditionallySelectedFields())) {
addableMetadata.add(
new SelectItem(keyView.getId(), keyView.getLabel(),
keyView instanceof SimpleMetadataViewInterface
? ((SimpleMetadataViewInterface) keyView).getInputType().toString()
: "dataTable"));
}
}
return sortMetadataList(addableMetadata, ruleset);
}
Expand Down

0 comments on commit a56d6fc

Please sign in to comment.