From 1f7b068ae91509e3e88939d50ad1c5031ed162ff Mon Sep 17 00:00:00 2001 From: Arved Solth Date: Mon, 27 Mar 2023 10:35:30 +0200 Subject: [PATCH] Prevent NPE when creating unknown metadata group and metadata --- .../createprocess/ProcessFieldedMetadata.java | 22 ++++++++++--------- .../createprocess/ProcessTextMetadata.java | 2 +- .../dataeditor/DataEditorService.java | 16 ++++++++------ 3 files changed, 22 insertions(+), 18 deletions(-) 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 09cff4f5468..b06f3553a50 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 @@ -579,16 +579,18 @@ public Collection 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); } 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..5fd6ba1bbc5 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 @@ -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); diff --git a/Kitodo/src/main/java/org/kitodo/production/services/dataeditor/DataEditorService.java b/Kitodo/src/main/java/org/kitodo/production/services/dataeditor/DataEditorService.java index dce6d94366a..1287e7e08eb 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/dataeditor/DataEditorService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/dataeditor/DataEditorService.java @@ -136,13 +136,15 @@ public static List getAddableMetadataForGroup(Ruleset ruleset, TreeN ProcessFieldedMetadata fieldedMetadata = ((ProcessFieldedMetadata) metadataNode.getData()); ComplexMetadataViewInterface metadataView = fieldedMetadata.getMetadataView(); List 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); }