List of usage examples for javax.json JsonException getMessage
public String getMessage()
From source file:edu.harvard.hms.dbmi.bd2k.irct.ri.i2b2transmart.I2B2TranSMARTResourceImplementation.java
@Override public Result runQuery(SecureSession session, Query query, Result result) throws ResourceInterfaceException { result = super.runQuery(session, query, result); if (result.getResultStatus() != ResultStatus.ERROR) { String resultInstanceId = result.getResourceActionId(); String resultId = resultInstanceId.split("\\|")[2]; try {//from www. j av a 2 s .c om // Wait for it to be either ready or fail result = checkForResult(session, result); while ((result.getResultStatus() != ResultStatus.ERROR) && (result.getResultStatus() != ResultStatus.COMPLETE)) { Thread.sleep(3000); result = checkForResult(session, result); } if (result.getResultStatus() == ResultStatus.ERROR) { return result; } result.setResultStatus(ResultStatus.RUNNING); // Loop through the select clauses to build up the select string String gatherAllEncounterFacts = "false"; Map<String, String> aliasMap = new HashMap<String, String>(); for (ClauseAbstract clause : query.getClauses().values()) { if (clause instanceof SelectClause) { SelectClause selectClause = (SelectClause) clause; String pui = convertPUItoI2B2Path(selectClause.getParameter().getPui()); aliasMap.put(pui, selectClause.getAlias()); } else if (clause instanceof WhereClause) { WhereClause whereClause = (WhereClause) clause; String encounter = whereClause.getStringValues().get("ENCOUNTER"); if ((encounter != null) && (encounter.equalsIgnoreCase("yes"))) { gatherAllEncounterFacts = "true"; } } } if (!aliasMap.isEmpty()) { ResultSet rs = (ResultSet) result.getData(); if (rs.getSize() == 0) { rs = createInitialDataset(result, aliasMap, gatherAllEncounterFacts); result.setData(rs); } // Loop through the columns submitting and appending to the // rows every 10 List<String> parameterList = new ArrayList<String>(); int counter = 0; String parameters = ""; for (String param : aliasMap.keySet()) { if (counter == 10) { parameterList.add(parameters); counter = 0; parameters = ""; } if (!parameters.equals("")) { parameters += "|"; } parameters += param; } if (!parameters.equals("")) { parameterList.add(parameters); } for (String parameter : parameterList) { // Call the tranSMART API to get the dataset String url = this.transmartURL + "/ClinicalData/retrieveClinicalData?rid=" + resultId + "&conceptPaths=" + URLEncoder.encode(parameter, "UTF-8") + "&gatherAllEncounterFacts=" + gatherAllEncounterFacts; HttpClient client = createClient(session); HttpGet get = new HttpGet(url); try { HttpResponse response = client.execute(get); JsonReader reader = Json.createReader(response.getEntity().getContent()); JsonArray arrayResults = reader.readArray(); // Convert the dataset to Tabular format result = convertJsonToResultSet(result, arrayResults, aliasMap, gatherAllEncounterFacts); } catch (JsonException e) { } } } // Set the status to complete result.setResultStatus(ResultStatus.COMPLETE); } catch (InterruptedException | UnsupportedOperationException | IOException | ResultSetException | PersistableException e) { result.setResultStatus(ResultStatus.ERROR); result.setMessage(e.getMessage()); } } return result; }