List of usage examples for javax.json JsonStructure getValueType
ValueType getValueType();
From source file:edu.harvard.hms.dbmi.bd2k.irct.ri.exac.EXACResourceImplementation.java
@Override public Result runQuery(SecureSession session, Query qep, Result result) throws ResourceInterfaceException { // TODO Auto-generated method stub HttpClient client = createClient(session); result.setResultStatus(ResultStatus.CREATED); // Check Clause if (qep.getClauses().size() != 1) { result.setResultStatus(ResultStatus.ERROR); result.setMessage("Wrong number of clauses"); return result; }// ww w . j a v a 2s . c o m ClauseAbstract clause = qep.getClauses().values().iterator().next(); if (!(clause instanceof WhereClause)) { result.setResultStatus(ResultStatus.ERROR); result.setMessage("Clause is not a where Clause"); return result; } WhereClause whereClause = (WhereClause) clause; // Create Query String urlString = null; // BY ENSEMBL if (whereClause.getPredicateType().getName().equals("ENSEMBL")) { urlString = resourceURL + "/rest" + getResourcePathFromPUI(whereClause.getField().getPui()) + "/" + whereClause.getStringValues().get("ENSEMBLID"); } else if (whereClause.getPredicateType().getName().equals("QUERY")) { // BY QUERY String[] resourcePath = getResourcePathFromPUI(whereClause.getField().getPui()).split("/"); String service = ""; if (resourcePath.length >= 3) { service = "&service=" + resourcePath[2]; } urlString = resourceURL + "/rest/awesome?query=" + whereClause.getStringValues().get("QUERY") + service; } else if (whereClause.getPredicateType().getName().equals("REGION")) { // BY REGION urlString = resourceURL + "/rest" + getResourcePathFromPUI(whereClause.getField().getPui()) + "/" + whereClause.getStringValues().get("CHROMOSOME") + "-" + whereClause.getStringValues().get("START"); if (whereClause.getStringValues().containsKey("STOP")) { urlString += "-" + whereClause.getStringValues().get("STOP"); } } else if (whereClause.getPredicateType().getName().equals("VARIANT")) { // BY VARIANT urlString = resourceURL + "/rest" + getResourcePathFromPUI(whereClause.getField().getPui()) + "/" + whereClause.getStringValues().get("CHROMOSOME") + "-" + whereClause.getStringValues().get("POSITION") + "-" + whereClause.getStringValues().get("REFERENCE") + "-" + whereClause.getStringValues().get("VARIANT"); } // Run Query if (urlString == null) { result.setResultStatus(ResultStatus.ERROR); result.setMessage("Unknown predicate"); return result; } HttpGet get = new HttpGet(urlString); try { HttpResponse response = client.execute(get); JsonReader reader = Json.createReader(response.getEntity().getContent()); JsonStructure results = reader.read(); if (results.getValueType().equals(ValueType.ARRAY)) { result = convertJsonArrayToResultSet((JsonArray) results, result); } else { result = convertJsonObjectToResultSet((JsonObject) results, result); } reader.close(); result.setResultStatus(ResultStatus.COMPLETE); } catch (IOException e) { result.setResultStatus(ResultStatus.ERROR); result.setMessage(e.getMessage()); } // Format Results return result; }