use of org.json.simple.JSONObject in project spatial-portal by AtlasOfLivingAustralia.
the class Util method getDistributionsOrChecklists.
/**
* Generates data for rendering of distributions table.
*
* @param type
* @param wkt
* @param lsids
* @param geomIdx
* @return
*/
public static String[] getDistributionsOrChecklists(String type, String wkt, String lsids, String geomIdx) {
try {
StringBuilder sbProcessUrl = new StringBuilder();
sbProcessUrl.append("/").append(type);
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(CommonData.getLayersServer() + sbProcessUrl.toString());
LOGGER.debug(CommonData.getLayersServer() + sbProcessUrl.toString());
if (wkt != null) {
post.addParameter(StringConstants.WKT, wkt);
}
if (lsids != null) {
post.addParameter(StringConstants.LSIDS, lsids);
}
if (geomIdx != null) {
post.addParameter(StringConstants.GEOM_IDX, geomIdx);
}
post.addRequestHeader(StringConstants.ACCEPT, StringConstants.JSON_JAVASCRIPT_ALL);
int result = client.executeMethod(post);
if (result == 200) {
String txt = post.getResponseBodyAsString();
JSONParser jp = new JSONParser();
JSONArray ja = (JSONArray) jp.parse(txt);
if (ja == null || ja.isEmpty()) {
return new String[0];
} else {
String[] lines = new String[ja.size() + 1];
lines[0] = "SPCODE,SCIENTIFIC_NAME,AUTHORITY_FULL,COMMON_NAME,FAMILY,GENUS_NAME,SPECIFIC_NAME,MIN_DEPTH,MAX_DEPTH,METADATA_URL,LSID,AREA_NAME,AREA_SQ_KM";
for (int i = 0; i < ja.size(); i++) {
JSONObject jo = (JSONObject) ja.get(i);
String spcode = jo.containsKey(StringConstants.SPCODE) ? jo.get(StringConstants.SPCODE).toString() : "";
String scientific = jo.containsKey(StringConstants.SCIENTIFIC) ? jo.get(StringConstants.SCIENTIFIC).toString() : "";
String auth = jo.containsKey(StringConstants.AUTHORITY) ? jo.get(StringConstants.AUTHORITY).toString() : "";
String common = jo.containsKey(StringConstants.COMMON_NAM) ? jo.get(StringConstants.COMMON_NAM).toString() : "";
String family = jo.containsKey(StringConstants.FAMILY) ? jo.get(StringConstants.FAMILY).toString() : "";
String genus = jo.containsKey(StringConstants.GENUS) ? jo.get(StringConstants.GENUS).toString() : "";
String name = jo.containsKey(StringConstants.SPECIFIC_N) ? jo.get(StringConstants.SPECIFIC_N).toString() : "";
String min = jo.containsKey(StringConstants.MIN_DEPTH) ? jo.get(StringConstants.MIN_DEPTH).toString() : "";
String max = jo.containsKey(StringConstants.MAX_DEPTH) ? jo.get(StringConstants.MAX_DEPTH).toString() : "";
String md = jo.containsKey(StringConstants.METADATA_U) ? jo.get(StringConstants.METADATA_U).toString() : "";
String lsid = jo.containsKey(StringConstants.LSID) ? jo.get(StringConstants.LSID).toString() : "";
String areaName = jo.containsKey(StringConstants.AREA_NAME) ? jo.get(StringConstants.AREA_NAME).toString() : "";
String areaKm = jo.containsKey(StringConstants.AREA_KM) ? jo.get(StringConstants.AREA_KM).toString() : "";
String dataResourceUid = jo.containsKey(StringConstants.DATA_RESOURCE_UID) ? jo.get(StringConstants.DATA_RESOURCE_UID).toString() : "";
lines[i + 1] = spcode + "," + wrap(scientific) + "," + wrap(auth) + "," + wrap(common) + "," + wrap(family) + "," + wrap(genus) + "," + wrap(name) + "," + min + "," + max + "," + wrap(md) + "," + wrap(lsid) + "," + wrap(areaName) + "," + wrap(areaKm) + "," + wrap(dataResourceUid);
}
return lines;
}
}
} catch (Exception e) {
LOGGER.error("error building distribution or checklist csv", e);
}
return new String[0];
}
use of org.json.simple.JSONObject in project spatial-portal by AtlasOfLivingAustralia.
the class CommonData method dynamicSpeciesListColumns.
private static String dynamicSpeciesListColumns() {
StringBuilder sb = new StringBuilder();
try {
JSONParser jp = new JSONParser();
JSONObject threatened = (JSONObject) jp.parse(Util.readUrl(settings.getProperty("species_list_url", "") + "/ws/speciesList/?isThreatened=eq:true&isAuthoritative=eq:true"));
JSONObject invasive = (JSONObject) jp.parse(Util.readUrl(settings.getProperty("species_list_url", "") + "/ws/speciesList/?isInvasive=eq:true&isAuthoritative=eq:true"));
JSONObject[] lists = { threatened, invasive };
for (JSONObject o : lists) {
if (sb.length() == 0)
sb.append("Conservation");
else
sb.append("|Invasive");
JSONArray ja = (JSONArray) o.get("lists");
for (int i = 0; i < ja.size(); i++) {
sb.append(",").append(((JSONObject) ja.get(i)).get("dataResourceUid"));
}
}
} catch (Exception e) {
LOGGER.error("failed to get species lists for threatened or invasive species", e);
}
return sb.toString();
}
use of org.json.simple.JSONObject in project spatial-portal by AtlasOfLivingAustralia.
the class EnvLayersCombobox method refresh.
public void refresh(String val) {
//don't do autocomplete when < 1 characters
if (val.length() < 0) {
return;
}
String baseUrl = CommonData.getLayersServer() + "/fields/";
try {
Iterator it = getItems().iterator();
JSONArray results;
String lsurl = baseUrl;
if (val.length() == 0) {
results = CommonData.getLayerListJSONArray();
} else {
lsurl += "search/?q=" + URLEncoder.encode(val, StringConstants.UTF_8);
LOGGER.debug("nsurl: " + lsurl);
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(lsurl);
get.addRequestHeader(StringConstants.ACCEPT, StringConstants.JSON_JAVASCRIPT_ALL);
client.executeMethod(get);
String slist = get.getResponseBodyAsString();
JSONParser jp = new JSONParser();
results = (JSONArray) jp.parse(slist);
}
LOGGER.debug("got " + results.size() + " layers");
Sessions.getCurrent().setAttribute("layerlist", results);
if (!results.isEmpty()) {
for (int i = 0; i < results.size(); i++) {
JSONObject field = (JSONObject) results.get(i);
JSONObject layer = (JSONObject) field.get("layer");
if (!field.get(StringConstants.ENABLED).toString().equalsIgnoreCase("true") || !field.containsKey(StringConstants.NAME) || !layer.containsKey(StringConstants.TYPE) || !field.get(StringConstants.ADD_TO_MAP).toString().equalsIgnoreCase("true") || (!StringConstants.ENVIRONMENTAL.equalsIgnoreCase(layer.get(StringConstants.TYPE).toString()) && (includeLayers != null && !"AllLayers".equalsIgnoreCase(includeLayers) && !"MixLayers".equalsIgnoreCase(includeLayers)))) {
continue;
}
String displayName = field.get(StringConstants.NAME).toString();
String type = layer.get(StringConstants.TYPE).toString();
String name = field.get(StringConstants.ID).toString();
Comboitem myci;
if (it != null && it.hasNext()) {
myci = ((Comboitem) it.next());
myci.setLabel(displayName);
} else {
it = null;
myci = new Comboitem(displayName);
myci.setParent(this);
}
String c2 = "";
if (layer.containsKey(StringConstants.CLASSIFICATION2) && !StringConstants.NULL.equals(layer.get(StringConstants.CLASSIFICATION2))) {
c2 = layer.get(StringConstants.CLASSIFICATION2) + ": ";
}
String c1 = "";
if (layer.containsKey(StringConstants.CLASSIFICATION1) && !StringConstants.NULL.equals(layer.get(StringConstants.CLASSIFICATION1))) {
c1 = layer.get(StringConstants.CLASSIFICATION1) + ": ";
}
myci.setDescription(c1 + c2 + type);
myci.setValue(field);
}
}
if (includeAnalysisLayers) {
for (MapLayer ml : getMapComposer().getAnalysisLayers()) {
String displayName = ml.getDisplayName();
String type;
String name;
String classification1;
String classification2;
if (ml.getSubType() == LayerUtilitiesImpl.MAXENT) {
type = StringConstants.ENVIRONMENTAL;
classification1 = StringConstants.ANALYSIS;
classification2 = StringConstants.PREDICTION;
name = ml.getName();
} else if (ml.getSubType() == LayerUtilitiesImpl.GDM) {
type = StringConstants.ENVIRONMENTAL;
classification1 = StringConstants.ANALYSIS;
classification2 = StringConstants.GDM;
name = ml.getName();
} else if (ml.getSubType() == LayerUtilitiesImpl.ODENSITY) {
type = StringConstants.ENVIRONMENTAL;
classification1 = StringConstants.ANALYSIS;
classification2 = StringConstants.OCCURRENCE_DENSITY;
name = ml.getName();
} else if (ml.getSubType() == LayerUtilitiesImpl.SRICHNESS) {
type = StringConstants.ENVIRONMENTAL;
classification1 = StringConstants.ANALYSIS;
classification2 = StringConstants.SPECIES_RICHNESS;
name = ml.getName();
} else {
continue;
}
Comboitem myci;
if (it != null && it.hasNext()) {
myci = ((Comboitem) it.next());
myci.setLabel(displayName);
} else {
it = null;
myci = new Comboitem(displayName);
myci.setParent(this);
}
myci.setDescription(classification1 + ": " + classification2 + " " + type);
myci.setDisabled(false);
JSONObject jo = new JSONObject();
jo.put(StringConstants.NAME, name);
myci.setValue(jo);
}
}
while (it != null && it.hasNext()) {
it.next();
it.remove();
}
} catch (Exception e) {
LOGGER.error("Error searching for layers:", e);
}
}
use of org.json.simple.JSONObject in project spatial-portal by AtlasOfLivingAustralia.
the class EnvironmentalList method setupListEntries.
void setupListEntries() {
listEntries = new ArrayList<ListEntryDTO>();
JSONArray ja = CommonData.getLayerListJSONArray();
for (int i = 0; i < ja.size(); i++) {
JSONObject field = (JSONObject) ja.get(i);
JSONObject layer = (JSONObject) field.get("layer");
listEntries.add(new ListEntryDTO(field.get(StringConstants.ID).toString(), field.containsKey(StringConstants.NAME) ? field.get(StringConstants.NAME).toString() : field.get(StringConstants.ID).toString(), layer.containsKey(StringConstants.CLASSIFICATION1) ? layer.get(StringConstants.CLASSIFICATION1).toString() : "", layer.containsKey(StringConstants.CLASSIFICATION2) ? layer.get(StringConstants.CLASSIFICATION2).toString() : "", layer.containsKey(StringConstants.TYPE) ? layer.get(StringConstants.TYPE).toString() : "", layer.containsKey(StringConstants.DOMAIN) ? layer.get(StringConstants.DOMAIN).toString() : "", layer));
}
if (includeAnalysisLayers) {
for (MapLayer ml : mapComposer.getAnalysisLayers()) {
ListEntryDTO le = null;
if (ml.getSubType() == LayerUtilitiesImpl.ALOC) {
le = new ListEntryDTO(ml.getName(), ml.getDisplayName(), StringConstants.ANALYSIS, StringConstants.CLASSIFICATION, "Contextual", null, null);
} else if (ml.getSubType() == LayerUtilitiesImpl.MAXENT) {
le = new ListEntryDTO(ml.getName(), ml.getDisplayName(), StringConstants.ANALYSIS, StringConstants.PREDICTION, StringConstants.ENVIRONMENTAL, null, null);
} else if (ml.getSubType() == LayerUtilitiesImpl.GDM) {
le = new ListEntryDTO(ml.getName(), ml.getDisplayName(), StringConstants.ANALYSIS, StringConstants.GDM, StringConstants.ENVIRONMENTAL, null, null);
} else if (ml.getSubType() == LayerUtilitiesImpl.ODENSITY) {
le = new ListEntryDTO(ml.getName(), ml.getDisplayName(), StringConstants.ANALYSIS, StringConstants.OCCURRENCE_DENSITY, StringConstants.ENVIRONMENTAL, null, null);
} else if (ml.getSubType() == LayerUtilitiesImpl.SRICHNESS) {
le = new ListEntryDTO(ml.getName(), ml.getDisplayName(), StringConstants.ANALYSIS, StringConstants.SPECIES_RICHNESS, StringConstants.ENVIRONMENTAL, null, null);
}
if (le != null) {
listEntries.add(le);
}
}
}
java.util.Collections.sort(listEntries, new Comparator<ListEntryDTO>() {
@Override
public int compare(ListEntryDTO e1, ListEntryDTO e2) {
return (e1.getCatagory1() + " " + e1.getCatagory2() + " " + e1.getDisplayName()).compareTo(e2.getCatagory1() + " " + e2.getCatagory2() + " " + e2.getDisplayName());
}
});
}
use of org.json.simple.JSONObject in project spatial-portal by AtlasOfLivingAustralia.
the class AreaRegionSelection method onClick$btnOk.
public void onClick$btnOk(Event event) {
Comboitem ci = gazetteerAuto.getSelectedItem();
if (!validate()) {
return;
}
//exit if no match found
if (ci == null) {
return;
}
JSONObject jo = ci.getValue();
MapLayer ml = getMapComposer().addObjectByPid(jo.get(StringConstants.PID).toString(), ci.getLabel(), dRadius.getValue());
layerName = ml.getName();
ok = true;
this.detach();
}
Aggregations