Search in sources :

Example 36 with JsonObject

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;
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) JSONObject(org.json.simple.JSONObject) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) JSONParser(org.json.simple.parser.JSONParser) IOException(java.io.IOException)

Example 37 with JsonObject

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);
    }
}
Also used : JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Event(org.zkoss.zk.ui.event.Event) JSONParser(org.json.simple.parser.JSONParser) Comboitem(org.zkoss.zul.Comboitem) EventListener(org.zkoss.zk.ui.event.EventListener) FieldDTO(au.org.ala.spatial.dto.FieldDTO)

Example 38 with JsonObject

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);
}
Also used : JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) EventListener(org.zkoss.zk.ui.event.EventListener) IOException(java.io.IOException)

Example 39 with JsonObject

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);
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray)

Example 40 with JsonObject

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) {
    }
}
Also used : JSONObject(org.json.simple.JSONObject) SQLException(java.sql.SQLException) Voo(br.senac.tads3.pi03b.gruposete.models.Voo) JSONArray(org.json.simple.JSONArray) VendaDAO(br.senac.tads3.pi03b.gruposete.dao.VendaDAO) PrintWriter(java.io.PrintWriter)

Aggregations

JSONObject (org.json.simple.JSONObject)2110 JSONArray (org.json.simple.JSONArray)601 JSONParser (org.json.simple.parser.JSONParser)389 Test (org.junit.Test)341 Test (org.junit.jupiter.api.Test)247 HashMap (java.util.HashMap)214 IOException (java.io.IOException)199 ArrayList (java.util.ArrayList)190 ParseException (org.json.simple.parser.ParseException)171 Map (java.util.Map)140 Date (java.util.Date)74 InputStreamReader (java.io.InputStreamReader)62 List (java.util.List)61 File (java.io.File)60 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)60 URL (java.net.URL)45 HashSet (java.util.HashSet)42 HttpURLConnection (java.net.HttpURLConnection)41 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)41 HttpClient (org.apache.commons.httpclient.HttpClient)41