use of org.json.simple.parser.JSONParser in project spatial-portal by AtlasOfLivingAustralia.
the class RemoteLogger method getLogItem.
public JSONObject getLogItem(String logId) {
init();
try {
if (Util.isLoggedIn()) {
String url = loggerService + "/app/view/" + logId + ".json" + "?appid=" + URLEncoder.encode(appid, StringConstants.UTF_8) + "&api_key=" + URLEncoder.encode(CommonData.getSettings().getProperty("api_key"), StringConstants.UTF_8);
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(url);
get.addRequestHeader(StringConstants.ACCEPT, StringConstants.APPLICATION_JSON);
client.executeMethod(get);
LOGGER.debug("get: " + url + ", response: " + get.getResponseBodyAsString());
JSONParser jp = new JSONParser();
return (JSONObject) jp.parse(get.getResponseBodyAsString());
}
} catch (Exception e) {
LOGGER.error("Error getting logging information from server:", e);
}
return null;
}
use of org.json.simple.parser.JSONParser 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.parser.JSONParser in project spatial-portal by AtlasOfLivingAustralia.
the class CommonData method initSpeciesListAdditionalColumns.
private static Map<String, Map<String, List<String>>> initSpeciesListAdditionalColumns() {
Map<String, Map<String, List<String>>> map = new HashMap<String, Map<String, List<String>>>();
String slac = settings.getProperty("species.list.additional.columns", "");
//append dynamic columns
slac += dynamicSpeciesListColumns();
String[] columns = slac.split("\\|");
for (String line : columns) {
String[] parts = line.split(",");
if (parts[0].equals("Conservation")) {
speciesListThreatened = "species_list_uid:" + StringUtils.join(Arrays.copyOfRange(parts, 1, parts.length), " OR species_list_uid:");
}
if (parts[0].equals("Invasive")) {
speciesListInvasive = "species_list_uid:" + StringUtils.join(Arrays.copyOfRange(parts, 1, parts.length), " OR species_list_uid:");
}
if (parts.length > 1) {
String columnTitle = parts[0];
for (int i = 1; i < parts.length; i++) {
try {
JSONParser jp = new JSONParser();
InputStream is = new URL(CommonData.getSpeciesListServer() + "/ws/speciesList?druid=" + parts[i]).openStream();
String listName = ((JSONObject) jp.parse(IOUtils.toString(is))).get("listName").toString();
is.close();
Map<String, List<String>> m = map.get(columnTitle);
if (m == null)
m = new HashMap<String, List<String>>();
ArrayList<String> sp = new ArrayList<String>();
//fetch species list
Collection<SpeciesListItemDTO> list = SpeciesListUtil.getListItems(parts[i]);
for (SpeciesListItemDTO item : list) {
if (item.getLsid() != null && !item.getLsid().isEmpty())
sp.add(item.getLsid());
}
Collections.sort(sp);
m.put(listName, sp);
map.put(columnTitle, m);
} catch (Exception e) {
LOGGER.error("error reading list: " + parts[i], e);
}
}
}
}
return map;
}
use of org.json.simple.parser.JSONParser 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.parser.JSONParser 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");
}
}
Aggregations