2020-05-15 12:25:37 +02:00
|
|
|
|
2020-05-22 17:17:41 +02:00
|
|
|
package eu.dnetlib.dhp.broker.oa.matchers.simple;
|
2020-05-15 12:25:37 +02:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import eu.dnetlib.broker.objects.Instance;
|
|
|
|
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.BrokerConstants;
|
|
|
|
import eu.dnetlib.dhp.broker.oa.util.ConversionUtils;
|
|
|
|
import eu.dnetlib.dhp.broker.oa.util.UpdateInfo;
|
2020-06-11 11:25:18 +02:00
|
|
|
import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations;
|
2020-06-09 16:01:31 +02:00
|
|
|
import eu.dnetlib.pace.config.DedupConfig;
|
2020-05-15 12:25:37 +02:00
|
|
|
|
2020-06-11 11:25:18 +02:00
|
|
|
public class EnrichMoreOpenAccess extends UpdateMatcher<Instance> {
|
2020-05-15 12:25:37 +02:00
|
|
|
|
|
|
|
public EnrichMoreOpenAccess() {
|
|
|
|
super(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-06-11 11:25:18 +02:00
|
|
|
protected List<UpdateInfo<Instance>> findUpdates(final ResultWithRelations source,
|
|
|
|
final ResultWithRelations target,
|
2020-06-10 12:11:16 +02:00
|
|
|
final DedupConfig dedupConfig) {
|
2020-05-15 12:25:37 +02:00
|
|
|
final Set<String> urls = target
|
2020-06-11 11:25:18 +02:00
|
|
|
.getResult()
|
2020-05-15 12:25:37 +02:00
|
|
|
.getInstance()
|
|
|
|
.stream()
|
|
|
|
.filter(i -> i.getAccessright().getClassid().equals(BrokerConstants.OPEN_ACCESS))
|
|
|
|
.map(i -> i.getUrl())
|
|
|
|
.flatMap(List::stream)
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
|
|
return source
|
2020-06-11 11:25:18 +02:00
|
|
|
.getResult()
|
2020-05-15 12:25:37 +02:00
|
|
|
.getInstance()
|
|
|
|
.stream()
|
|
|
|
.filter(i -> i.getAccessright().getClassid().equals(BrokerConstants.OPEN_ACCESS))
|
|
|
|
.map(ConversionUtils::oafInstanceToBrokerInstances)
|
2020-06-04 17:10:43 +02:00
|
|
|
.flatMap(List::stream)
|
2020-05-15 12:25:37 +02:00
|
|
|
.filter(i -> !urls.contains(i.getUrl()))
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
public UpdateInfo<Instance> generateUpdateInfo(final Instance highlightValue,
|
2020-06-11 11:25:18 +02:00
|
|
|
final ResultWithRelations source,
|
|
|
|
final ResultWithRelations target,
|
2020-06-09 16:01:31 +02:00
|
|
|
final DedupConfig dedupConfig) {
|
2020-05-15 12:25:37 +02:00
|
|
|
return new UpdateInfo<>(
|
|
|
|
Topic.ENRICH_MORE_OA_VERSION,
|
|
|
|
highlightValue, source, target,
|
|
|
|
(p, i) -> p.getInstances().add(i),
|
2020-06-09 16:01:31 +02:00
|
|
|
Instance::getUrl, dedupConfig);
|
2020-05-15 12:25:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|