2020-05-22 17:17:41 +02:00
|
|
|
|
|
|
|
package eu.dnetlib.dhp.broker.oa.matchers.relatedPublications;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
|
|
|
|
import eu.dnetlib.dhp.broker.model.Topic;
|
|
|
|
import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher;
|
|
|
|
import eu.dnetlib.dhp.broker.oa.util.ConversionUtils;
|
|
|
|
import eu.dnetlib.dhp.broker.oa.util.UpdateInfo;
|
|
|
|
import eu.dnetlib.dhp.schema.oaf.Publication;
|
|
|
|
import eu.dnetlib.dhp.schema.oaf.Result;
|
2020-06-09 16:01:31 +02:00
|
|
|
import eu.dnetlib.pace.config.DedupConfig;
|
2020-05-22 17:17:41 +02:00
|
|
|
|
|
|
|
public abstract class AbstractEnrichMissingPublication
|
|
|
|
extends UpdateMatcher<Pair<Result, List<Publication>>, eu.dnetlib.broker.objects.Publication> {
|
|
|
|
|
|
|
|
private final Topic topic;
|
|
|
|
|
|
|
|
public AbstractEnrichMissingPublication(final Topic topic) {
|
|
|
|
super(true);
|
|
|
|
this.topic = topic;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected final List<UpdateInfo<eu.dnetlib.broker.objects.Publication>> findUpdates(
|
|
|
|
final Pair<Result, List<Publication>> source,
|
2020-06-09 16:01:31 +02:00
|
|
|
final Pair<Result, List<Publication>> target,
|
|
|
|
final DedupConfig dedupConfig) {
|
2020-05-22 17:17:41 +02:00
|
|
|
|
|
|
|
final Set<String> existingPublications = target
|
|
|
|
.getRight()
|
|
|
|
.stream()
|
|
|
|
.map(Publication::getId)
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
|
|
return source
|
|
|
|
.getRight()
|
|
|
|
.stream()
|
|
|
|
.filter(d -> !existingPublications.contains(d.getId()))
|
2020-06-05 11:43:00 +02:00
|
|
|
.map(ConversionUtils::oafResultToBrokerPublication)
|
2020-06-09 16:01:31 +02:00
|
|
|
.map(i -> generateUpdateInfo(i, source, target, dedupConfig))
|
2020-05-22 17:17:41 +02:00
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected final UpdateInfo<eu.dnetlib.broker.objects.Publication> generateUpdateInfo(
|
|
|
|
final eu.dnetlib.broker.objects.Publication highlightValue,
|
|
|
|
final Pair<Result, List<Publication>> source,
|
2020-06-09 16:01:31 +02:00
|
|
|
final Pair<Result, List<Publication>> target,
|
|
|
|
final DedupConfig dedupConfig) {
|
2020-05-22 17:17:41 +02:00
|
|
|
return new UpdateInfo<>(
|
|
|
|
getTopic(),
|
|
|
|
highlightValue, source.getLeft(), target.getLeft(),
|
2020-05-26 08:44:15 +02:00
|
|
|
(p, rel) -> p.getPublications().add(rel),
|
2020-06-09 16:01:31 +02:00
|
|
|
rel -> rel.getInstances().get(0).getUrl(), dedupConfig);
|
2020-05-22 17:17:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Topic getTopic() {
|
|
|
|
return topic;
|
|
|
|
}
|
|
|
|
}
|