Some cleanup.
This commit is contained in:
parent
e5028dc668
commit
59b2d9431e
1 changed files with 54 additions and 44 deletions
|
@ -77,47 +77,10 @@ public class GrefineMqlreadServlet extends VitroHttpServlet {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// parse query
|
// parse query
|
||||||
|
ArrayList<String> subjectUriList = new ArrayList<String>();
|
||||||
|
Map<String, JSONArray> propertyUriMap = new HashMap<String, JSONArray>();
|
||||||
String query = vreq.getParameter("query");
|
String query = vreq.getParameter("query");
|
||||||
System.out.println("query: " + query);
|
parseQuery(query, subjectUriList, propertyUriMap);
|
||||||
|
|
||||||
JSONObject rawJson = new JSONObject(query);
|
|
||||||
JSONArray qJsonArr = rawJson.getJSONArray("query");
|
|
||||||
|
|
||||||
|
|
||||||
ArrayList<String> subjectUriList = new ArrayList();
|
|
||||||
Map<String, JSONArray> propertyUriMap = new HashMap();
|
|
||||||
for (int i=0; i<qJsonArr.length(); i++) {
|
|
||||||
Object obj = qJsonArr.get(i);
|
|
||||||
|
|
||||||
if (obj instanceof JSONObject) {
|
|
||||||
JSONObject jsonObj = (JSONObject)obj;
|
|
||||||
JSONArray jsonObjNames = jsonObj.names();
|
|
||||||
for (int j=0; j<jsonObjNames.length(); j++) {
|
|
||||||
String objName = (String)jsonObjNames.get(j);
|
|
||||||
if (objName.contains("http://")) { // most likely this is a propertyUri
|
|
||||||
// e.g. http://weill.cornell.edu/vivo/ontology/wcmc#cwid
|
|
||||||
Object propertyUriObj = jsonObj.get(objName);
|
|
||||||
if (propertyUriObj instanceof JSONArray) {
|
|
||||||
propertyUriMap.put(objName, (JSONArray)propertyUriObj);
|
|
||||||
}
|
|
||||||
} else if ("id".equals(objName)) { // id
|
|
||||||
Object idObj = jsonObj.get(objName); // TODO: This is a String object but not sure what it is for
|
|
||||||
} else if ("id|=".equals(objName)) { // list of subject uri
|
|
||||||
Object subjectUriObj = jsonObj.get(objName);
|
|
||||||
if (subjectUriObj instanceof JSONArray) {
|
|
||||||
JSONArray subjectUriUriArr = (JSONArray)subjectUriObj;
|
|
||||||
for (int k=0; k<subjectUriUriArr.length(); k++) {
|
|
||||||
// e.g. http://vivo.med.cornell.edu/individual/cwid-jsd2002
|
|
||||||
Object subjectUriUriObj = subjectUriUriArr.get(k);
|
|
||||||
if (subjectUriUriObj instanceof String) {
|
|
||||||
subjectUriList.add((String)subjectUriUriObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// run SPARQL query to get the results
|
// run SPARQL query to get the results
|
||||||
JSONArray resultAllJsonArr = new JSONArray();
|
JSONArray resultAllJsonArr = new JSONArray();
|
||||||
|
@ -153,11 +116,58 @@ public class GrefineMqlreadServlet extends VitroHttpServlet {
|
||||||
resultAllJson.put("result", resultAllJsonArr);
|
resultAllJson.put("result", resultAllJsonArr);
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("JSONException: " + e);
|
log.error("GrefineMqlreadServlet getResult JSONException: " + e);
|
||||||
throw new ServletException("GrefineMqlreadServlet JSONException: " + e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// System.out.println(resultAllJson);
|
// System.out.println(resultAllJson);
|
||||||
return resultAllJson;
|
return resultAllJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct json from query String
|
||||||
|
* @param query
|
||||||
|
* @param subjectUriList
|
||||||
|
* @param propertyUriMap
|
||||||
|
*/
|
||||||
|
private void parseQuery(String query, ArrayList<String> subjectUriList, Map<String, JSONArray> propertyUriMap) {
|
||||||
|
try {
|
||||||
|
JSONObject rawJson = new JSONObject(query);
|
||||||
|
JSONArray qJsonArr = rawJson.getJSONArray("query");
|
||||||
|
for (int i=0; i<qJsonArr.length(); i++) {
|
||||||
|
Object obj = qJsonArr.get(i);
|
||||||
|
|
||||||
|
if (obj instanceof JSONObject) {
|
||||||
|
JSONObject jsonObj = (JSONObject)obj;
|
||||||
|
JSONArray jsonObjNames = jsonObj.names();
|
||||||
|
for (int j=0; j<jsonObjNames.length(); j++) {
|
||||||
|
String objName = (String)jsonObjNames.get(j);
|
||||||
|
if (objName.contains("http://")) { // most likely this is a propertyUri
|
||||||
|
// e.g. http://weill.cornell.edu/vivo/ontology/wcmc#cwid
|
||||||
|
Object propertyUriObj = jsonObj.get(objName);
|
||||||
|
if (propertyUriObj instanceof JSONArray) {
|
||||||
|
propertyUriMap.put(objName, (JSONArray)propertyUriObj);
|
||||||
|
}
|
||||||
|
} else if ("id".equals(objName)) { // id
|
||||||
|
Object idObj = jsonObj.get(objName); // TODO: This is a String object but not sure what it is for
|
||||||
|
} else if ("id|=".equals(objName)) { // list of subject uri
|
||||||
|
Object subjectUriObj = jsonObj.get(objName);
|
||||||
|
if (subjectUriObj instanceof JSONArray) {
|
||||||
|
JSONArray subjectUriUriArr = (JSONArray)subjectUriObj;
|
||||||
|
for (int k=0; k<subjectUriUriArr.length(); k++) {
|
||||||
|
// e.g. http://vivo.med.cornell.edu/individual/cwid-jsd2002
|
||||||
|
Object subjectUriUriObj = subjectUriUriArr.get(k);
|
||||||
|
if (subjectUriUriObj instanceof String) {
|
||||||
|
subjectUriList.add((String)subjectUriUriObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
log.error("GrefineMqlreadServlet parseQuery JSONException: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue