AnalysisParser { protected static String getGeoJSONInput(JSONObject json, String id) { if (json == null || !json.has(JSON_KEY_FEATURES)) { return null; } JSONArray geofeas = json.optJSONArray(JSON_KEY_FEATURES); if (geofeas == null) { return null; } JSONArray response = new JSONArray(); for (int i = 0; i < geofeas.length(); i++) { JSONObject feature = geofeas.optJSONObject(i); if (feature == null) { continue; } JSONHelper.putValue(feature, "id", id + "." + i); feature.remove("crs"); response.put(feature); } JSONObject collection = new JSONObject(); JSONHelper.putValue(collection, "type", "FeatureCollection"); JSONHelper.putValue(collection, JSON_KEY_FEATURES, response); return JSONHelper.getStringFromJSON(collection, null); }  AnalysisLayer parseAnalysisLayer(JSONObject json, String filter1, String filter2, String baseUrl, User user); String getSourceLayerId(JSONObject json); String getNamespacePrefix(OskariLayer layer); String parseAggregateResults(String response,
                                        AnalysisLayer analysisLayer); String harmonizeElementNames(String featureSet, final AnalysisLayer analysisLayer); AnalysisLayer parseSwitch2UnionLayer(AnalysisLayer analysisLayer, String analyse, String filter1,
                                               String filter2, String baseUrl, String outputFormat); String mergeAggregateResults2FeatureSet(String featureSet, AnalysisLayer analysisLayer, List<String> rowOrder, List<String> colOrder); JSONArray reorderAggregateResult(JSONObject jsaggregate, List<String> rowOrder, List<String> colOrder); void fixTypeNames(AnalysisLayer analysisLayer, JSONObject analysejs); void removeTextTypeFields(AnalysisLayer analysisLayer); static final String ANALYSIS_LAYER_PREFIX; static final String MYPLACES_LAYER_PREFIX; static final String USERLAYER_PREFIX; static final String BUFFER; static final String INTERSECT; static final String SPATIAL_JOIN; static final String SPATIAL_JOIN_STATISTICS; static final String DIFFERENCE; static final String AGGREGATE; static final String UNION; static final String LAYER_UNION; static final String ZONESECTOR; }
@Test public void testGetGeoJSONInput() throws Exception { String ID_PREFIX = "testing"; assertNull("Null input should produce null as GeoJSON", AnalysisParser.getGeoJSONInput(null, ID_PREFIX)); JSONObject input = new JSONObject(); JSONArray features = new JSONArray(); input.putOpt("features", features); assertTrue("Empty features array in input should produce empty feature collection", JSONHelper.isEqual(getFeatureCollection(), new JSONObject(AnalysisParser.getGeoJSONInput(input, "testing")))); JSONObject firstFeature = generateFeature(false); features.put(firstFeature); JSONObject testFeature1 = copyFeature(firstFeature, ID_PREFIX + ".0"); assertTrue("Feature in input should produce feature collection with overridden id", JSONHelper.isEqual(getFeatureCollection(testFeature1), new JSONObject(AnalysisParser.getGeoJSONInput(input, ID_PREFIX)))); JSONObject secondFeature = generateFeature(true); JSONObject testFeature2 = copyFeature(secondFeature, ID_PREFIX + ".1"); testFeature2.remove("crs"); features.put(secondFeature); assertTrue("Feature with CRS in input should produce feature collection with overridden ids and cleaned up features", JSONHelper.isEqual(getFeatureCollection(testFeature1, testFeature2), new JSONObject(AnalysisParser.getGeoJSONInput(input, ID_PREFIX)))); }