[DUMP INDICATORS ] added code and resource to test the serialization of indicators
This commit is contained in:
parent
bdd1cfc1e0
commit
0a53c29a8f
|
@ -6,6 +6,7 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.spark.SparkConf;
|
||||
|
@ -26,8 +27,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import com.google.gson.Gson;
|
||||
|
||||
import eu.dnetlib.dhp.oa.graph.dump.community.CommunityMap;
|
||||
import eu.dnetlib.dhp.oa.model.Instance;
|
||||
import eu.dnetlib.dhp.oa.model.OpenAccessRoute;
|
||||
import eu.dnetlib.dhp.oa.model.*;
|
||||
import eu.dnetlib.dhp.oa.model.community.CommunityResult;
|
||||
import eu.dnetlib.dhp.oa.model.graph.GraphResult;
|
||||
import eu.dnetlib.dhp.schema.common.ModelConstants;
|
||||
|
@ -110,7 +110,42 @@ public class DumpJobTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPublicationDump() {
|
||||
public void testDumpIndicators() {
|
||||
final String sourcePath = getClass()
|
||||
.getResource("/eu/dnetlib/dhp/oa/graph/dump/resultDump/publicationWithMeasures")
|
||||
.getPath();
|
||||
|
||||
final String communityMapPath = getClass()
|
||||
.getResource("/eu/dnetlib/dhp/oa/graph/dump/communityMapPath/communitymap.json")
|
||||
.getPath();
|
||||
|
||||
DumpProducts dump = new DumpProducts();
|
||||
dump
|
||||
.run(
|
||||
// false, sourcePath, workingDir.toString() + "/result", communityMapPath, Publication.class,
|
||||
false, sourcePath, workingDir.toString() + "/result", communityMapPath, Publication.class,
|
||||
GraphResult.class, Constants.DUMPTYPE.COMPLETE.getType());
|
||||
|
||||
final JavaSparkContext sc = JavaSparkContext.fromSparkContext(spark.sparkContext());
|
||||
|
||||
JavaRDD<GraphResult> tmp = sc
|
||||
.textFile(workingDir.toString() + "/result")
|
||||
.map(item -> OBJECT_MAPPER.readValue(item, GraphResult.class));
|
||||
|
||||
org.apache.spark.sql.Dataset<GraphResult> verificationDataset = spark
|
||||
.createDataset(tmp.rdd(), Encoders.bean(GraphResult.class));
|
||||
|
||||
Assertions.assertEquals(1, verificationDataset.count());
|
||||
|
||||
GraphResult gr = verificationDataset.first();
|
||||
|
||||
Assertions.assertTrue(Optional.ofNullable(gr.getIndicators().getUsageCounts()).isPresent());
|
||||
Assertions.assertFalse(Optional.ofNullable(gr.getIndicators().getImpactMeasures()).isPresent());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPublicationDump() throws JsonProcessingException {
|
||||
final String sourcePath = getClass()
|
||||
.getResource("/eu/dnetlib/dhp/oa/graph/dump/resultDump/publication_extendedinstance")
|
||||
.getPath();
|
||||
|
@ -139,6 +174,8 @@ public class DumpJobTest {
|
|||
|
||||
GraphResult gr = verificationDataset.first();
|
||||
|
||||
System.out.println(new ObjectMapper().writeValueAsString(gr));
|
||||
|
||||
Assertions.assertEquals(6, gr.getAuthor().size());
|
||||
Assertions
|
||||
.assertTrue(
|
||||
|
@ -320,252 +357,44 @@ public class DumpJobTest {
|
|||
|
||||
Assertions.assertEquals("2020-03-23T00:20:51.392Z", gr.getDateofcollection());
|
||||
|
||||
Assertions.assertEquals(7, gr.getIndicators().size());
|
||||
Assertions.assertTrue(Optional.ofNullable(gr.getIndicators().getUsageCounts()).isPresent());
|
||||
Assertions.assertTrue(Optional.ofNullable(gr.getIndicators().getImpactMeasures()).isPresent());
|
||||
|
||||
Assertions
|
||||
.assertEquals(1, gr.getIndicators().stream().filter(i -> i.getId().equalsIgnoreCase("influence")).count());
|
||||
.assertTrue(gr.getIndicators().getImpactMeasures().getInfluence() != null);
|
||||
Assertions
|
||||
.assertEquals(
|
||||
1, gr.getIndicators().stream().filter(i -> i.getId().equalsIgnoreCase("popularity_alt")).count());
|
||||
Assertions
|
||||
.assertEquals(1, gr.getIndicators().stream().filter(i -> i.getId().equalsIgnoreCase("popularity")).count());
|
||||
Assertions
|
||||
.assertEquals(
|
||||
1, gr.getIndicators().stream().filter(i -> i.getId().equalsIgnoreCase("influence_alt")).count());
|
||||
Assertions
|
||||
.assertEquals(1, gr.getIndicators().stream().filter(i -> i.getId().equalsIgnoreCase("impulse")).count());
|
||||
Assertions
|
||||
.assertEquals(1, gr.getIndicators().stream().filter(i -> i.getId().equalsIgnoreCase("downloads")).count());
|
||||
Assertions
|
||||
.assertEquals(1, gr.getIndicators().stream().filter(i -> i.getId().equalsIgnoreCase("views")).count());
|
||||
.assertTrue(gr.getIndicators().getImpactMeasures().getPopularity_alt() != null);
|
||||
|
||||
Assertions
|
||||
.assertEquals(
|
||||
2, gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("influence"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.count());
|
||||
|
||||
.assertTrue(gr.getIndicators().getImpactMeasures().getPopularity() != null);
|
||||
Assertions
|
||||
.assertEquals(
|
||||
2, gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("influence_alt"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.count());
|
||||
|
||||
.assertTrue(gr.getIndicators().getImpactMeasures().getInfluence_alt() != null);
|
||||
Assertions
|
||||
.assertEquals(
|
||||
2, gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("popularity"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.count());
|
||||
|
||||
.assertTrue(gr.getIndicators().getImpactMeasures().getImpulse() != null);
|
||||
Assertions
|
||||
.assertEquals(
|
||||
2, gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("popularity_alt"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.count());
|
||||
|
||||
.assertTrue(gr.getIndicators().getUsageCounts() != null);
|
||||
Assertions
|
||||
.assertEquals(
|
||||
2, gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("impulse"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.count());
|
||||
|
||||
.assertTrue(Integer.valueOf(gr.getIndicators().getUsageCounts().getDownloads()) >= 0);
|
||||
Assertions
|
||||
.assertEquals(
|
||||
1, gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("downloads"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.count());
|
||||
.assertTrue(Integer.valueOf(gr.getIndicators().getUsageCounts().getViews()) >= 0);
|
||||
|
||||
Assertions
|
||||
.assertEquals(
|
||||
1, gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("views"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.count());
|
||||
Assertions.assertEquals("6.01504990349e-09", gr.getIndicators().getImpactMeasures().getInfluence().getScore());
|
||||
Assertions.assertEquals("C", gr.getIndicators().getImpactMeasures().getInfluence().getClazz());
|
||||
|
||||
Assertions
|
||||
.assertTrue(
|
||||
gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("influence"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.anyMatch(m -> m.getKey().equals("score") && m.getValue().equals("6.01504990349e-09")));
|
||||
Assertions.assertEquals("2.304", gr.getIndicators().getImpactMeasures().getPopularity_alt().getScore());
|
||||
Assertions.assertEquals("C", gr.getIndicators().getImpactMeasures().getPopularity_alt().getClazz());
|
||||
|
||||
Assertions
|
||||
.assertTrue(
|
||||
gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("influence"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.anyMatch(m -> m.getKey().equals("class") && m.getValue().equals("C")));
|
||||
Assertions.assertEquals("1.81666032463e-08", gr.getIndicators().getImpactMeasures().getPopularity().getScore());
|
||||
Assertions.assertEquals("C", gr.getIndicators().getImpactMeasures().getPopularity().getClazz());
|
||||
|
||||
Assertions
|
||||
.assertTrue(
|
||||
gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("popularity_alt"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.anyMatch(m -> m.getKey().equals("score") && m.getValue().equals("2.304")));
|
||||
Assertions.assertEquals("8.0", gr.getIndicators().getImpactMeasures().getInfluence_alt().getScore());
|
||||
Assertions.assertEquals("C", gr.getIndicators().getImpactMeasures().getInfluence_alt().getClazz());
|
||||
|
||||
Assertions
|
||||
.assertTrue(
|
||||
gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("popularity_alt"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.anyMatch(m -> m.getKey().equals("class") && m.getValue().equals("C")));
|
||||
Assertions.assertEquals("8.0", gr.getIndicators().getImpactMeasures().getImpulse().getScore());
|
||||
Assertions.assertEquals("C", gr.getIndicators().getImpactMeasures().getImpulse().getClazz());
|
||||
|
||||
Assertions
|
||||
.assertTrue(
|
||||
gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("popularity"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.anyMatch(m -> m.getKey().equals("score") && m.getValue().equals("1.81666032463e-08")));
|
||||
|
||||
Assertions
|
||||
.assertTrue(
|
||||
gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("popularity"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.anyMatch(m -> m.getKey().equals("class") && m.getValue().equals("C")));
|
||||
|
||||
Assertions
|
||||
.assertTrue(
|
||||
gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("influence_alt"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.anyMatch(m -> m.getKey().equals("score") && m.getValue().equals("8.0")));
|
||||
|
||||
Assertions
|
||||
.assertTrue(
|
||||
gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("influence_alt"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.anyMatch(m -> m.getKey().equals("class") && m.getValue().equals("C")));
|
||||
|
||||
Assertions
|
||||
.assertTrue(
|
||||
gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("impulse"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.anyMatch(m -> m.getKey().equals("score") && m.getValue().equals("8.0")));
|
||||
|
||||
Assertions
|
||||
.assertTrue(
|
||||
gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("impulse"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.anyMatch(m -> m.getKey().equals("class") && m.getValue().equals("C")));
|
||||
|
||||
Assertions
|
||||
.assertTrue(
|
||||
gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("downloads"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.anyMatch(m -> m.getKey().equals("count") && m.getValue().equals("0")));
|
||||
|
||||
Assertions
|
||||
.assertTrue(
|
||||
gr
|
||||
.getIndicators()
|
||||
.stream()
|
||||
.filter(i -> i.getId().equalsIgnoreCase("views"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getMeasure()
|
||||
.stream()
|
||||
.anyMatch(m -> m.getKey().equals("count") && m.getValue().equals("1")));
|
||||
Assertions.assertEquals("0", gr.getIndicators().getUsageCounts().getDownloads());
|
||||
Assertions.assertEquals("1", gr.getIndicators().getUsageCounts().getViews());
|
||||
|
||||
Assertions.assertEquals(1, gr.getInstance().size());
|
||||
|
||||
|
@ -596,7 +425,10 @@ public class DumpJobTest {
|
|||
Assertions.assertEquals("2017-01-01", instance.getPublicationdate());
|
||||
Assertions.assertEquals(null, instance.getArticleprocessingcharge());
|
||||
Assertions.assertEquals("peerReviewed", instance.getRefereed());
|
||||
Assertions.assertEquals(5, instance.getIndicators().stream().count());
|
||||
Indicator indicator = instance.getIndicators();
|
||||
|
||||
Assertions.assertFalse(Optional.ofNullable(indicator.getUsageCounts()).isPresent());
|
||||
Assertions.assertTrue(Optional.ofNullable(indicator.getImpactMeasures()).isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1180,4 +1012,15 @@ public class DumpJobTest {
|
|||
.getString(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void provaSerializzazione() throws IOException {
|
||||
ImpactMeasures im = new ImpactMeasures();
|
||||
Score s = new Score();
|
||||
s.setClazz("pippo");
|
||||
s.setScore("pluto");
|
||||
im.setInfluence(s);
|
||||
String st = new ObjectMapper().writeValueAsString(im);
|
||||
System.out.println(st);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue