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 makeHTML.
private void makeHTML() {
//make report
fileNumber = 1;
try {
//read data
JSONParser jp = new JSONParser();
JSONObject tabulations = (JSONObject) jp.parse(FileUtils.readFileToString(new File(filePath + "/tabulations.json"), "UTF-8"));
JSONObject csvs = (JSONObject) jp.parse(FileUtils.readFileToString(new File(filePath + "/csvs.json")));
JSONObject counts = (JSONObject) jp.parse(FileUtils.readFileToString(new File(filePath + "/counts.json"), "UTF-8"));
//header
String filename = filePath + "/report.html";
FileWriter fw = startHtmlOut(fileNumber, filename);
//box summary
fw.write("<img id='imgHeader' src='" + CommonData.getWebportalServer() + "/area-report/header.jpg' width='100%' />");
//fw.write("<div>AREA REPORT</div>");
fw.write("<table id='dashboard' >");
fw.write("<tr>");
fw.write("<td>");
fw.write("Area: " + String.format("%s", (counts.get("Area (sq km)"))) + " sq km");
fw.write("</td>");
fw.write("<td>");
fw.write("Species: " + String.format("%s", (counts.get("Species"))));
fw.write("</td>");
fw.write("<td>");
fw.write("Occurrences: " + String.format("%s", counts.get("Occurrences")));
fw.write("</td>");
fw.write("</tr>");
fw.write("<tr>");
fw.write("<td>");
fw.write("Endemic species: " + String.format("%s", counts.get("Endemic Species")));
fw.write("</td>");
fw.write("<td>");
fw.write("All threatened species: " + counts.get("Threatened_Species"));
fw.write("</td>");
fw.write("<td>");
fw.write("Migratory species: " + counts.get("Migratory_Species"));
fw.write("</td>");
fw.write("</tr>");
fw.write("<tr>");
fw.write("<td>");
fw.write("All invasive species: " + counts.get("Invasive_Species"));
fw.write("</td>");
fw.write("<td>");
fw.write("Iconic species: " + counts.get("Iconic_Species"));
fw.write("</td>");
fw.write("<td>");
fw.write("JournalMap Articles: " + counts.get("Journalmap"));
fw.write("</td>");
fw.write("</tr>");
fw.write("<tr>");
fw.write("<td>");
fw.write("Animals: " + String.format("%s", counts.get("Animals")));
fw.write("</td>");
fw.write("<td>");
fw.write("Plants: " + String.format("%s", counts.get("Plants")));
fw.write("</td>");
fw.write("<td>");
fw.write("Birds: " + String.format("%s", counts.get("Birds")));
fw.write("</td>");
fw.write("</tr>");
fw.write("</table>");
fw.write("</body></html>");
fw.close();
fileNumber++;
fw = startHtmlOut(fileNumber, filename);
//index page
//map pages
int figureNumber = 1;
int tableNumber = 1;
mapPage(fw, areaName, figureNumber, tableNumber, "base_area.png", "Area: <b>" + String.format("%s", counts.get("Area (sq km)")) + " sq km</b>", null, null);
fw.write("</body></html>");
fw.close();
String[] layers = CommonData.getSettings().getProperty("detailed_area_report_layers").split("\n");
for (String layer : layers) {
if (!layer.isEmpty()) {
String[] split = layer.trim().split("\\|");
String shortname = split[0];
String displayname = split[1];
String geoserver_url = split[2];
String canSetColourMode = split[3];
String description = split[4];
fileNumber++;
fw = startHtmlOut(fileNumber, filename);
figureNumber++;
mapPage(fw, displayname, figureNumber, tableNumber, shortname + ".png", description, (JSONObject) tabulations.get(CommonData.getLayerFacetName(shortname)), geoserver_url.isEmpty() ? null : geoserver_url);
fw.write("</body></html>");
fw.close();
}
}
// fw = startHtmlOut(fileNumber, filename);
// figureNumber++;
// mapPage(fw, "Integrated Marine and Coastal Regionalisation of Australia (IMCRA)", figureNumber, "imcra4_pb.png",
// "<br /><br />The Integrated Marine and Coastal Regionalisation of Australia (IMCRA v4.0) is a spatial framework for classifying Australia's marine environment into bioregions that make sense ecologically and are at a scale useful for regional planning. These bioregions are the basis for the development of a National Representative System of Marine Protected Areas (NRSMPA). [Ref3]\n" +
// "<br /><br />IMCRA: <a href='http://www.environment.gov.au/node/18075'>http://www.environment.gov.au/node/18075</a>" +
// "<br /><br />IMCRA Regions layer: Classification: Biodiversity - Region; Type: Contextual (polygonal); Metadata contact organisation: Environmental Resources Information Network (ERIN). <a href='http://spatial.ala.org.au/ws/layers/view/more/imcra4_pb'>http://spatial.ala.org.au/ws/layers/view/more/imcra4_pb</a>" +
// "<br /><br />Goals and Principles for the Establishment of the NRSMPA: <a href='http://www.environment.gov.au/resource/goals-and-principles-establishment-national-representative-system-marine-protected-areas'>http://www.environment.gov.au/resource/goals-and-principles-establishment-national-representative-system-marine-protected-areas</a>",
// tabulations.getJSONObject(CommonData.getLayerFacetName("imcra4_pb")));
// fw.write("</body></html>");fw.close();
// fileNumber++;
fileNumber++;
fw = startHtmlOut(fileNumber, filename);
figureNumber++;
tableNumber++;
//occurrences page
int count = Integer.parseInt(counts.get("Occurrences").toString());
int countKosher = Integer.parseInt(counts.get("Occurrences (spatially valid only)").toString());
String imageUrl = StringConstants.OCCURRENCES + ".png";
String notes = "Spatially valid records are considered those that do not have any type of flag questioning their location, for example a terrestrial species being recorded in the ocean. [Ref6]";
speciesPage(true, fw, "My Area", "Occurrences", notes, tableNumber, count, countKosher, figureNumber, imageUrl, null);
figureNumber++;
fw.write("</body></html>");
fw.close();
fileNumber++;
fw = startHtmlOut(fileNumber, filename);
//species pages
count = Integer.parseInt(counts.get("Species").toString());
countKosher = Integer.parseInt(counts.get("Species (spatially valid only)").toString());
imageUrl = null;
notes = "Spatially valid records are considered those that do not have any type of flag questioning their location, for example a terrestrial species being recorded in the ocean. [Ref6]";
speciesPage(true, fw, "My Area", "Species", notes, tableNumber, count, countKosher, figureNumber, imageUrl, csvs.get("Species").toString());
tableNumber++;
fw.write("</body></html>");
fw.close();
fileNumber++;
fw = startHtmlOut(fileNumber, filename);
//threatened species page
count = Integer.parseInt(counts.get("Threatened_Species").toString());
imageUrl = "Threatened_Species" + ".png";
notes = "";
speciesPage(true, fw, "My Area", "All threatened species", notes, tableNumber, count, -1, figureNumber, imageUrl, csvs.get("Threatened_Species").toString());
figureNumber++;
fw.write("</body></html>");
fw.close();
fileNumber++;
fw = startHtmlOut(fileNumber, filename);
//invasive species page
count = Integer.parseInt(counts.get("Invasive_Species").toString());
imageUrl = "Invasive_Species" + ".png";
notes = "";
speciesPage(true, fw, "My Area", "All invasive species", notes, tableNumber, count, -1, figureNumber, imageUrl, csvs.get("Invasive_Species").toString());
figureNumber++;
fw.write("</body></html>");
fw.close();
fileNumber++;
fw = startHtmlOut(fileNumber, filename);
//iconic species page
count = Integer.parseInt(counts.get("Iconic_Species").toString());
imageUrl = "Iconic_Species" + ".png";
notes = "";
speciesPage(true, fw, "My Area", "Iconic species", notes, tableNumber, count, -1, figureNumber, imageUrl, csvs.get("Iconic_Species").toString());
figureNumber++;
fw.write("</body></html>");
fw.close();
fileNumber++;
fw = startHtmlOut(fileNumber, filename);
//migratory species page
count = Integer.parseInt(counts.get("Migratory_Species").toString());
imageUrl = "Migratory_Species" + ".png";
notes = "";
speciesPage(true, fw, "My Area", "Migratory species", notes, tableNumber, count, -1, figureNumber, imageUrl, csvs.get("Migratory_Species").toString());
figureNumber++;
fw.write("</body></html>");
fw.close();
fileNumber++;
fw = startHtmlOut(fileNumber, filename);
for (int i = 0; i < StringConstants.SPECIES_GROUPS.length; i++) {
String s = StringConstants.SPECIES_GROUPS[i];
count = Integer.parseInt(counts.get(s).toString());
countKosher = Integer.parseInt(counts.get(s + " (spatially valid only)").toString());
speciesPage(true, fw, "My Area", "lifeform - " + s, notes, tableNumber, count, countKosher, figureNumber, "lifeform - " + s + ".png", csvs.get(s).toString());
tableNumber++;
figureNumber++;
fw.write("</body></html>");
fw.close();
fileNumber++;
fw = startHtmlOut(fileNumber, filename);
}
//expert distributions
count = Integer.parseInt(counts.get("Distribution Areas").toString());
speciesPage(false, fw, "My Area", "Expert Distributions", notes, tableNumber, count, -1, figureNumber, null, csvs.get(StringConstants.DISTRIBUTIONS).toString());
fw.write("</body></html>");
fw.close();
fileNumber++;
fw = startHtmlOut(fileNumber, filename);
count = Integer.parseInt(counts.get("Checklist Areas").toString());
speciesPage(false, fw, "My Area", "Checklist Areas", notes, tableNumber, count, -1, figureNumber, null, csvs.get(StringConstants.CHECKLISTS).toString());
fw.write("</body></html>");
fw.close();
fileNumber++;
fw = startHtmlOut(fileNumber, filename);
//Journalmap page
count = Integer.parseInt(counts.get("Journalmap").toString());
notes = "<a href='http://journalmap.org'>JournalMap</a>";
speciesPage(false, fw, "My Area", "JournalMap Articles", notes, tableNumber, count, -1, figureNumber, null, csvs.get("Journalmap").toString());
tableNumber++;
fw.write("</body></html>");
fw.close();
fileNumber++;
} catch (Exception e) {
LOGGER.error("failed to produce report pdf", e);
}
}
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