From edcb17ca9827c39c8662b3083d2246dd91bd26ab Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Fri, 3 Nov 2023 13:01:14 +0100 Subject: [PATCH] refactoring and test --- .../PrepareResultCommunitySet.java | 2 +- .../SparkResultToCommunityFromProject.java | 18 +++++++++-- .../dnetlib/dhp/bulktag/BulkTagJobTest.java | 1 - .../ResultToCommunityJobTest.java | 31 +++++++++++++------ 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/dhp-workflows/dhp-enrichment/src/main/java/eu/dnetlib/dhp/resulttocommunityfromproject/PrepareResultCommunitySet.java b/dhp-workflows/dhp-enrichment/src/main/java/eu/dnetlib/dhp/resulttocommunityfromproject/PrepareResultCommunitySet.java index 9a2f25fa6..7bee1ea0c 100644 --- a/dhp-workflows/dhp-enrichment/src/main/java/eu/dnetlib/dhp/resulttocommunityfromproject/PrepareResultCommunitySet.java +++ b/dhp-workflows/dhp-enrichment/src/main/java/eu/dnetlib/dhp/resulttocommunityfromproject/PrepareResultCommunitySet.java @@ -56,7 +56,7 @@ public class PrepareResultCommunitySet { log.info("production: {}", production); final CommunityEntityMap projectsMap = Utils.getCommunityProjects(production); - //log.info("projectsMap: {}", new Gson().toJson(projectsMap)); + // log.info("projectsMap: {}", new Gson().toJson(projectsMap)); SparkConf conf = new SparkConf(); diff --git a/dhp-workflows/dhp-enrichment/src/main/java/eu/dnetlib/dhp/resulttocommunityfromproject/SparkResultToCommunityFromProject.java b/dhp-workflows/dhp-enrichment/src/main/java/eu/dnetlib/dhp/resulttocommunityfromproject/SparkResultToCommunityFromProject.java index 90c30f812..6e298cf94 100644 --- a/dhp-workflows/dhp-enrichment/src/main/java/eu/dnetlib/dhp/resulttocommunityfromproject/SparkResultToCommunityFromProject.java +++ b/dhp-workflows/dhp-enrichment/src/main/java/eu/dnetlib/dhp/resulttocommunityfromproject/SparkResultToCommunityFromProject.java @@ -112,7 +112,7 @@ public class SparkResultToCommunityFromProject implements Serializable { R ret = value._1(); Optional rcl = Optional.ofNullable(value._2()); if (rcl.isPresent()) { - ArrayList communitySet = rcl.get().getCommunityList(); + // ArrayList communitySet = rcl.get().getCommunityList(); List contextList = ret .getContext() .stream() @@ -124,7 +124,7 @@ public class SparkResultToCommunityFromProject implements Serializable { res.setId(ret.getId()); List propagatedContexts = new ArrayList<>(); - for (String cId : communitySet) { + for (String cId : rcl.get().getCommunityList()) { if (!contextList.contains(cId)) { Context newContext = new Context(); newContext.setId(cId); @@ -138,6 +138,20 @@ public class SparkResultToCommunityFromProject implements Serializable { PROPAGATION_RESULT_COMMUNITY_PROJECT_CLASS_NAME, ModelConstants.DNET_PROVENANCE_ACTIONS))); propagatedContexts.add(newContext); + } else { + ret + .getContext() + .stream() + .filter(c -> c.getId().equals(cId)) + .findFirst() + .get() + .getDataInfo() + .add( + getDataInfo( + PROPAGATION_DATA_INFO_TYPE, + PROPAGATION_RESULT_COMMUNITY_PROJECT_CLASS_ID, + PROPAGATION_RESULT_COMMUNITY_PROJECT_CLASS_NAME, + ModelConstants.DNET_PROVENANCE_ACTIONS)); } } res.setContext(propagatedContexts); diff --git a/dhp-workflows/dhp-enrichment/src/test/java/eu/dnetlib/dhp/bulktag/BulkTagJobTest.java b/dhp-workflows/dhp-enrichment/src/test/java/eu/dnetlib/dhp/bulktag/BulkTagJobTest.java index d02faedec..efabcc6bc 100644 --- a/dhp-workflows/dhp-enrichment/src/test/java/eu/dnetlib/dhp/bulktag/BulkTagJobTest.java +++ b/dhp-workflows/dhp-enrichment/src/test/java/eu/dnetlib/dhp/bulktag/BulkTagJobTest.java @@ -6,7 +6,6 @@ import static eu.dnetlib.dhp.bulktag.community.TaggingConstants.ZENODO_COMMUNITY import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; - import java.util.List; import org.apache.commons.io.FileUtils; diff --git a/dhp-workflows/dhp-enrichment/src/test/java/eu/dnetlib/dhp/resulttocommunityfromproject/ResultToCommunityJobTest.java b/dhp-workflows/dhp-enrichment/src/test/java/eu/dnetlib/dhp/resulttocommunityfromproject/ResultToCommunityJobTest.java index b705af8ac..5642501b3 100644 --- a/dhp-workflows/dhp-enrichment/src/test/java/eu/dnetlib/dhp/resulttocommunityfromproject/ResultToCommunityJobTest.java +++ b/dhp-workflows/dhp-enrichment/src/test/java/eu/dnetlib/dhp/resulttocommunityfromproject/ResultToCommunityJobTest.java @@ -8,7 +8,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.List; -import eu.dnetlib.dhp.schema.oaf.Context; import org.apache.commons.io.FileUtils; import org.apache.spark.SparkConf; import org.apache.spark.api.java.JavaRDD; @@ -27,6 +26,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import eu.dnetlib.dhp.orcidtoresultfromsemrel.OrcidPropagationJobTest; import eu.dnetlib.dhp.resulttocommunityfromorganization.SparkResultToCommunityFromOrganizationJob; +import eu.dnetlib.dhp.schema.oaf.Context; import eu.dnetlib.dhp.schema.oaf.Dataset; public class ResultToCommunityJobTest { @@ -98,23 +98,36 @@ public class ResultToCommunityJobTest { * {"resultId":"50|57a035e5b1ae::803aaad4decab7e27cd4b52a1931b3a1","communityList":["sdsn-gr"]} * {"resultId":"50|57a035e5b1ae::a02e9e4087bca50687731ae5c765b5e1","communityList":["netherlands"]} */ - List context = tmp.filter(r -> r.getId().equals("50|57a035e5b1ae::d5be548ca7ae489d762f893be67af52f")) - .first().getContext(); + List context = tmp + .filter(r -> r.getId().equals("50|57a035e5b1ae::d5be548ca7ae489d762f893be67af52f")) + .first() + .getContext(); Assertions.assertTrue(context.stream().anyMatch(c -> containsResultCommunityProject(c))); - context = tmp.filter(r -> r.getId().equals("50|57a035e5b1ae::a77232ffca9115fcad51c3503dbc7e3e")) - .first().getContext(); + context = tmp + .filter(r -> r.getId().equals("50|57a035e5b1ae::a77232ffca9115fcad51c3503dbc7e3e")) + .first() + .getContext(); Assertions.assertTrue(context.stream().anyMatch(c -> containsResultCommunityProject(c))); - Assertions.assertEquals(0, tmp.filter(r -> r.getId().equals("50|57a035e5b1ae::803aaad4decab7e27cd4b52a1931b3a1")).count()); + Assertions + .assertEquals( + 0, tmp.filter(r -> r.getId().equals("50|57a035e5b1ae::803aaad4decab7e27cd4b52a1931b3a1")).count()); - Assertions.assertEquals(0, tmp.filter(r -> r.getId().equals("50|57a035e5b1ae::a02e9e4087bca50687731ae5c765b5e1")).count()); + Assertions + .assertEquals( + 0, tmp.filter(r -> r.getId().equals("50|57a035e5b1ae::a02e9e4087bca50687731ae5c765b5e1")).count()); - Assertions.assertEquals(2, tmp.filter(r -> r.getContext().stream().anyMatch(c -> c.getId().equals("aurora"))).count()); + Assertions + .assertEquals( + 2, tmp.filter(r -> r.getContext().stream().anyMatch(c -> c.getId().equals("aurora"))).count()); } private static boolean containsResultCommunityProject(Context c) { - return c.getDataInfo().stream().anyMatch(di -> di.getProvenanceaction().getClassid().equals("result:community:project")); + return c + .getDataInfo() + .stream() + .anyMatch(di -> di.getProvenanceaction().getClassid().equals("result:community:project")); } }