Search in sources :

Example 41 with JsonObject

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

the class InOutComposer method onChange$autoCompleteLayers.

public void onChange$autoCompleteLayers(Event event) {
    autoCompleteLayerSelection = null;
    autoCompleteLayerAreas = null;
    if (autoCompleteLayers.getItemCount() > 0 && autoCompleteLayers.getSelectedItem() != null) {
        JSONObject jo = autoCompleteLayers.getSelectedItem().getValue();
        autoCompleteLayerSelection = (String) jo.get(StringConstants.ID);
    }
}
Also used : JSONObject(org.json.simple.JSONObject)

Example 42 with JsonObject

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

the class AddLayerController method loadMap.

public void loadMap(Event event) {
    if (lbListLayers.getSelectedLayers().length > 0) {
        String[] sellayers = lbListLayers.getSelectedLayers();
        for (String s : sellayers) {
            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(s)) {
                    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=" + layer.get(StringConstants.NAME).toString() + "&styles=" + name + "_style";
                    metadata = CommonData.getLayersServer() + "/layers/view/more/" + uid;
                    break;
                }
            }
            getMapComposer().addWMSLayer(s, treeName, treePath, (float) 0.75, metadata, legendurl, StringConstants.ENVIRONMENTAL.equalsIgnoreCase(type) ? LayerUtilitiesImpl.GRID : LayerUtilitiesImpl.CONTEXTUAL, null, null, null);
            remoteLogger.logMapArea(treeName, "Layer - " + type, treePath, s, metadata);
        }
    }
    this.detach();
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray)

Example 43 with JsonObject

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

the class ContextualLayerListComposer method addToMap.

private void addToMap(Map htCat1, Map htCat2, String cat1, String cat2, DefaultTreeNode treeNode) {
    String nCat1 = cat1;
    if (cat1.trim().isEmpty() || "?".equals(cat1.trim()) || StringConstants.NULL.equals(cat1.trim())) {
        nCat1 = "Other";
    }
    if (cat2.trim().isEmpty() || "?".equals(cat2.trim()) || StringConstants.NULL.equals(cat2.trim())) {
        List alCat1 = (List) htCat1.get(cat1);
        if (alCat1 == null) {
            alCat1 = new ArrayList();
        }
        alCat1.add(treeNode);
        htCat1.put(nCat1, alCat1);
    } else {
        // first check if cat1 already exists
        // if yes, grab the cat2 list and add add to its AL
        // else, create a new one and add it to cat1.list
        String cat2Full = nCat1 + ">" + cat2;
        List alCat2 = (List) htCat2.get(cat2Full);
        if (alCat2 == null) {
            alCat2 = new ArrayList();
        }
        alCat2.add(treeNode);
        if (!htCat2.containsKey(cat2Full)) {
            htCat2.put(cat2Full, alCat2);
        }
        List alCat1 = (List) htCat1.get(cat1);
        if (alCat1 == null) {
            alCat1 = new ArrayList();
        }
        String subtype = ((JSONObject) ((JSONObject) treeNode.getData()).get("layer")).get(StringConstants.TYPE).toString();
        JSONParser jp = new JSONParser();
        JSONObject joCat2 = null;
        try {
            joCat2 = (JSONObject) jp.parse("{\"name\":\"" + cat2Full + "\",\"layer\":{\"type\":\"node\"},\"subtype\":" + ((StringConstants.ENVIRONMENTAL.equalsIgnoreCase(subtype)) ? LayerUtilitiesImpl.GRID : LayerUtilitiesImpl.CONTEXTUAL) + "}");
        } catch (ParseException e) {
            LOGGER.error("parse error");
        }
        DefaultTreeNode stnCat2 = new DefaultTreeNode(joCat2, alCat2);
        boolean found = false;
        for (int i = 0; i < alCat1.size(); i++) {
            if (stnCat2.toString().equals(alCat1.get(i).toString())) {
                found = true;
                ((DefaultTreeNode) alCat1.get(i)).add(treeNode);
                break;
            }
        }
        if (!found) {
            alCat1.add(stnCat2);
        }
        if (!htCat1.containsKey(nCat1)) {
            htCat1.put(nCat1, alCat1);
        }
    }
}
Also used : JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException)

Example 44 with JsonObject

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

the class BiocacheQuery method getQidDetails.

private JSONObject getQidDetails(String qidTerm) {
    HttpClient client = new HttpClient();
    String url = biocacheServer + QID_DETAILS + qidTerm.replace("qid:", "");
    GetMethod get = new GetMethod(url);
    try {
        int result = client.executeMethod(get);
        String response = get.getResponseBodyAsString();
        if (result == 200) {
            JSONParser jp = new JSONParser();
            JSONObject jo = (JSONObject) jp.parse(response);
            return jo;
        } else {
            LOGGER.debug("error with url:" + url + " getting qid details for " + qidTerm + " > response_code:" + result + " response:" + response);
        }
    } catch (Exception e) {
        LOGGER.error("error getting biocache param details from " + url, e);
    }
    return null;
}
Also used : JSONObject(org.json.simple.JSONObject) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JSONParser(org.json.simple.parser.JSONParser)

Example 45 with JsonObject

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

the class CommonData method getLayerFacetNameDefault.

public static String getLayerFacetNameDefault(String layer) {
    String facetName = layer;
    JSONObject f = getLayer(layer);
    if (f != null) {
        facetName = f.get(StringConstants.ID).toString();
    }
    return facetName;
}
Also used : JSONObject(org.json.simple.JSONObject)

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