Search in sources :

Example 71 with JSONObject

use of org.json.simple.JSONObject in project spatial-portal by AtlasOfLivingAustralia.

the class AreaReportController method onMapPointsOfInterest.

public void onMapPointsOfInterest(Event event) {
    try {
        String activeAreaLayerName = "Points of interest in " + areaDisplayName;
        StringBuilder sb = new StringBuilder();
        sb.append("MULTIPOINT(");
        if (pointsOfInterest == null) {
            String wkt = selectedArea.getWkt();
            if (wkt.contains(StringConstants.ENVELOPE) && selectedArea.getMapLayer() != null) {
                // use boundingbox
                List<Double> bbox = selectedArea.getMapLayer().getMapLayerMetadata().getBbox();
                double long1 = bbox.get(0);
                double lat1 = bbox.get(1);
                double long2 = bbox.get(2);
                double lat2 = bbox.get(3);
                wkt = StringConstants.POLYGON + "((" + long1 + " " + lat1 + "," + long1 + " " + lat2 + "," + long2 + " " + lat2 + "," + long2 + " " + lat1 + "," + long1 + " " + lat1 + "))";
            } else {
            //wkt = selectedArea.getReducedWkt();
            }
            pointsOfInterest = getPointsOfInterest(wkt);
        }
        for (int i = 0; i < pointsOfInterest.size(); i++) {
            JSONObject jsonObjPoi = (JSONObject) pointsOfInterest.get(i);
            double latitude = Double.parseDouble(jsonObjPoi.get(StringConstants.LATITUDE).toString());
            double longitude = Double.parseDouble(jsonObjPoi.get(StringConstants.LONGITUDE).toString());
            sb.append(longitude);
            sb.append(" ");
            sb.append(latitude);
            if (i < pointsOfInterest.size() - 1) {
                sb.append(",");
            }
        }
        sb.append(")");
        getMapComposer().mapPointsOfInterest(sb.toString(), activeAreaLayerName, activeAreaLayerName);
    } catch (Exception e) {
        LOGGER.error("error mapping points of interest", e);
    }
}
Also used : JSONObject(org.json.simple.JSONObject)

Example 72 with JSONObject

use of org.json.simple.JSONObject 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");
    }
}
Also used : JSONObject(org.json.simple.JSONObject) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser)

Example 73 with JSONObject

use of org.json.simple.JSONObject in project spatial-portal by AtlasOfLivingAustralia.

the class ProgressController method get.

JSONObject get() {
    try {
        StringBuilder sbProcessUrl = new StringBuilder();
        sbProcessUrl.append(CommonData.getSatServer()).append("/ws/job?pid=").append(pid);
        LOGGER.debug("checking status every '" + timer.getDelay() + "' sec: " + sbProcessUrl.toString());
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(sbProcessUrl.toString());
        get.addRequestHeader(StringConstants.ACCEPT, StringConstants.APPLICATION_JSON);
        client.getHttpConnectionManager().getParams().setSoTimeout(timer.getDelay());
        int result = client.executeMethod(get);
        if (result == 200) {
            JSONParser jp = new JSONParser();
            return (JSONObject) jp.parse(get.getResponseBodyAsString());
        }
    } catch (SocketTimeoutException e) {
        LOGGER.debug("progress timeout exception, will be trying again.");
    } catch (Exception e) {
        LOGGER.error("error getting updated job info pid=" + pid, e);
    }
    return null;
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) JSONObject(org.json.simple.JSONObject) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JSONParser(org.json.simple.parser.JSONParser) SocketTimeoutException(java.net.SocketTimeoutException)

Example 74 with JSONObject

use of org.json.simple.JSONObject in project spatial-portal by AtlasOfLivingAustralia.

the class AreaReportController method journalmap.

Map<String, String> journalmap(AreaReportItemDTO model) {
    Map<String, String> countData = new HashMap<String, String>();
    try {
        String area = selectedArea.getWkt();
        double lat1 = 0;
        double lat2 = 0;
        double long1 = 0;
        double long2 = 0;
        if (area.contains(StringConstants.ENVELOPE) && selectedArea.getMapLayer() != null) {
            // use boundingbox
            List<Double> bbox = selectedArea.getMapLayer().getMapLayerMetadata().getBbox();
            long1 = bbox.get(0);
            lat1 = bbox.get(1);
            long2 = bbox.get(2);
            lat2 = bbox.get(3);
            area = "POLYGON((" + long1 + " " + lat1 + "," + long1 + " " + lat2 + "," + long2 + " " + lat2 + "," + long2 + " " + lat1 + "," + long1 + " " + lat1 + "))";
        }
        List<JSONObject> list = CommonData.filterJournalMapArticles(area);
        String journalmapUrl = CommonData.getSettings().getProperty("journalmap.url", null);
        StringBuilder sb = new StringBuilder();
        sb.append("<ol>");
        for (int i = 0; i < list.size(); i++) {
            JSONObject o = list.get(i);
            sb.append("<li>");
            sb.append("<a href=\"").append(journalmapUrl + "articles/" + o.get("id").toString()).append("\" ");
            sb.append("target=\"_blank\">");
            sb.append(o.get("title"));
            sb.append("</li>");
        }
        sb.append("</ol>");
        if (!list.isEmpty()) {
            journalmapHtml = sb.toString();
        }
        countData.put(StringConstants.JOURNAL_MAP, String.valueOf(list.size()));
        model.setCount(Integer.toString(list.size()));
        if (!list.isEmpty()) {
            model.setExtraInfo(new ExtraInfoEnum[] { ExtraInfoEnum.LIST });
            model.setListType(ListType.JOURNAL_MAP);
            model.addUrlDetails("JournalMap", "https://www.journalmap.org/");
        }
    } catch (Exception e) {
        LOGGER.error("unable to get area info from journalmap", e);
        countData.put(StringConstants.JOURNAL_MAP, "unavailable");
        model.setCount("Unavailable");
    }
    return countData;
}
Also used : JSONObject(org.json.simple.JSONObject)

Example 75 with JSONObject

use of org.json.simple.JSONObject in project spatial-portal by AtlasOfLivingAustralia.

the class MapComposer method mapLayerFromParams.

/**
     * Maps environmental and contextual layers from a "&layers" param. Uses the
     * short name of the layer. e.g. "aspect" or ""
     */
public void mapLayerFromParams() {
    Map<String, String> userParams = getQueryParameterMap(Executions.getCurrent().getDesktop().getQueryString());
    if (userParams != null) {
        String layersCSV = userParams.get("layers");
        if (StringUtils.trimToNull(layersCSV) == null) {
            return;
        }
        String[] layers = layersCSV.split(",");
        for (String s : layers) {
            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.equalsIgnoreCase(s) || s.equalsIgnoreCase(layer.get("name").toString())) {
                    String fieldId = field.get(StringConstants.ID).toString();
                    String uid = layer.get(StringConstants.ID).toString();
                    String type = layer.get(StringConstants.TYPE).toString();
                    String treeName = StringUtils.capitalize(field.get(StringConstants.NAME).toString());
                    String treePath = layer.get("displaypath").toString();
                    String legendurl = CommonData.getGeoServer() + "/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=9&LAYER=" + s + (fieldId.length() < 10 ? "&styles=" + fieldId + "_style" : "");
                    String metadata = CommonData.getLayersServer() + "/layers/view/more/" + uid;
                    getMapComposer().addWMSLayer(s, treeName, treePath, (float) 0.75, 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)

Aggregations

JSONObject (org.json.simple.JSONObject)961 Test (org.junit.Test)312 JSONArray (org.json.simple.JSONArray)232 JSONParser (org.json.simple.parser.JSONParser)164 Map (java.util.Map)97 HashMap (java.util.HashMap)91 IOException (java.io.IOException)84 ArrayList (java.util.ArrayList)75 ParseException (org.json.simple.parser.ParseException)60 HttpClient (org.apache.commons.httpclient.HttpClient)39 File (java.io.File)38 List (java.util.List)38 BlockchainTest (org.xel.BlockchainTest)34 GetMethod (org.apache.commons.httpclient.methods.GetMethod)30 HttpURLConnection (java.net.HttpURLConnection)27 Tuple (org.apache.storm.tuple.Tuple)23 Transaction (org.xel.Transaction)23 APICall (org.xel.http.APICall)23 InputStreamReader (java.io.InputStreamReader)22 WriterConfiguration (org.apache.metron.common.configuration.writer.WriterConfiguration)22