map construction moved in class

This commit is contained in:
Miriam Baglioni 2020-06-11 12:59:22 +02:00
parent db27663750
commit 356dd582a3
2 changed files with 43 additions and 4 deletions

View File

@ -4,10 +4,20 @@ package eu.dnetlib.dhp.oa.graph.dump;
import eu.dnetlib.dhp.utils.ISLookupClientFactory; import eu.dnetlib.dhp.utils.ISLookupClientFactory;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; 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.List;
import java.util.Map;
public class QueryInformationSystem { public class QueryInformationSystem {
private ISLookUpService isLookUp;
private static final String XQUERY = "for $x in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType') " + private static final String XQUERY = "for $x in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType') " +
" where $x//CONFIGURATION/context[./@type='community' or ./@type='ri'] " + " where $x//CONFIGURATION/context[./@type='community' or ./@type='ri'] " +
" return " + " return " +
@ -18,16 +28,41 @@ public class QueryInformationSystem {
public List<String> getCommunityMap(final String isLookupUrl) public Map<String,String> getCommunityMap()
throws ISLookUpException { throws ISLookUpException {
ISLookUpService isLookUp = ISLookupClientFactory.getLookUpService(isLookupUrl); return getMap(isLookUp.quickSearchProfile(XQUERY));
return 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<String, String> getMap(List<String> communityMap) {
final Map<String, String> 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;
}
} }

View File

@ -0,0 +1,4 @@
package eu.dnetlib.dhp.oa.graph.dump;
public class QueryInformationSystemTest {
}