|
|
|
@ -570,7 +570,21 @@ public class Result extends OafEntity implements Serializable {
|
|
|
|
|
private static String extractKeyFromPid(final StructuredProperty pid) {
|
|
|
|
|
if (pid == null)
|
|
|
|
|
return null;
|
|
|
|
|
final StructuredProperty normalizedPid = CleaningFunctions.normalizePidValue(pid);
|
|
|
|
|
final Pid normalizedPid = CleaningFunctions.normalizePidValue((Pid) pid);
|
|
|
|
|
|
|
|
|
|
return String.format("%s::%s", normalizedPid.getQualifier().getClassid(), normalizedPid.getValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Normalize pid string.
|
|
|
|
|
*
|
|
|
|
|
* @param pid the pid
|
|
|
|
|
* @return the string
|
|
|
|
|
*/
|
|
|
|
|
private static String extractKeyFromAltId(final StructuredProperty pid) {
|
|
|
|
|
if (pid == null)
|
|
|
|
|
return null;
|
|
|
|
|
final StructuredProperty normalizedPid = CleaningFunctions.normalizeSPValue(pid);
|
|
|
|
|
|
|
|
|
|
return String.format("%s::%s", normalizedPid.getQualifier().getClassid(), normalizedPid.getValue());
|
|
|
|
|
}
|
|
|
|
@ -595,8 +609,6 @@ public class Result extends OafEntity implements Serializable {
|
|
|
|
|
* @return the result map
|
|
|
|
|
*/
|
|
|
|
|
public static Map<String, Instance> toInstanceMap(final List<Instance> ri) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ri
|
|
|
|
|
.stream()
|
|
|
|
|
.filter(i -> i.getPid() != null || i.getAlternateIdentifier() != null)
|
|
|
|
@ -622,7 +634,7 @@ public class Result extends OafEntity implements Serializable {
|
|
|
|
|
* @param enrichments the List of enrichment instances having the same pid
|
|
|
|
|
* @return the list
|
|
|
|
|
*/
|
|
|
|
|
private static List<Instance> findEnrichmentsByPID(final List<StructuredProperty> pids, final Map<String,Instance> enrichments) {
|
|
|
|
|
private static List<Instance> findEnrichmentsByPID(final List<Pid> pids, final Map<String,Instance> enrichments) {
|
|
|
|
|
if (pids == null || enrichments == null)
|
|
|
|
|
return null;
|
|
|
|
|
return pids
|
|
|
|
@ -633,6 +645,25 @@ public class Result extends OafEntity implements Serializable {
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This utility method finds the list of enrichment instances
|
|
|
|
|
* that match one or more PIDs in the input list
|
|
|
|
|
*
|
|
|
|
|
* @param pids the list of PIDs
|
|
|
|
|
* @param enrichments the List of enrichment instances having the same pid
|
|
|
|
|
* @return the list
|
|
|
|
|
*/
|
|
|
|
|
private static List<Instance> findEnrichmentsByAlternateIdentifier(final List<StructuredProperty> pids, final Map<String,Instance> enrichments) {
|
|
|
|
|
if (pids == null || enrichments == null)
|
|
|
|
|
return null;
|
|
|
|
|
return pids
|
|
|
|
|
.stream()
|
|
|
|
|
.map(Result::extractKeyFromAltId)
|
|
|
|
|
.map(enrichments::get)
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This method apply enrichment on a single instance
|
|
|
|
|
* The enrichment consists of replacing values on
|
|
|
|
@ -712,11 +743,11 @@ public class Result extends OafEntity implements Serializable {
|
|
|
|
|
|
|
|
|
|
toEnrichInstances.forEach(i -> {
|
|
|
|
|
final List<Instance> e = findEnrichmentsByPID(i.getPid(), ri);
|
|
|
|
|
if (e!= null && e.size()> 0) {
|
|
|
|
|
if (e!= null && !e.isEmpty()) {
|
|
|
|
|
e.forEach(enr -> applyEnrichment(i, enr));
|
|
|
|
|
} else {
|
|
|
|
|
final List<Instance> a = findEnrichmentsByPID(i.getAlternateIdentifier(), ri);
|
|
|
|
|
if (a!= null && a.size()> 0) {
|
|
|
|
|
final List<Instance> a = findEnrichmentsByAlternateIdentifier(i.getAlternateIdentifier(), ri);
|
|
|
|
|
if (a!= null && !a.isEmpty()) {
|
|
|
|
|
a.forEach(enr -> applyEnrichment(i, enr));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|