This commit is contained in:
Miriam Baglioni 2020-08-13 12:08:24 +02:00
parent 69bbb9592a
commit 90b54d3efb
1 changed files with 44 additions and 49 deletions

View File

@ -1,8 +1,3 @@
/**
* Dumps of entities in the model defined in eu.dnetlib.dhp.schema.dump.oaf.graph.
* Results are dumped using the same Mapper as for eu.dnetlib.dhp.schema.dump.oaf.community, while for
* the other entities the mapping is defined below
*/
package eu.dnetlib.dhp.oa.graph.dump.graph; package eu.dnetlib.dhp.oa.graph.dump.graph;
@ -31,6 +26,10 @@ import eu.dnetlib.dhp.schema.oaf.Field;
import eu.dnetlib.dhp.schema.oaf.Journal; import eu.dnetlib.dhp.schema.oaf.Journal;
import eu.dnetlib.dhp.schema.oaf.OafEntity; import eu.dnetlib.dhp.schema.oaf.OafEntity;
/**
* Dumps of entities in the model defined in eu.dnetlib.dhp.schema.dump.oaf.graph. Results are dumped using the same
* Mapper as for eu.dnetlib.dhp.schema.dump.oaf.community, while for the other entities the mapping is defined below
*/
public class DumpGraphEntities implements Serializable { public class DumpGraphEntities implements Serializable {
public void run(Boolean isSparkSessionManaged, public void run(Boolean isSparkSessionManaged,
@ -285,7 +284,7 @@ public class DumpGraphEntities implements Serializable {
return c; return c;
} }
private static Project mapProject(eu.dnetlib.dhp.schema.oaf.Project p) { private static Project mapProject(eu.dnetlib.dhp.schema.oaf.Project p) throws DocumentException {
Project project = new Project(); Project project = new Project();
Optional Optional
@ -383,61 +382,57 @@ public class DumpGraphEntities implements Serializable {
.collect(Collectors.toList())) .collect(Collectors.toList()))
.orElse(new ArrayList<>())); .orElse(new ArrayList<>()));
project Optional<List<Field<String>>> ofundTree = Optional
.setFunding( .ofNullable(p.getFundingtree());
Optional List<Funder> funList = new ArrayList<>();
.ofNullable(p.getFundingtree()) if (ofundTree.isPresent()) {
.map( for (Field<String> fundingtree : ofundTree.get()) {
value -> value funList.add(getFunder(fundingtree.getValue()));
.stream() }
.map(fundingtree -> getFunder(fundingtree.getValue())) }
.collect(Collectors.toList())) project.setFunding(funList);
.orElse(new ArrayList<>()));
return project; return project;
} }
public static Funder getFunder(String fundingtree) { public static Funder getFunder(String fundingtree) throws DocumentException {
Funder f = new Funder(); Funder f = new Funder();
final Document doc; final Document doc;
try {
doc = new SAXReader().read(new StringReader(fundingtree));
f.setShortName(((org.dom4j.Node) (doc.selectNodes("//funder/shortname").get(0))).getText());
f.setName(((org.dom4j.Node) (doc.selectNodes("//funder/name").get(0))).getText());
f.setJurisdiction(((org.dom4j.Node) (doc.selectNodes("//funder/jurisdiction").get(0))).getText());
// f.setId(((org.dom4j.Node) (doc.selectNodes("//funder/id").get(0))).getText());
String id = ""; doc = new SAXReader().read(new StringReader(fundingtree));
String description = ""; f.setShortName(((org.dom4j.Node) (doc.selectNodes("//funder/shortname").get(0))).getText());
// List<Levels> fundings = new ArrayList<>(); f.setName(((org.dom4j.Node) (doc.selectNodes("//funder/name").get(0))).getText());
int level = 0; f.setJurisdiction(((org.dom4j.Node) (doc.selectNodes("//funder/jurisdiction").get(0))).getText());
List<org.dom4j.Node> nodes = doc.selectNodes("//funding_level_" + level); // f.setId(((org.dom4j.Node) (doc.selectNodes("//funder/id").get(0))).getText());
while (nodes.size() > 0) {
for (org.dom4j.Node n : nodes) {
List node = n.selectNodes("./id"); String id = "";
id = ((org.dom4j.Node) node.get(0)).getText(); String description = "";
id = id.substring(id.indexOf("::") + 2); // List<Levels> fundings = new ArrayList<>();
int level = 0;
List<org.dom4j.Node> nodes = doc.selectNodes("//funding_level_" + level);
while (nodes.size() > 0) {
for (org.dom4j.Node n : nodes) {
node = n.selectNodes("./description"); List node = n.selectNodes("./id");
description += ((Node) node.get(0)).getText() + " - "; id = ((org.dom4j.Node) node.get(0)).getText();
id = id.substring(id.indexOf("::") + 2);
node = n.selectNodes("./description");
description += ((Node) node.get(0)).getText() + " - ";
}
level += 1;
nodes = doc.selectNodes("//funding_level_" + level);
} }
level += 1;
if (!id.equals("")) { nodes = doc.selectNodes("//funding_level_" + level);
Fundings fundings = new Fundings();
fundings.setId(id);
fundings.setDescription(description.substring(0, description.length() - 3).trim());
f.setFunding_stream(fundings);
}
return f;
} catch (DocumentException e) {
e.printStackTrace();
} }
if (!id.equals("")) {
Fundings fundings = new Fundings();
fundings.setId(id);
fundings.setDescription(description.substring(0, description.length() - 3).trim());
f.setFunding_stream(fundings);
}
return f; return f;
} }