2020-05-21 16:47:53 +02:00
|
|
|
|
2020-05-22 17:17:41 +02:00
|
|
|
package eu.dnetlib.dhp.broker.oa.matchers.relatedProjects;
|
2020-05-21 16:47:53 +02:00
|
|
|
|
|
|
|
import java.util.List;
|
2020-06-04 17:10:43 +02:00
|
|
|
import java.util.Set;
|
|
|
|
import java.util.stream.Collectors;
|
2020-05-21 16:47:53 +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-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-05-21 16:47:53 +02:00
|
|
|
import eu.dnetlib.dhp.schema.oaf.Project;
|
|
|
|
|
2020-06-11 11:25:18 +02:00
|
|
|
public class EnrichMoreProject extends UpdateMatcher<eu.dnetlib.broker.objects.Project> {
|
2020-05-21 16:47:53 +02:00
|
|
|
|
|
|
|
public EnrichMoreProject() {
|
2020-06-12 09:47:55 +02:00
|
|
|
super(true,
|
|
|
|
prj -> Topic.ENRICH_MORE_PROJECT,
|
|
|
|
(p, prj) -> p.getProjects().add(prj),
|
|
|
|
prj -> prj.getFunder() + "::" + prj.getFundingProgram() + prj.getCode());
|
2020-05-21 16:47:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-06-12 09:47:55 +02:00
|
|
|
protected List<eu.dnetlib.broker.objects.Project> findDifferences(final ResultWithRelations source,
|
|
|
|
final ResultWithRelations target) {
|
2020-06-04 17:10:43 +02:00
|
|
|
|
2020-06-08 08:32:22 +02:00
|
|
|
final Set<String> existingProjects = source
|
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(Project::getId)
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
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
|
|
|
.filter(p -> !existingProjects.contains(p.getId()))
|
|
|
|
.map(ConversionUtils::oafProjectToBrokerProject)
|
|
|
|
.collect(Collectors.toList());
|
2020-05-21 16:47:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|