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

54 lines
1.6 KiB
Java
Raw Normal View History

2020-05-08 16:49:47 +02:00
package eu.dnetlib.dhp.broker.oa.matchers.relatedProjects;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
2020-05-13 12:00:27 +02:00
import eu.dnetlib.dhp.broker.model.Topic;
import eu.dnetlib.dhp.broker.oa.matchers.UpdateMatcher;
import eu.dnetlib.dhp.broker.oa.util.ConversionUtils;
2020-05-15 12:25:37 +02:00
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.RelatedProject;
import eu.dnetlib.dhp.broker.oa.util.aggregators.withRels.ResultWithRelations;
2020-06-09 16:01:31 +02:00
import eu.dnetlib.pace.config.DedupConfig;
public class EnrichMissingProject
2020-06-11 11:25:18 +02:00
extends UpdateMatcher<eu.dnetlib.broker.objects.Project> {
2020-05-13 12:00:27 +02:00
public EnrichMissingProject() {
super(true);
}
@Override
2020-06-11 11:25:18 +02:00
protected List<UpdateInfo<eu.dnetlib.broker.objects.Project>> findUpdates(final ResultWithRelations source,
final ResultWithRelations target,
2020-06-09 16:01:31 +02:00
final DedupConfig dedupConfig) {
2020-06-11 11:25:18 +02:00
if (source.getProjects().isEmpty()) {
return Arrays.asList();
} else {
2020-06-08 08:32:22 +02:00
return target
2020-06-11 11:25:18 +02:00
.getProjects()
.stream()
2020-06-11 11:25:18 +02:00
.map(RelatedProject::getRelProject)
.map(ConversionUtils::oafProjectToBrokerProject)
2020-06-09 16:01:31 +02:00
.map(p -> generateUpdateInfo(p, source, target, dedupConfig))
.collect(Collectors.toList());
}
}
public UpdateInfo<eu.dnetlib.broker.objects.Project> generateUpdateInfo(
final eu.dnetlib.broker.objects.Project 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-13 12:00:27 +02:00
return new UpdateInfo<>(
Topic.ENRICH_MISSING_PROJECT,
2020-06-11 11:25:18 +02:00
highlightValue, source, target,
2020-05-13 12:00:27 +02:00
(p, prj) -> p.getProjects().add(prj),
2020-06-09 16:01:31 +02:00
prj -> prj.getFunder() + "::" + prj.getFundingProgram() + prj.getCode(), dedupConfig);
}
}