exclude pid values set to 'none'

This commit is contained in:
Claudio Atzori 2020-11-02 14:25:26 +01:00
parent 8e7f81c5f5
commit 78c3c1b62b
1 changed files with 9 additions and 3 deletions

View File

@ -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 public final static String ID_REGEX = "^[0-9][0-9]\\" + ID_PREFIX_SEPARATOR + ".{12}" + ID_SEPARATOR
+ "[a-zA-Z0-9]{32}$"; + "[a-zA-Z0-9]{32}$";
public static final int ID_PREFIX_LEN = 12; 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 * 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 return entity
.getPid() .getPid()
.stream() .stream()
.filter(s -> Objects.nonNull(s.getQualifier())) .filter(s -> pidFilter(s))
.filter(s -> PidType.isValid(s.getQualifier().getClassid()))
.filter(s -> StringUtils.isNotBlank(StringUtils.trim(s.getValue())))
.min(new PidComparator<>(entity)) .min(new PidComparator<>(entity))
.map(s -> idFromPid(entity, s)) .map(s -> idFromPid(entity, s))
.map(IdentifierFactory::verifyIdSyntax) .map(IdentifierFactory::verifyIdSyntax)
.orElseGet(entity::getId); .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. * Utility method that normalises PID values on a per-type basis.
* @param pid the PID whose value will be normalised. * @param pid the PID whose value will be normalised.