From 78c3c1b62bc31941fe9fc0d7f22ddd3a7c6c0fe8 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Mon, 2 Nov 2020 14:25:26 +0100 Subject: [PATCH] exclude pid values set to 'none' --- .../dhp/schema/oaf/utils/IdentifierFactory.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/schema/oaf/utils/IdentifierFactory.java b/dhp-common/src/main/java/eu/dnetlib/dhp/schema/oaf/utils/IdentifierFactory.java index 3059459d6..c57a7c135 100644 --- a/dhp-common/src/main/java/eu/dnetlib/dhp/schema/oaf/utils/IdentifierFactory.java +++ b/dhp-common/src/main/java/eu/dnetlib/dhp/schema/oaf/utils/IdentifierFactory.java @@ -23,6 +23,7 @@ public class IdentifierFactory implements Serializable { public final static String ID_REGEX = "^[0-9][0-9]\\" + ID_PREFIX_SEPARATOR + ".{12}" + ID_SEPARATOR + "[a-zA-Z0-9]{32}$"; public static final int ID_PREFIX_LEN = 12; + public static final String NONE = "none"; /** * Creates an identifier from the most relevant PID (if available) in the given entity T. Returns entity.id @@ -40,15 +41,20 @@ public class IdentifierFactory implements Serializable { return entity .getPid() .stream() - .filter(s -> Objects.nonNull(s.getQualifier())) - .filter(s -> PidType.isValid(s.getQualifier().getClassid())) - .filter(s -> StringUtils.isNotBlank(StringUtils.trim(s.getValue()))) + .filter(s -> pidFilter(s)) .min(new PidComparator<>(entity)) .map(s -> idFromPid(entity, s)) .map(IdentifierFactory::verifyIdSyntax) .orElseGet(entity::getId); } + protected static boolean pidFilter(StructuredProperty s) { + return Objects.nonNull(s.getQualifier()) && + PidType.isValid(s.getQualifier().getClassid()) && + StringUtils.isNotBlank(StringUtils.trim(s.getValue())) && + !NONE.equals(StringUtils.trim(StringUtils.lowerCase(s.getValue()))); + } + /** * Utility method that normalises PID values on a per-type basis. * @param pid the PID whose value will be normalised.