/** method to update data in caching layer object from JSON * */ public boolean updateFromJSON(JSONObject jsonObj) { try { JSONArray hasArcsArray = jsonObj.optJSONArray("hasArcs"); if (hasArcsArray != null) { ArrayList<Arc> aListOfHasArcs = new ArrayList<Arc>(hasArcsArray.length()); for (int i = 0; i < hasArcsArray.length(); i++) { int id = hasArcsArray.optInt(i); if (ArcManager.getInstance().get(id) != null) { aListOfHasArcs.add(ArcManager.getInstance().get(id)); } } setHasArcs(aListOfHasArcs); } if (!jsonObj.isNull("hasPropertySet")) { int hasPropertySetId = jsonObj.optInt("hasPropertySet"); PropertySet value = PropertySetManager.getInstance().get(hasPropertySetId); if (value != null) { setHasPropertySet(value); } } if (!jsonObj.isNull("hasDomainNodes")) { int hasDomainNodesId = jsonObj.optInt("hasDomainNodes"); NodeList value = NodeListManager.getInstance().get(hasDomainNodesId); if (value != null) { setHasDomainNodes(value); } } } catch (Exception e) { logWriter.error("Failure updating from JSON", e); return false; } return true; }
public JSONObject asJSONTreeAux(ConcurrentHashMap<DomainConcept, DomainConcept> written) { JSONObject jsonObj = new JSONObject(); try { jsonObj.put("class", "ClassModel"); jsonObj.put("id", id); if (written.contains(this)) { return jsonObj; } written.put(this, this); if (getHasArcs() != null) { JSONArray jsonHasArcs = new JSONArray(); for (Arc row : getHasArcs()) { jsonHasArcs.put(row.asJSONTreeAux(written)); } jsonObj.put("hasArcs", jsonHasArcs); } if (getHasPropertySet() != null) { jsonObj.put("hasPropertySet", getHasPropertySet().asJSONTreeAux(written)); } jsonObj.put("id", getId()); if (getHasDomainNodes() != null) { jsonObj.put("hasDomainNodes", getHasDomainNodes().asJSONTreeAux(written)); } written.remove(this); } catch (Exception e1) { logWriter.error("Error in marshalling to JSON ", e1); } return jsonObj; }
/** method to marshall data from caching layer object to JSON * */ public JSONObject asJSON() { JSONObject jsonObj = new JSONObject(); try { jsonObj.put("class", "ClassModel"); jsonObj.put("id", id); if (getHasArcs() != null) { JSONArray jsonHasArcs = new JSONArray(); for (Arc row : getHasArcs()) { jsonHasArcs.put(row.getId()); } jsonObj.put("hasArcs", jsonHasArcs); } if (getHasPropertySet() != null) { jsonObj.put("hasPropertySet", getHasPropertySet().getId()); } jsonObj.put("id", getId()); if (getHasDomainNodes() != null) { jsonObj.put("hasDomainNodes", getHasDomainNodes().getId()); } } catch (Exception e1) { logWriter.error("Error in marshalling to JSON ", e1); } return jsonObj; }