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.Arrays;
|
|
|
|
import java.util.List;
|
2020-05-15 12:25:37 +02:00
|
|
|
import java.util.stream.Collectors;
|
2020-05-07 12:31:26 +02:00
|
|
|
|
|
|
|
import eu.dnetlib.broker.objects.Pid;
|
2020-05-13 12:00:27 +02:00
|
|
|
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;
|
|
|
|
import eu.dnetlib.dhp.broker.oa.util.UpdateInfo;
|
2020-05-07 12:31:26 +02:00
|
|
|
import eu.dnetlib.dhp.schema.oaf.Result;
|
2020-06-09 16:01:31 +02:00
|
|
|
import eu.dnetlib.pace.config.DedupConfig;
|
2020-05-07 12:31:26 +02:00
|
|
|
|
2020-05-21 16:47:53 +02:00
|
|
|
public class EnrichMissingPid extends UpdateMatcher<Result, Pid> {
|
2020-05-07 12:31:26 +02:00
|
|
|
|
2020-05-13 12:00:27 +02:00
|
|
|
public EnrichMissingPid() {
|
|
|
|
super(true);
|
2020-05-07 12:31:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-06-10 12:11:16 +02:00
|
|
|
protected List<UpdateInfo<Pid>> findUpdates(final Result source, final Result target,
|
|
|
|
final DedupConfig dedupConfig) {
|
2020-05-15 12:25:37 +02:00
|
|
|
final long count = target.getPid().size();
|
|
|
|
|
2020-06-10 12:11:16 +02:00
|
|
|
if (count > 0) {
|
|
|
|
return Arrays.asList();
|
|
|
|
}
|
2020-05-15 12:25:37 +02:00
|
|
|
|
|
|
|
return source
|
|
|
|
.getPid()
|
|
|
|
.stream()
|
|
|
|
.map(ConversionUtils::oafPidToBrokerPid)
|
2020-06-09 16:01:31 +02:00
|
|
|
.map(i -> generateUpdateInfo(i, source, target, dedupConfig))
|
2020-05-15 12:25:37 +02:00
|
|
|
.collect(Collectors.toList());
|
2020-05-07 12:31:26 +02:00
|
|
|
}
|
|
|
|
|
2020-06-10 12:11:16 +02:00
|
|
|
public UpdateInfo<Pid> generateUpdateInfo(final Pid highlightValue, final Result source, final Result target,
|
|
|
|
final DedupConfig dedupConfig) {
|
2020-05-13 12:00:27 +02:00
|
|
|
return new UpdateInfo<>(
|
|
|
|
Topic.ENRICH_MISSING_PID,
|
|
|
|
highlightValue, source, target,
|
|
|
|
(p, pid) -> p.getPids().add(pid),
|
2020-06-09 16:01:31 +02:00
|
|
|
pid -> pid.getType() + "::" + pid.getValue(), dedupConfig);
|
2020-05-07 12:31:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|