use of org.json.simple.JSONObject in project spatial-portal by AtlasOfLivingAustralia.
the class ToolComposer method processAdhoc.
JSONObject processAdhoc(String scientificName) {
String url = CommonData.getBiocacheServer() + "/process/adhoc";
try {
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(url);
StringRequestEntity sre = new StringRequestEntity("{ \"scientificName\": \"" + scientificName.replace("\"", "'") + "\" } ", StringConstants.APPLICATION_JSON, StringConstants.UTF_8);
post.setRequestEntity(sre);
int result = client.executeMethod(post);
if (result == 200) {
JSONParser jp = new JSONParser();
return (JSONObject) jp.parse(post.getResponseBodyAsString());
}
} catch (Exception e) {
LOGGER.error("error processing species request: " + url + ", scientificName=" + scientificName, e);
}
return null;
}
use of org.json.simple.JSONObject in project spatial-portal by AtlasOfLivingAustralia.
the class TabulationComposer method afterCompose.
@Override
public void afterCompose() {
super.afterCompose();
this.selectedMethod = StringConstants.TABULATION;
this.totalSteps = 1;
this.updateWindowTitle();
cbTabLayers1.setFocus(true);
tabLayers = new HashMap<FieldDTO, List<FieldDTO>>();
tabLayerDisplayNames = new HashMap<String, List<String>>();
try {
int i;
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(CommonData.getLayersServer() + "/tabulations.json");
get.addRequestHeader(StringConstants.ACCEPT, StringConstants.APPLICATION_JSON);
client.executeMethod(get);
String tlayers = get.getResponseBodyAsString();
JSONParser jp = new JSONParser();
JSONObject joTop = (JSONObject) jp.parse(tlayers);
JSONArray joarr = (JSONArray) joTop.get("tabulations");
for (i = 0; i < joarr.size(); i++) {
JSONObject jo = (JSONObject) joarr.get(i);
FieldDTO f1 = new FieldDTO(jo.get("fid1").toString(), jo.get("name1").toString(), "");
FieldDTO f2 = new FieldDTO(jo.get("fid2").toString(), jo.get("name2").toString(), "");
load(f1, f2);
load(f2, f1);
}
Set keySet = (Set) tabLayerDisplayNames.keySet();
List keyList = new ArrayList(keySet);
Collections.sort(keyList);
LOGGER.debug("keyList1=" + keyList);
for (int j = 0; j < keyList.size(); j++) {
String temp = (String) keyList.get(j);
LOGGER.debug("temp=" + temp);
Comboitem ci = new Comboitem(temp);
ci.setValue(temp);
ci.setParent(cbTabLayers1);
}
cbTabLayers1.addEventListener("onChange", new EventListener() {
public void onEvent(Event event) throws Exception {
onChange$cbTabLayer1(event);
}
});
cbTabLayers1.setSelectedIndex(0);
onChange$cbTabLayer1(null);
cbTabLayers2.setSelectedIndex(0);
cbTabType.setSelectedIndex(0);
} catch (Exception e) {
LOGGER.debug("Unable to call tabulation service for a list of layers", e);
}
}
use of org.json.simple.JSONObject in project spatial-portal by AtlasOfLivingAustralia.
the class ToolComposer method addToMpLayers.
void addToMpLayers(MapLayer ml, boolean analysis) {
// get layer name
String name = null;
String url = ml.getUri();
if (analysis) {
name = ml.getName();
} else {
int p1 = url.indexOf("&style=") + 7;
int p2 = url.indexOf("_style", p1);
if (p1 > 4) {
if (p2 < 0) {
p2 = url.length();
}
name = url.substring(p1, p2);
}
}
// cbLayer1
Menuitem mi = new Menuitem(ml.getDisplayName());
mi.setValue(name);
mi.addEventListener(StringConstants.ONCLICK, new EventListener() {
public void onEvent(Event event) {
Menuitem mi = (Menuitem) event.getTarget();
String displayname = ((JSONObject) CommonData.getLayer(mi.getValue()).get("layer")).get("displayname").toString();
cbLayer1.setValue(displayname + " ");
cbLayer1.refresh(displayname);
for (Object o : cbLayer1.getItems()) {
Comboitem ci = (Comboitem) o;
JSONObject jo = ci.getValue();
if (jo.get(StringConstants.NAME).toString().equals(displayname)) {
cbLayer1.setSelectedItem(ci);
cbLayer1.setText(ci.getLabel());
toggles();
return;
}
}
}
});
mi.setParent(mpLayer1);
// cbLayer2
mi = new Menuitem(ml.getDisplayName());
mi.setValue(name);
mi.addEventListener(StringConstants.ONCLICK, new EventListener() {
public void onEvent(Event event) throws Exception {
Menuitem mi = (Menuitem) event.getTarget();
String displayname = ((JSONObject) CommonData.getLayer(mi.getValue()).get("layer")).get("displayname").toString();
cbLayer2.setValue(displayname + " ");
cbLayer2.refresh(displayname);
for (Object o : cbLayer2.getItems()) {
Comboitem ci = (Comboitem) o;
JSONObject jo = ci.getValue();
if (jo.get(StringConstants.NAME).equals(displayname)) {
cbLayer2.setSelectedItem(ci);
cbLayer2.setText(ci.getLabel());
toggles();
return;
}
}
}
});
mi.setParent(mpLayer2);
}
use of org.json.simple.JSONObject in project spatial-portal by AtlasOfLivingAustralia.
the class AreaReportPDF method createLayer.
MapLayer createLayer(String layerName, float opacity) {
String uid;
String type = "";
String treeName = "";
String treePath = "";
String legendurl = "";
String metadata = "";
JSONArray layerlist = CommonData.getLayerListJSONArray();
for (int j = 0; j < layerlist.size(); j++) {
JSONObject field = (JSONObject) layerlist.get(j);
JSONObject layer = (JSONObject) field.get("layer");
String name = field.get(StringConstants.ID).toString();
if (name.equals(layerName)) {
String fieldId = field.get(StringConstants.ID).toString();
uid = layer.get(StringConstants.ID).toString();
type = layer.get(StringConstants.TYPE).toString();
treeName = StringUtils.capitalize(field.get(StringConstants.NAME).toString());
treePath = layer.get("displaypath").toString();
legendurl = CommonData.getGeoServer() + "/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=9&LAYER=" + layerName + (fieldId.length() < 10 ? "&styles=" + fieldId + "_style" : "");
metadata = CommonData.getLayersServer() + "/layers/view/more/" + uid;
break;
}
}
return addWMSLayer(layerName, treeName, treePath, opacity, metadata, legendurl, StringConstants.ENVIRONMENTAL.equalsIgnoreCase(type) ? LayerUtilitiesImpl.GRID : LayerUtilitiesImpl.CONTEXTUAL, null, null, null);
}
use of org.json.simple.JSONObject in project Loja_Agencia_De_Viagens by ArtCouSan.
the class BuscaVooVendaServlet method doPost.
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
String busca = request.getParameter("busca");
VendaDAO dao = new VendaDAO();
ArrayList<Voo> voo = dao.procurarVoo(busca);
JSONArray jsonArray = new JSONArray();
for (Voo voos : voo) {
JSONObject json = new JSONObject();
json.put("id_voo", voos.getId_voo());
json.put("data_volta", voos.getData_volta());
json.put("data_ida", voos.getData_ida());
json.put("origem", voos.getOrigem());
json.put("preco", voos.getPreco());
json.put("quantidade_passagens", voos.getQuantidade_passagens());
json.put("destino", voos.getDestino());
jsonArray.add(json);
}
try (PrintWriter out = response.getWriter()) {
out.println(jsonArray.toJSONString());
}
} catch (ClassNotFoundException | SQLException e) {
}
}
Aggregations