JSONLDUtilSimple { public static JSONObject mergeJSONObjects(String left, String right, Map<String, String> provenanceProperties) throws ParseException { JSONParser parser = new JSONParser(); return mergeJSONObjects((JSONObject)parser.parse(left), (JSONObject)parser.parse(right), provenanceProperties); } private  JSONLDUtilSimple(); static JSONObject mergeJSONObjects(String left, String right, Map<String, String> provenanceProperties); static JSONObject mergeJSONObjects(Iterator<String> iterator); static JSONObject mergeJSONObjects(Iterator<String> iterator, Map<String, String> provenanceProperties); static JSONObject mergeJSONObjects(JSONObject left, JSONObject right, Map<String, String> provenanceProperties);  }
@Test public void testProvenance() throws IOException, ParseException { HashMap<String, String> provProperties = new HashMap<String, String>(); provProperties.put("source", "string"); provProperties.put("publisher", "string"); provProperties.put("dateRecorded", "date"); JSONParser parser = new JSONParser(); String json_line = "{\"a\": [\"Vulnerability\"], " + "\"dateRecorded\": [\"2017-02-10T12:13:51\",\"2017-02-09T18:13:51\"], " + "\"description\": \"d\", " + "\"publisher\": \"hg-cve\", \"uri\": \"http: + "\"source\": \"hg-cve-2A7DF54A\", " + "\"hasCVSS\": {\"uri\" :\"http: + "\"vulnerabilityOf\": [{\"uri\":\"cpe:/a:apache:tomcat:7.0.12\"}, {\"uri\": \"cpe:/a:apache:tomcat:6.0.27\"}], " + "\"name\": [\"CVE-2013-2067\"]}"; JSONObject json1 = (JSONObject)parser.parse(json_line); JSONObject json2 = (JSONObject)parser.parse(json_line); json2.put("dateRecorded", "2017-02-09T16:13:51"); json2.put("source", "hg-cve-FFFFFFFF"); JSONObject result = JSONLDUtilSimple.mergeJSONObjects(json1, json2, provProperties); assert(result.get("dateRecorded").toString().equals("[\"2017-02-09T16:13:51\",\"2017-02-10T12:13:51\"]")); assert(result.get("source").toString().equals("hg-cve-2A7DF54A")); JSONArray vulArr = (JSONArray)json2.get("vulnerabilityOf"); JSONObject vul = new JSONObject(); vul.put("uri", "cpe:/a:apache:tomcat:8.0.12"); vulArr.add(vul); json2.put("vulnerabilityOf", vulArr); result = JSONLDUtilSimple.mergeJSONObjects(json1, json2, provProperties); assert(result.get("dateRecorded").toString().equals("[\"2017-02-09T16:13:51\",\"2017-02-10T12:13:51\"]")); assert(result.get("source").toString().equals("hg-cve-2A7DF54A")); json2.put("tempField", "test"); result = JSONLDUtilSimple.mergeJSONObjects(json1, json2, provProperties); assert(result.get("dateRecorded").toString().equals("[\"2017-02-09T16:13:51\",\"2017-02-10T12:13:51\"]")); assert(result.get("source").toString().equals("[\"hg-cve-2A7DF54A\",\"hg-cve-FFFFFFFF\"]")); }