From d28b7085f6f13a644926302e47da314dcb22de5d Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Tue, 17 Oct 2023 11:09:31 +0200 Subject: [PATCH] more NPE checks --- .../common/vocabulary/VocabularyGroup.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/common/vocabulary/VocabularyGroup.java b/dhp-common/src/main/java/eu/dnetlib/dhp/common/vocabulary/VocabularyGroup.java index 4c1feac457..64b6f91af2 100644 --- a/dhp-common/src/main/java/eu/dnetlib/dhp/common/vocabulary/VocabularyGroup.java +++ b/dhp-common/src/main/java/eu/dnetlib/dhp/common/vocabulary/VocabularyGroup.java @@ -136,24 +136,21 @@ public class VocabularyGroup implements Serializable { } public Qualifier lookupTermBySynonym(final String vocId, final String syn) { - if (StringUtils.isBlank(vocId)) { - return OafMapperUtils.unknown("", ""); - } - - final Vocabulary vocabulary = vocs.get(vocId.toLowerCase()); - - return Optional - .ofNullable(vocabulary.getTerm(syn)) + return find(vocId) .map( - term -> OafMapperUtils - .qualifier(term.getId(), term.getName(), vocabulary.getId(), vocabulary.getName())) - .orElse( - Optional - .ofNullable(vocabulary.getTermBySynonym(syn)) + vocabulary -> Optional + .ofNullable(vocabulary.getTerm(syn)) .map( term -> OafMapperUtils .qualifier(term.getId(), term.getName(), vocabulary.getId(), vocabulary.getName())) - .orElse(null)); + .orElse( + Optional + .ofNullable(vocabulary.getTermBySynonym(syn)) + .map( + term -> OafMapperUtils + .qualifier(term.getId(), term.getName(), vocabulary.getId(), vocabulary.getName())) + .orElse(null))) + .orElse(null); } /**