public static String getStringValue(String arg, JSONArray json) throws JSONException { return getJSONObjectWithName(arg, json).get(ClientJsonKeys.value.name()).toString(); }
for (int i = 0; i < inputArr.length(); i++) { JSONObject inpP = inputArr.getJSONObject(i); if (inpP.getString(ClientJsonKeys.name.name()).equals("outputColumns") || inpP.getString(ClientJsonKeys.name.name()).equals("inputColumns")) continue; JSONArray hNodeJSONRep = new JSONArray(inpP.get(ClientJsonKeys.value.name()).toString()); for (int j=0; j<hNodeJSONRep.length(); j++) { JSONObject cNameObj = (JSONObject) hNodeJSONRep.get(j); inpP.put(ClientJsonKeys.value.name(), node.getId()); else { inpP.put(ClientJsonKeys.value.name(), lastNodeId); JSONObject link = new JSONObject(inpP.get(ClientJsonKeys.value.name()).toString()); Object subject = link.get("subject"); String predicate = link.getString("predicate"); inpP.put(ClientJsonKeys.value.name(), subjectHNodeId + "---" + predicate + "---" + objectHNodeId); } else if(HistoryJsonUtil.getParameterType(inpP) == ParameterType.worksheetId) { inpP.put(ClientJsonKeys.value.name(), worksheetId); } else if (HistoryJsonUtil.getParameterType(inpP) == ParameterType.hNodeIdList) { JSONArray hNodes = new JSONArray(inpP.get(ClientJsonKeys.value.name()).toString()); for (int k = 0; k < hNodes.length(); k++) { JSONObject hnodeJSON = hNodes.getJSONObject(k); JSONArray hNodeJSONRep = new JSONArray(hnodeJSON.get(ClientJsonKeys.value.name()).toString()); for (int j=0; j<hNodeJSONRep.length(); j++) { JSONObject cNameObj = (JSONObject) hNodeJSONRep.get(j);
JSONArray hnodes = (JSONArray) JSONUtil.createJson(inpP.getString(ClientJsonKeys.value.name())); for (int j = 0; j < hnodes.length(); j++) { JSONObject obj = (JSONObject)hnodes.get(j); Object value = obj.get(ClientJsonKeys.value.name()); if (value instanceof String) { String hNodeId = (String) value; HNode node = workspace.getFactory().getHNode(hNodeId); JSONArray hNodeRepresentation = node.getJSONArrayRepresentation(workspace.getFactory()); obj.put(ClientJsonKeys.value.name(), hNodeRepresentation); inpP.put(ClientJsonKeys.value.name(), hnodes); } else if(HistoryJsonUtil.getParameterType(inpP) == ParameterType.orderedColumns) { Object tmp = inpP.get(ClientJsonKeys.value.name()); JSONArray hnodes = (JSONArray) JSONUtil.createJson(tmp.toString()); for (int j = 0; j < hnodes.length(); j++) { JSONObject obj = (JSONObject)hnodes.get(j); String hNodeId = obj.getString(ClientJsonKeys.id.name()); HNode node = workspace.getFactory().getHNode(hNodeId); JSONArray hNodeRepresentation = node.getJSONArrayRepresentation(workspace.getFactory()); obj.put(ClientJsonKeys.id.name(), hNodeRepresentation); if (obj.has(ClientJsonKeys.children.name())) obj.put(ClientJsonKeys.children.name(), parseChildren(obj.get(ClientJsonKeys.children.name()).toString(), workspace)); inpP.put(ClientJsonKeys.value.name(), hnodes); } else if(HistoryJsonUtil.getParameterType(inpP) == ParameterType.hNodeId) { String hNodeId = inpP.getString(ClientJsonKeys.value.name()); HNode node = workspace.getFactory().getHNode(hNodeId); JSONArray hNodeRepresentation = node.getJSONArrayRepresentation(workspace.getFactory()); inpP.put(ClientJsonKeys.value.name(), hNodeRepresentation);
private void saveSemanticTypesInformation(Worksheet worksheet, Workspace workspace , Collection<SemanticType> semanticTypes) throws JSONException { JSONArray typesArray = new JSONArray(); // Add the vworksheet information JSONObject vwIDJObj = new JSONObject(); vwIDJObj.put(ClientJsonKeys.name.name(), ParameterType.worksheetId.name()); vwIDJObj.put(ClientJsonKeys.type.name(), ParameterType.worksheetId.name()); vwIDJObj.put(ClientJsonKeys.value.name(), worksheetId); typesArray.put(vwIDJObj); for (SemanticType type: semanticTypes) { // Add the hNode information JSONObject hNodeJObj = new JSONObject(); hNodeJObj.put(ClientJsonKeys.name.name(), ParameterType.hNodeId.name()); hNodeJObj.put(ClientJsonKeys.type.name(), ParameterType.hNodeId.name()); hNodeJObj.put(ClientJsonKeys.value.name(), type.getHNodeId()); typesArray.put(hNodeJObj); // Add the semantic type information JSONObject typeJObj = new JSONObject(); typeJObj.put(ClientJsonKeys.name.name(), ClientJsonKeys.SemanticType.name()); typeJObj.put(ClientJsonKeys.type.name(), ParameterType.other.name()); typeJObj.put(ClientJsonKeys.value.name(), type.getJSONArrayRepresentation()); typesArray.put(typeJObj); } setInputParameterJson(typesArray.toString(4)); }
private void saveSemanticTypesInformation(Worksheet worksheet, Workspace workspace , Collection<SemanticType> semanticTypes) throws JSONException { JSONArray typesArray = new JSONArray(); // Add the vworksheet information JSONObject vwIDJObj = new JSONObject(); vwIDJObj.put(ClientJsonKeys.name.name(), ParameterType.worksheetId.name()); vwIDJObj.put(ClientJsonKeys.type.name(), ParameterType.worksheetId.name()); vwIDJObj.put(ClientJsonKeys.value.name(), worksheetId); typesArray.put(vwIDJObj); for (SemanticType type: semanticTypes) { // Add the hNode information JSONObject hNodeJObj = new JSONObject(); hNodeJObj.put(ClientJsonKeys.name.name(), ParameterType.hNodeId.name()); hNodeJObj.put(ClientJsonKeys.type.name(), ParameterType.hNodeId.name()); hNodeJObj.put(ClientJsonKeys.value.name(), type.getHNodeId()); typesArray.put(hNodeJObj); // Add the semantic type information JSONObject typeJObj = new JSONObject(); typeJObj.put(ClientJsonKeys.name.name(), ClientJsonKeys.SemanticType.name()); typeJObj.put(ClientJsonKeys.type.name(), ParameterType.other.name()); typeJObj.put(ClientJsonKeys.value.name(), type.getJSONArrayRepresentation()); typesArray.put(typeJObj); } setInputParameterJson(typesArray.toString()); }
public static boolean getBooleanValue(String arg, JSONArray json) throws JSONException { return getJSONObjectWithName(arg, json).getBoolean(ClientJsonKeys.value.name()); }
public static ParameterType getParameterType(JSONObject json) throws JSONException { return ParameterType.valueOf(json.getString(ClientJsonKeys.type.name())); }
public static boolean setArgumentValue(String name, Object value, JSONArray inputJson) throws JSONException { JSONObject obj = getJSONObjectWithName(name, inputJson); if(obj != null) { obj.put(ClientJsonKeys.value.name(), value); return true; } return false; }
public static JSONObject getJSONObjectWithName(String arg, JSONArray json) throws JSONException { for(int i=0; i<json.length(); i++) { JSONObject obj = json.getJSONObject(i); String nameS = obj.getString(ClientJsonKeys.name.name()); if(nameS.equals(arg)) { return obj; } } return null; }
private String parseChildren(String inputJSON, Workspace workspace) { JSONArray array = (JSONArray) JSONUtil.createJson(inputJSON); for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); String hNodeId = obj.getString(ClientJsonKeys.id.name()); HNode node = workspace.getFactory().getHNode(hNodeId); JSONArray hNodeRepresentation = node.getJSONArrayRepresentation(workspace.getFactory()); obj.put(ClientJsonKeys.id.name(), hNodeRepresentation); if (obj.has(ClientJsonKeys.children.name())) obj.put(ClientJsonKeys.children.name(), parseChildren(obj.get(ClientJsonKeys.children.name()).toString(), workspace)); } return array.toString(); }
public static JSONObject createJsonObject(String name, Object value, ParameterType type) throws JSONException { JSONObject obj = new JSONObject(); obj.put(ClientJsonKeys.name.name(), name); obj.put(ClientJsonKeys.value.name(), value); obj.put(ClientJsonKeys.type.name(), type.toString()); return obj; } }
private JSONArray processChildren(JSONArray children, HTable hTable, String commandName) { for (int i = 0; i < children.length(); i++) { JSONObject obj = children.getJSONObject(i); JSONArray array = new JSONArray(obj.get(ClientJsonKeys.id.name()).toString()); processHNodeId(array, hTable, commandName, obj); if (obj.has(ClientJsonKeys.children.name())) { obj.put(ClientJsonKeys.children.name(), processChildren(new JSONArray(obj.get(ClientJsonKeys.children.name()).toString()), hTable, commandName)); } } return children; } }