use of org.json.simple.JsonObject in project spatial-portal by AtlasOfLivingAustralia.
the class Sampling method getDownloadUrl.
static String getDownloadUrl(String statusUrl) {
String downloadUrl = null;
try {
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(statusUrl);
get.addRequestHeader(StringConstants.CONTENT_TYPE, StringConstants.APPLICATION_JSON);
client.executeMethod(get);
JSONParser jp = new JSONParser();
JSONObject jo = (JSONObject) jp.parse(get.getResponseBodyAsString());
if ("finished".equals(jo.get(StringConstants.STATUS))) {
downloadUrl = jo.get("downloadUrl").toString();
} else if ("cancelled".equals(jo.get(StringConstants.STATUS)) || "error".equals(jo.get(StringConstants.STATUS))) {
downloadUrl = null;
} else {
downloadUrl = "";
}
} catch (Exception e) {
LOGGER.error("error getting response from : " + statusUrl, e);
}
return downloadUrl;
}
use of org.json.simple.JsonObject in project spatial-portal by AtlasOfLivingAustralia.
the class PhylogeneticDiversityListResults method evalArea.
private void evalArea(SelectedArea sa) {
try {
Query sq = QueryUtil.queryFromSelectedArea(selectedQuery, sa, null, false, null);
CSVReader r = new CSVReader(new StringReader(sq.speciesList()));
JSONArray ja = new JSONArray();
for (String[] s : r.readAll()) {
ja.add(s[1]);
}
//call pd with specieslist=ja.toString()
String url = CommonData.getSettings().getProperty(CommonData.PHYLOLIST_URL) + "/phylo/getPD";
NameValuePair[] params = new NameValuePair[2];
params[0] = new NameValuePair("noTreeText", StringConstants.TRUE);
params[1] = new NameValuePair("speciesList", ja.toString());
JSONParser jp = new JSONParser();
JSONArray pds = (JSONArray) jp.parse(Util.readUrlPost(url, params));
Map<String, String> pdrow = new HashMap<String, String>();
Map<String, JSONArray> speciesRow = new HashMap<String, JSONArray>();
for (int j = 0; j < pds.size(); j++) {
String tree = "" + ((JSONObject) pds.get(j)).get(StringConstants.STUDY_ID);
pdrow.put(tree, ((JSONObject) pds.get(j)).get("pd").toString());
speciesRow.put(tree, (JSONArray) ((JSONObject) pds.get(j)).get("taxaRecognised"));
//maxPD retrieval
String maxPd = ((JSONObject) pds.get(j)).get("maxPd").toString();
for (int k = 0; k < selectedTrees.size(); k++) {
if (((Map<String, String>) selectedTrees.get(k)).get(StringConstants.STUDY_ID).equals(tree)) {
((Map<String, String>) selectedTrees.get(k)).put("maxPd", maxPd);
}
}
}
areaPds.add(pdrow);
areaSpeciesMatches.add(speciesRow);
} catch (Exception e) {
LOGGER.error("failed processing a pd for a selected area.", e);
}
}
use of org.json.simple.JsonObject in project spatial-portal by AtlasOfLivingAustralia.
the class AreaReportController method onMapPointsOfInterest.
public void onMapPointsOfInterest(Event event) {
try {
String activeAreaLayerName = "Points of interest in " + areaDisplayName;
StringBuilder sb = new StringBuilder();
sb.append("MULTIPOINT(");
if (pointsOfInterest == null) {
String wkt = selectedArea.getWkt();
if (wkt.contains(StringConstants.ENVELOPE) && selectedArea.getMapLayer() != null) {
// use boundingbox
List<Double> bbox = selectedArea.getMapLayer().getMapLayerMetadata().getBbox();
double long1 = bbox.get(0);
double lat1 = bbox.get(1);
double long2 = bbox.get(2);
double lat2 = bbox.get(3);
wkt = StringConstants.POLYGON + "((" + long1 + " " + lat1 + "," + long1 + " " + lat2 + "," + long2 + " " + lat2 + "," + long2 + " " + lat1 + "," + long1 + " " + lat1 + "))";
} else {
//wkt = selectedArea.getReducedWkt();
}
pointsOfInterest = getPointsOfInterest(wkt);
}
for (int i = 0; i < pointsOfInterest.size(); i++) {
JSONObject jsonObjPoi = (JSONObject) pointsOfInterest.get(i);
double latitude = Double.parseDouble(jsonObjPoi.get(StringConstants.LATITUDE).toString());
double longitude = Double.parseDouble(jsonObjPoi.get(StringConstants.LONGITUDE).toString());
sb.append(longitude);
sb.append(" ");
sb.append(latitude);
if (i < pointsOfInterest.size() - 1) {
sb.append(",");
}
}
sb.append(")");
getMapComposer().mapPointsOfInterest(sb.toString(), activeAreaLayerName, activeAreaLayerName);
} catch (Exception e) {
LOGGER.error("error mapping points of interest", e);
}
}
use of org.json.simple.JsonObject in project spatial-portal by AtlasOfLivingAustralia.
the class SpeciesAutoComplete method getResults.
private JSONArray getResults(String nsurl) throws Exception {
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(nsurl);
get.addRequestHeader(StringConstants.CONTENT_TYPE, StringConstants.TEXT_PLAIN);
client.executeMethod(get);
String rawJSON = get.getResponseBodyAsString();
//parse
JSONParser jp = new JSONParser();
JSONObject jo = (JSONObject) jp.parse(rawJSON);
//support search and auto bie webservices
if (jo.containsKey("searchResults")) {
return (JSONArray) ((JSONObject) jo.get("searchResults")).get("results");
} else {
return (JSONArray) jo.get("autoCompleteList");
}
}
use of org.json.simple.JsonObject in project spatial-portal by AtlasOfLivingAustralia.
the class ProgressController method get.
JSONObject get() {
try {
StringBuilder sbProcessUrl = new StringBuilder();
sbProcessUrl.append(CommonData.getSatServer()).append("/ws/job?pid=").append(pid);
LOGGER.debug("checking status every '" + timer.getDelay() + "' sec: " + sbProcessUrl.toString());
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(sbProcessUrl.toString());
get.addRequestHeader(StringConstants.ACCEPT, StringConstants.APPLICATION_JSON);
client.getHttpConnectionManager().getParams().setSoTimeout(timer.getDelay());
int result = client.executeMethod(get);
if (result == 200) {
JSONParser jp = new JSONParser();
return (JSONObject) jp.parse(get.getResponseBodyAsString());
}
} catch (SocketTimeoutException e) {
LOGGER.debug("progress timeout exception, will be trying again.");
} catch (Exception e) {
LOGGER.error("error getting updated job info pid=" + pid, e);
}
return null;
}
Aggregations