2020-06-09 15:37:46 +02:00
|
|
|
|
2020-07-20 17:54:28 +02:00
|
|
|
package eu.dnetlib.dhp.oa.graph.dump;
|
2020-06-09 15:37:46 +02:00
|
|
|
|
2020-06-15 11:12:14 +02:00
|
|
|
import java.io.StringReader;
|
|
|
|
import java.util.List;
|
|
|
|
|
2020-06-11 12:59:22 +02:00
|
|
|
import org.dom4j.Document;
|
|
|
|
import org.dom4j.DocumentException;
|
|
|
|
import org.dom4j.Element;
|
|
|
|
import org.dom4j.io.SAXReader;
|
2021-08-11 12:13:22 +02:00
|
|
|
import org.xml.sax.SAXException;
|
2020-06-09 15:37:46 +02:00
|
|
|
|
2020-07-24 17:27:26 +02:00
|
|
|
import eu.dnetlib.dhp.oa.graph.dump.community.CommunityMap;
|
2020-06-15 11:12:14 +02:00
|
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
|
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
2020-06-09 15:37:46 +02:00
|
|
|
|
2020-06-09 15:39:03 +02:00
|
|
|
public class QueryInformationSystem {
|
2020-06-11 12:59:22 +02:00
|
|
|
|
|
|
|
private ISLookUpService isLookUp;
|
|
|
|
|
2021-07-13 18:07:25 +02:00
|
|
|
private static final String XQUERY_ALL = "for $x in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType') "
|
2020-06-15 11:12:14 +02:00
|
|
|
+
|
|
|
|
" where $x//CONFIGURATION/context[./@type='community' or ./@type='ri'] " +
|
2021-07-13 17:32:38 +02:00
|
|
|
" and ($x//context/param[./@name = 'status']/text() = 'all') "
|
2020-07-08 10:29:37 +02:00
|
|
|
+
|
2020-06-15 11:12:14 +02:00
|
|
|
" return " +
|
|
|
|
"<community> " +
|
|
|
|
"{$x//CONFIGURATION/context/@id}" +
|
|
|
|
"{$x//CONFIGURATION/context/@label}" +
|
|
|
|
"</community>";
|
2020-06-09 15:39:03 +02:00
|
|
|
|
2021-07-13 18:07:25 +02:00
|
|
|
private static final String XQUERY_CI = "for $x in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType') "
|
2021-08-06 18:56:18 +02:00
|
|
|
+
|
|
|
|
" where $x//CONFIGURATION/context[./@type='community' or ./@type='ri'] " +
|
|
|
|
" and $x//CONFIGURATION/context[./@id=%s] "
|
|
|
|
+
|
|
|
|
" return " +
|
|
|
|
"<community> " +
|
|
|
|
"{$x//CONFIGURATION/context/@id}" +
|
|
|
|
"{$x//CONFIGURATION/context/@label}" +
|
|
|
|
"</community>";
|
2021-07-13 18:07:25 +02:00
|
|
|
|
2021-10-04 18:40:07 +02:00
|
|
|
public CommunityMap getCommunityMap(boolean singleCommunity, String communityId)
|
2021-08-11 12:13:22 +02:00
|
|
|
throws ISLookUpException, DocumentException, SAXException {
|
2021-07-13 18:07:25 +02:00
|
|
|
if (singleCommunity)
|
2021-10-04 18:40:07 +02:00
|
|
|
return getMap(isLookUp.quickSearchProfile(XQUERY_CI.replace("%s", "'" + communityId + "'")));
|
2021-07-13 18:07:25 +02:00
|
|
|
return getMap(isLookUp.quickSearchProfile(XQUERY_ALL));
|
2020-06-11 12:59:22 +02:00
|
|
|
|
|
|
|
}
|
2020-06-09 15:37:46 +02:00
|
|
|
|
2020-06-11 12:59:22 +02:00
|
|
|
public ISLookUpService getIsLookUp() {
|
|
|
|
return isLookUp;
|
2020-06-09 15:37:46 +02:00
|
|
|
}
|
|
|
|
|
2020-06-11 12:59:22 +02:00
|
|
|
public void setIsLookUp(ISLookUpService isLookUpService) {
|
|
|
|
this.isLookUp = isLookUpService;
|
|
|
|
}
|
|
|
|
|
2021-08-11 12:13:22 +02:00
|
|
|
private CommunityMap getMap(List<String> communityMap) throws DocumentException, SAXException {
|
2020-06-15 11:12:14 +02:00
|
|
|
final CommunityMap map = new CommunityMap();
|
2020-06-09 15:37:46 +02:00
|
|
|
|
2020-08-13 12:04:33 +02:00
|
|
|
for (String xml : communityMap) {
|
2020-06-11 12:59:22 +02:00
|
|
|
final Document doc;
|
2021-08-11 12:13:22 +02:00
|
|
|
final SAXReader reader = new SAXReader();
|
2021-10-19 10:15:26 +02:00
|
|
|
reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
2021-08-11 12:13:22 +02:00
|
|
|
doc = reader.read(new StringReader(xml));
|
2020-08-13 12:04:33 +02:00
|
|
|
Element root = doc.getRootElement();
|
|
|
|
map.put(root.attribute("id").getValue(), root.attribute("label").getValue());
|
|
|
|
}
|
2020-06-09 15:39:03 +02:00
|
|
|
|
2020-06-11 12:59:22 +02:00
|
|
|
return map;
|
|
|
|
}
|
2020-06-09 15:39:03 +02:00
|
|
|
|
2020-06-09 15:37:46 +02:00
|
|
|
}
|