dnet-hadoop/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/matchers/relatedSoftware/EnrichMoreSoftware.java

60 lines
1.8 KiB
Java
Raw Normal View History

package eu.dnetlib.dhp.broker.oa.matchers.relatedSoftware;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
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;
2020-06-11 11:25:18 +02:00
import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.RelatedSoftware;
import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations;
import eu.dnetlib.dhp.schema.oaf.Software;
2020-06-09 16:01:31 +02:00
import eu.dnetlib.pace.config.DedupConfig;
public class EnrichMoreSoftware
2020-06-11 11:25:18 +02:00
extends UpdateMatcher<eu.dnetlib.broker.objects.Software> {
public EnrichMoreSoftware() {
super(true);
}
@Override
protected List<UpdateInfo<eu.dnetlib.broker.objects.Software>> findUpdates(
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-06-08 08:32:22 +02:00
final Set<String> existingSoftwares = source
2020-06-11 11:25:18 +02:00
.getSoftwares()
.stream()
2020-06-11 11:25:18 +02:00
.map(RelatedSoftware::getRelSoftware)
.map(Software::getId)
.collect(Collectors.toSet());
2020-06-08 08:32:22 +02:00
return target
2020-06-11 11:25:18 +02:00
.getSoftwares()
.stream()
2020-06-11 11:25:18 +02:00
.map(RelatedSoftware::getRelSoftware)
.filter(p -> !existingSoftwares.contains(p.getId()))
.map(ConversionUtils::oafSoftwareToBrokerSoftware)
2020-06-09 16:01:31 +02:00
.map(p -> generateUpdateInfo(p, source, target, dedupConfig))
.collect(Collectors.toList());
}
public UpdateInfo<eu.dnetlib.broker.objects.Software> generateUpdateInfo(
final eu.dnetlib.broker.objects.Software 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) {
return new UpdateInfo<>(
Topic.ENRICH_MORE_SOFTWARE,
2020-06-11 11:25:18 +02:00
highlightValue, source, target,
(p, s) -> p.getSoftwares().add(s),
2020-06-09 16:01:31 +02:00
s -> s.getName(), dedupConfig);
}
}