added more cleaning/identifier utilities
This commit is contained in:
parent
a7472744ec
commit
b0203ff5cc
|
@ -46,18 +46,27 @@ public class CleaningFunctions {
|
||||||
* @return the PID containing the normalised value.
|
* @return the PID containing the normalised value.
|
||||||
*/
|
*/
|
||||||
public static StructuredProperty normalizePidValue(StructuredProperty pid) {
|
public static StructuredProperty normalizePidValue(StructuredProperty pid) {
|
||||||
String value = Optional
|
pid.setValue(
|
||||||
.ofNullable(pid.getValue())
|
normalizePidValue(
|
||||||
.map(String::trim)
|
pid.getQualifier().getClassid(),
|
||||||
.orElseThrow(() -> new IllegalArgumentException("PID value cannot be empty"));
|
pid.getValue()));
|
||||||
switch (pid.getQualifier().getClassid()) {
|
|
||||||
|
|
||||||
// TODO add cleaning for more PID types as needed
|
|
||||||
case "doi":
|
|
||||||
pid.setValue(value.toLowerCase().replaceFirst(DOI_PREFIX_REGEX, DOI_PREFIX));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String normalizePidValue(String pidType, String pidValue) {
|
||||||
|
String value = Optional
|
||||||
|
.ofNullable(pidValue)
|
||||||
|
.map(String::trim)
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException("PID value cannot be empty"));
|
||||||
|
|
||||||
|
switch (pidType) {
|
||||||
|
|
||||||
|
// TODO add cleaning for more PID types as needed
|
||||||
|
case "doi":
|
||||||
|
return value.toLowerCase().replaceFirst(DOI_PREFIX_REGEX, DOI_PREFIX);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,9 +164,7 @@ public class IdentifierFactory implements Serializable {
|
||||||
.stream()
|
.stream()
|
||||||
// filter away PIDs provided by a DS that is not considered an authority for the
|
// filter away PIDs provided by a DS that is not considered an authority for the
|
||||||
// given PID Type
|
// given PID Type
|
||||||
.filter(p -> {
|
.filter(p -> shouldFilterPid(collectedFrom, p, mapHandles))
|
||||||
return shouldFilterPid(collectedFrom, p, mapHandles);
|
|
||||||
})
|
|
||||||
.map(CleaningFunctions::normalizePidValue)
|
.map(CleaningFunctions::normalizePidValue)
|
||||||
.filter(CleaningFunctions::pidFilter))
|
.filter(CleaningFunctions::pidFilter))
|
||||||
.orElse(Stream.empty());
|
.orElse(Stream.empty());
|
||||||
|
@ -193,12 +191,16 @@ public class IdentifierFactory implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T extends OafEntity> String idFromPid(T entity, StructuredProperty s, boolean md5) {
|
private static <T extends OafEntity> String idFromPid(T entity, StructuredProperty s, boolean md5) {
|
||||||
|
return idFromPid(ModelSupport.getIdPrefix(entity.getClass()), s.getQualifier().getClassid(), s.getValue(), md5);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String idFromPid(String numericPrefix, String pidType, String pidValue, boolean md5) {
|
||||||
return new StringBuilder()
|
return new StringBuilder()
|
||||||
.append(ModelSupport.getIdPrefix(entity.getClass()))
|
.append(numericPrefix)
|
||||||
.append(ID_PREFIX_SEPARATOR)
|
.append(ID_PREFIX_SEPARATOR)
|
||||||
.append(createPrefix(s.getQualifier().getClassid()))
|
.append(createPrefix(pidType))
|
||||||
.append(ID_SEPARATOR)
|
.append(ID_SEPARATOR)
|
||||||
.append(md5 ? md5(s.getValue()) : s.getValue())
|
.append(md5 ? md5(pidValue) : pidValue)
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue