From 356dd582a390f5fcadcd44e737b741b6c0d3c4ce Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Thu, 11 Jun 2020 12:59:22 +0200 Subject: [PATCH] map construction moved in class --- .../oa/graph/dump/QueryInformationSystem.java | 43 +++++++++++++++++-- .../dump/QueryInformationSystemTest.java | 4 ++ 2 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/QueryInformationSystemTest.java diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/QueryInformationSystem.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/QueryInformationSystem.java index c3bf652290..ab98335cab 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/QueryInformationSystem.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/QueryInformationSystem.java @@ -4,10 +4,20 @@ package eu.dnetlib.dhp.oa.graph.dump; import eu.dnetlib.dhp.utils.ISLookupClientFactory; import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; +import java.io.StringReader; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class QueryInformationSystem { + + private ISLookUpService isLookUp; + private static final String XQUERY = "for $x in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType') " + " where $x//CONFIGURATION/context[./@type='community' or ./@type='ri'] " + " return " + @@ -18,16 +28,41 @@ public class QueryInformationSystem { - public List getCommunityMap(final String isLookupUrl) + public Map getCommunityMap() throws ISLookUpException { - ISLookUpService isLookUp = ISLookupClientFactory.getLookUpService(isLookupUrl); - return isLookUp.quickSearchProfile(XQUERY); + return getMap(isLookUp.quickSearchProfile(XQUERY)); } + public ISLookUpService getIsLookUp() { + return isLookUp; + } + + public void setIsLookUp(ISLookUpService isLookUpService) { + this.isLookUp = isLookUpService; + } + +public void set(String isLookUpUrl){ + isLookUpUrl = get(isLookUpUrl); +} + public ISLookUpService + private static Map getMap(List communityMap) { + final Map map = new HashMap<>(); + + communityMap.stream().forEach(xml -> { + final Document doc; + try { + doc = new SAXReader().read(new StringReader(xml)); + Element root = doc.getRootElement(); + map.put(root.attribute("id").getValue(), root.attribute("label").getValue()); + } catch (DocumentException e) { + e.printStackTrace(); + } + }); - + return map; + } } diff --git a/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/QueryInformationSystemTest.java b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/QueryInformationSystemTest.java new file mode 100644 index 0000000000..fb3269eed9 --- /dev/null +++ b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/QueryInformationSystemTest.java @@ -0,0 +1,4 @@ +package eu.dnetlib.dhp.oa.graph.dump; + +public class QueryInformationSystemTest { +}