public ImportTask task() throws IOException { if (json.has("task")) { json = json.getJSONObject("task"); } ImportTask task = new ImportTask(); if (json.has("id")) { task.setId(json.getInt("id")); } if (json.has("updateMode")) { task.setUpdateMode(UpdateMode.valueOf(json.getString("updateMode").toUpperCase())); } JSONObject data = null; if (json.has("data")) { data = json.getJSONObject("data"); } else if (json.has("source")) { // backward compatible check for source data = json.getJSONObject("source"); } if (data != null) { // we only support updating the charset if (data.has("charset")) { if (task.getData() == null) { task.setData(new ImportData.TransferObject()); } task.getData().setCharsetEncoding(data.getString("charset")); } } if (json.has("target")) { task.setStore(fromJSON(json.getJSONObject("target"), StoreInfo.class)); } LayerInfo layer = null; if (json.has("layer")) { layer = layer(json.getJSONObject("layer")); } else { layer = importer.getCatalog().getFactory().createLayer(); } task.setLayer(layer); if (json.has("transformChain")) { task.setTransform(transformChain(json.getJSONObject("transformChain"))); } return task; }
LayerInfo layer(JSONObject json) throws IOException { CatalogFactory f = importer.getCatalog().getFactory(); if (json.has("layer")) { json = json.getJSONObject("layer"); } ResourceInfo r = f.createFeatureType(); if (json.has("name")) { r.setName(json.getString("name")); } if (json.has("nativeName")) { r.setNativeName(json.getString("nativeName")); } if (json.has("srs")) { r.setSRS(json.getString("srs")); try { r.setNativeCRS(CRS.decode(json.getString("srs"))); } catch (Exception e) { // should fail later } } if (json.has("bbox")) { r.setNativeBoundingBox(bbox(json.getJSONObject("bbox"))); } LayerInfo l = f.createLayer(); l.setResource(r); // l.setName(); don't need to this, layer.name just forwards to name of underlying resource if (json.has("style")) { JSONObject sobj = new JSONObject(); sobj.put("defaultStyle", json.get("style")); JSONObject lobj = new JSONObject(); lobj.put("layer", sobj); LayerInfo tmp = fromJSON(lobj, LayerInfo.class); if (tmp.getDefaultStyle() != null) { l.setDefaultStyle(tmp.getDefaultStyle()); } else { sobj = new JSONObject(); sobj.put("style", json.get("style")); l.setDefaultStyle(fromJSON(sobj, StyleInfo.class)); } } return l; }