2020-05-08 16:49:47 +02:00
|
|
|
|
2020-05-22 17:17:41 +02:00
|
|
|
package eu.dnetlib.dhp.broker.oa.matchers.simple;
|
2020-05-07 12:31:26 +02:00
|
|
|
|
|
|
|
import java.util.List;
|
2020-05-15 12:25:37 +02:00
|
|
|
import java.util.Set;
|
|
|
|
import java.util.stream.Collectors;
|
2020-05-07 12:31:26 +02:00
|
|
|
|
2020-05-13 12:00:27 +02:00
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
|
|
|
|
import eu.dnetlib.dhp.broker.model.Topic;
|
2020-05-22 17:17:41 +02:00
|
|
|
import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher;
|
2020-05-15 12:25:37 +02:00
|
|
|
import eu.dnetlib.dhp.broker.oa.util.ConversionUtils;
|
2020-06-11 11:25:18 +02:00
|
|
|
import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations;
|
2020-05-07 12:31:26 +02:00
|
|
|
|
2020-06-11 11:25:18 +02:00
|
|
|
public class EnrichMoreSubject extends UpdateMatcher<Pair<String, String>> {
|
2020-05-13 12:00:27 +02:00
|
|
|
|
|
|
|
public EnrichMoreSubject() {
|
2020-06-12 09:47:55 +02:00
|
|
|
super(true,
|
|
|
|
pair -> Topic.fromPath("ENRICH/MORE/SUBJECT/" + pair.getLeft()),
|
|
|
|
(p, pair) -> p.getSubjects().add(pair.getRight()),
|
|
|
|
pair -> pair.getLeft() + "::" + pair.getRight());
|
2020-05-13 12:00:27 +02:00
|
|
|
}
|
2020-05-07 12:31:26 +02:00
|
|
|
|
2020-05-13 12:00:27 +02:00
|
|
|
@Override
|
2020-06-12 09:47:55 +02:00
|
|
|
protected List<Pair<String, String>> findDifferences(final ResultWithRelations source,
|
|
|
|
final ResultWithRelations target) {
|
2020-05-15 12:25:37 +02:00
|
|
|
final Set<String> existingSubjects = target
|
2020-06-11 11:25:18 +02:00
|
|
|
.getResult()
|
2020-05-15 12:25:37 +02:00
|
|
|
.getSubject()
|
|
|
|
.stream()
|
|
|
|
.map(pid -> pid.getQualifier().getClassid() + "::" + pid.getValue())
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
|
|
return source
|
2020-06-11 11:25:18 +02:00
|
|
|
.getResult()
|
2020-05-15 12:25:37 +02:00
|
|
|
.getPid()
|
|
|
|
.stream()
|
|
|
|
.filter(pid -> !existingSubjects.contains(pid.getQualifier().getClassid() + "::" + pid.getValue()))
|
|
|
|
.map(ConversionUtils::oafSubjectToPair)
|
|
|
|
.collect(Collectors.toList());
|
2020-05-07 12:31:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|