2020-05-08 16:49:47 +02:00
|
|
|
|
2020-05-22 17:17:41 +02:00
|
|
|
package eu.dnetlib.dhp.broker.oa.matchers.relatedProjects;
|
2020-05-07 12:31:26 +02:00
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
2020-06-04 17:10:43 +02:00
|
|
|
import java.util.stream.Collectors;
|
2020-05-07 12:31:26 +02:00
|
|
|
|
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-06-04 17:10:43 +02:00
|
|
|
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;
|
2020-05-07 12:31:26 +02:00
|
|
|
|
2020-05-21 16:47:53 +02:00
|
|
|
public class EnrichMissingProject
|
2020-06-11 11:25:18 +02:00
|
|
|
extends UpdateMatcher<eu.dnetlib.broker.objects.Project> {
|
2020-05-07 12:31:26 +02:00
|
|
|
|
2020-05-13 12:00:27 +02:00
|
|
|
public EnrichMissingProject() {
|
|
|
|
super(true);
|
2020-05-07 12:31:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@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-04 17:10:43 +02:00
|
|
|
|
2020-06-11 11:25:18 +02:00
|
|
|
if (source.getProjects().isEmpty()) {
|
2020-06-04 17:10:43 +02:00
|
|
|
return Arrays.asList();
|
|
|
|
} else {
|
2020-06-08 08:32:22 +02:00
|
|
|
return target
|
2020-06-11 11:25:18 +02:00
|
|
|
.getProjects()
|
2020-06-04 17:10:43 +02:00
|
|
|
.stream()
|
2020-06-11 11:25:18 +02:00
|
|
|
.map(RelatedProject::getRelProject)
|
2020-06-04 17:10:43 +02:00
|
|
|
.map(ConversionUtils::oafProjectToBrokerProject)
|
2020-06-09 16:01:31 +02:00
|
|
|
.map(p -> generateUpdateInfo(p, source, target, dedupConfig))
|
2020-06-04 17:10:43 +02:00
|
|
|
.collect(Collectors.toList());
|
|
|
|
}
|
2020-05-07 12:31:26 +02:00
|
|
|
}
|
|
|
|
|
2020-05-21 16:47:53 +02:00
|
|
|
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);
|
2020-05-07 12:31:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|