private JsonNode filterNodes(JsonNode jsonNode) { for (String filterNode : getKeysToFilter()) { JsonNode parent; while ((parent = jsonNode.findParent(filterNode)) != null) { if (parent instanceof ObjectNode) { JsonNode remove = ((ObjectNode) parent).remove(filterNode); System.out.println(" >removed node \"" + filterNode + "\": " + remove); } } } return jsonNode; }
// public String parseSchema(TreeNode node, String key) throws IOException { // if (node.isObject()) { // type.push(key); // Iterator<String> fields = node.fieldNames(); // List<String> s = new ArrayList<String>(); // while (fields.hasNext()) { // String field = fields.next(); // if (node.at("/type").toString().contains("object")) { // // System.out.println("true"); // key = parseSchema(node.get(field), field); // // } else { // // System.out.println("false"); // // System.out.println(type.toString()+":"+field); // // s.add(node.a); // key = parseSchema(node.get(field), field); // } // } // types.put(type.toString(), s); // type.pop(); // } // // return key; // } public String printAll(JsonNode node, String f) throws JsonProcessingException, IOException, JSONException { System.out.println("---"); ObjectNode json = factory.objectNode(); if (!f.equals("properties")) { type.push(f); } Iterator<String> fieldNames = node.fieldNames(); Enumeration<String> e = type.elements(); while (e.hasMoreElements()) { e.nextElement(); } String uri = type.toString() .replaceAll(", ", ".") .replaceFirst(".schema.", ".community.") .replaceAll("[\\[\\]]", ""); json.put("uri", uri); ArrayNode index_mode = factory.arrayNode(); index_mode.add("dm4.core.fulltext"); index_mode.add("dm4.core.fulltext_key"); json.set("index_mode_uris", index_mode); json.put("data_type_uri", "dm.core.text"); ArrayNode array = factory.arrayNode(); while (fieldNames.hasNext()) { String fieldName = fieldNames.next(); JsonNode fieldValue = node.get(fieldName); if (node.findParent("description").get("description") != null) { json.set("value", node.findParent("description").get("description")); } if (fieldValue.isObject()) { ObjectNode assoc = factory.objectNode(); assoc.put( "child_type_uri", uri + "." + printAll(fieldValue, fieldName).replaceAll("\n", "")); assoc.put("child_cardinality_uri", "dm4.core.one"); assoc.put("parent_cardinality_uri", "dm4.core.one"); assoc.put("assoc_type_uri", "dm4.core.composition_def"); // json.append(("composite: "+uri+"."+printAll(fieldValue, fieldName)).replaceAll("\n", // "")+"\n"); array.add(assoc); json.put("data_type_uri", "dm4.core.composite"); json.set("assoc_defs", array); } else { // String value = fieldValue.toString(); if (fieldName.equals("description")) { json.set("value", fieldValue); // json.append("\"value\"" + " : " + value+",\n"); } if (fieldName.equals("enum")) { // json.append("\"options\"" + " : " + value+",\n"); json.set("enum", fieldValue); } } } // json.append("}"); System.out.println("xxx"); System.out.println(m.writerWithDefaultPrettyPrinter().writeValueAsString(json)); TopicTypeModel t = new TopicTypeModel(new JSONObject(json.toString())); System.err.println(t.getUri()); System.err.println(t.getAssocDefs()); if (!f.equals("properties")) { return type.pop(); } else { return ""; } }