Displaying differences for changeset |
@@ -55,11 +55,16 @@ |
static final String EDIT_PCANNUALPROD = Config.getString("edit.pcannualprod", |
"/services/models/esd/%s/%s/plant-community-tables.json?table=annual%%20production"); |
+ // %s (053C) MLRA id, %s (R053CY010SD) EcoclassID |
+// "/services/models/esd/%s/%s/plant-community-tables.json?table=annual%%20production"); |
+ static final String EDIT_PLANTCOMPOSITION = Config.getString("edit.plantcomposition", |
+ "/services/plant-community-tables/esd/%s/%s/1/1/1/rangeland-plant-composition.json"); |
+ |
static final Configuration CONF = Configuration.defaultConfiguration() |
.addOptions(Option.SUPPRESS_EXCEPTIONS); |
// <url> -> <response> |
- final LRUCache<String, ReadContext> cache = new LRUCache<>(EDIT_CACHE_SIZE); |
+ static final LRUCache<String, ReadContext> cache = new LRUCache<>(EDIT_CACHE_SIZE); |
SessionLogger log; |
@@ -76,7 +81,6 @@ |
ReadContext callEdit(String url) throws Exception { |
ReadContext resp; |
- // System.out.println("Calling : " + url); |
synchronized (cache) { |
resp = cache.get(url); |
} |
@@ -118,4 +122,9 @@ |
return callEdit(String.format(EDIT_URL + EDIT_PCANNUALPROD, Utils.getMLRA(ecId), ecId)); |
} |
+ |
+ public ReadContext fetchPlantComposition(String ecId) throws Exception { |
+ return callEdit(String.format(EDIT_URL + EDIT_PLANTCOMPOSITION, Utils.getMLRA(ecId), ecId)); |
+ } |
+ |
} |
@@ -24,7 +24,6 @@ |
*/ |
public class EditQueries { |
- |
public static String getEcoClassNameFor(ReadContext r, String ecId) throws Exception { |
List<String> names = r.read(String.format("$.ecoclasses[?(@.id == '%s')].name", ecId)); |
return names.isEmpty() ? null : names.get(0); |
@@ -56,6 +55,11 @@ |
} |
+ public static List getCompositionGroups(ReadContext resp) throws Exception { |
+ return resp.read(String.format("$.rangeComposition.*")); |
+ } |
+ |
+ |
public static String getSiteDescrUrl(String ecId) { |
return String.format(EDIT_URL + EDIT_CATALOGS, Utils.getMLRA(ecId), ecId); |
} |
@@ -14,7 +14,12 @@ |
import com.jayway.jsonpath.ReadContext; |
import csip.SessionLogger; |
import edit.EditConnection; |
+import java.util.ArrayList; |
import java.util.List; |
+import java.util.Map; |
+import org.codehaus.jettison.json.JSONArray; |
+import org.codehaus.jettison.json.JSONException; |
+import org.codehaus.jettison.json.JSONObject; |
/** |
* Rest service access to EditQueries (Ecological Dynamics Interpretive Tool). |
@@ -24,9 +29,7 @@ |
*/ |
public class EditScratch { |
- public static void main(String[] args) throws Exception { |
-// JSONArray r = gras_fisprodesd("R053CY010SD", 0.2, 0, "name", new SessionLogger()); |
-// System.out.println(r.toString(4)); |
+ static void t1() throws Exception { |
EditConnection s = new EditConnection(new SessionLogger()); |
String es_id = "R053CY004SD"; |
@@ -35,8 +38,60 @@ |
// System.out.println(new JSONObject(f).toString(2)); |
List l = EditQueries.getAnnualProd(f, 1, 1, 1); |
+ System.out.println(l); |
+ System.out.println(l.size()); |
- System.out.println(l); |
+ } |
+ |
+ static List<List> grs = new ArrayList<>(); |
+ |
+ |
+ static void add(Map<String, Object> o) throws JSONException { |
+ int index = (int) o.get("group") - 1; |
+ List gr; |
+ if (index >= grs.size()) |
+ grs.add(index, gr = new ArrayList()); |
+ else |
+ gr = (List) grs.get(index); |
+ |
+ gr.add(o); |
+ } |
+ |
+ |
+ static void t12() throws Exception { |
+ EditConnection s = new EditConnection(new SessionLogger()); |
+ String es_id = "R042XC244TX"; |
+ |
+ ReadContext f = s.fetchPlantComposition(es_id); |
+// System.out.println(f.jsonString()); |
+ |
+ List<List<Map<String, Object>>> cg = EditQueries.getCompositionGroups(f); |
+ for (List<Map<String, Object>> comps : cg) { |
+ for (Map<String, Object> comp : comps) { |
+ add(comp); |
+ } |
+ } |
+ |
+ for (List gr : grs) { |
+ System.out.println("----"); |
+ for (Object object : gr) { |
+ System.out.println(object); |
+ } |
+ } |
+ |
+ System.out.println(grs); |
+// System.out.println(cg); |
+// System.out.println(cg.size()); |
+// System.out.println(cg.get(0).get(0).getClass()); |
+ |
+ } |
+ |
+ |
+ public static void main(String[] args) throws Exception { |
+ |
+ t12(); |
+// JSONArray r = gras_fisprodesd("R053CY010SD", 0.2, 0, "name", new SessionLogger()); |
+// System.out.println(r.toString(4)); |
// System.out.println(l.get(0)); |
// String edit_es_name = getEcoClassNameFor(s.fetchEcoClassList(es_id), es_id); |
@@ -15,10 +15,14 @@ |
// check 'R053CY004SD' |
public static void checkEcoclassId(String ecId) { |
- if (ecId.length() != 11 |
- || (ecId.charAt(0) != 'R' && ecId.charAt(0) != 'F')) { |
+ if (!isEcoclassId(ecId)) |
throw new IllegalArgumentException("Invalid ecoclassid: " + ecId); |
- } |
+ } |
+ |
+ |
+ public static boolean isEcoclassId(String ecId) { |
+ return (ecId.length() == 11 |
+ && (ecId.charAt(0) == 'R' || ecId.charAt(0) == 'F')); |
} |