@Test public void testProcessAddMetadata() throws Exception { JsonNode unitBeforeUpdate = JsonHandler.getFromFile(PropertiesUtils.getResourceFile("Trigger/history_unit_before_add.json")); JsonNode unitAfterUpdate = JsonHandler.getFromFile(PropertiesUtils.getResourceFile("Trigger/history_unit_after_add.json")); ChangesHistory changesHistory = new ChangesHistory("_mgt.ClassificationRule"); changesHistory.addHistory(unitBeforeUpdate, unitAfterUpdate); String unitAfterUpdateString = unitAfterUpdate.toString(); JsonPath path = JsonPath.from(unitAfterUpdateString); List histories = path.getList("_history"); Assert.assertEquals(1, histories.size()); Assert.assertNotNull(path.get("_history[0].ud")); Assert.assertEquals(10, path.getInt("_history[0].data._v")); Assert.assertNull(unitAfterUpdate.get("_history").get(0).get("data").get("_mgt").get("ClassificationRule")); }
public void addHistory(JsonNode unitBeforeUpdate, JsonNode unitAfterUpdate) { final JsonNode objectToHistory = JsonHandler.findNode(unitBeforeUpdate, objectPathForHistory); final JsonNode historyNode = unitAfterUpdate.findPath(History._HISTORY); final History history = new History(objectPathForHistory, getUnitVersion(unitBeforeUpdate), objectToHistory); if (historyNode.isMissingNode()) { ((ObjectNode) unitAfterUpdate).set(History._HISTORY, history.getArrayNode()); } else { ((ArrayNode) historyNode).add(history.getNode()); } }
ChangesHistory { public void addHistory(JsonNode unitBeforeUpdate, JsonNode unitAfterUpdate) { final JsonNode objectToHistory = JsonHandler.findNode(unitBeforeUpdate, objectPathForHistory); final JsonNode historyNode = unitAfterUpdate.findPath(History._HISTORY); final History history = new History(objectPathForHistory, getUnitVersion(unitBeforeUpdate), objectToHistory); if (historyNode.isMissingNode()) { ((ObjectNode) unitAfterUpdate).set(History._HISTORY, history.getArrayNode()); } else { ((ArrayNode) historyNode).add(history.getNode()); } } }
ChangesHistory { public void addHistory(JsonNode unitBeforeUpdate, JsonNode unitAfterUpdate) { final JsonNode objectToHistory = JsonHandler.findNode(unitBeforeUpdate, objectPathForHistory); final JsonNode historyNode = unitAfterUpdate.findPath(History._HISTORY); final History history = new History(objectPathForHistory, getUnitVersion(unitBeforeUpdate), objectToHistory); if (historyNode.isMissingNode()) { ((ObjectNode) unitAfterUpdate).set(History._HISTORY, history.getArrayNode()); } else { ((ArrayNode) historyNode).add(history.getNode()); } } ChangesHistory(String objectPathForHistory); }
ChangesHistory { public void addHistory(JsonNode unitBeforeUpdate, JsonNode unitAfterUpdate) { final JsonNode objectToHistory = JsonHandler.findNode(unitBeforeUpdate, objectPathForHistory); final JsonNode historyNode = unitAfterUpdate.findPath(History._HISTORY); final History history = new History(objectPathForHistory, getUnitVersion(unitBeforeUpdate), objectToHistory); if (historyNode.isMissingNode()) { ((ObjectNode) unitAfterUpdate).set(History._HISTORY, history.getArrayNode()); } else { ((ArrayNode) historyNode).add(history.getNode()); } } ChangesHistory(String objectPathForHistory); void addHistory(JsonNode unitBeforeUpdate, JsonNode unitAfterUpdate); }
ChangesHistory { public void addHistory(JsonNode unitBeforeUpdate, JsonNode unitAfterUpdate) { final JsonNode objectToHistory = JsonHandler.findNode(unitBeforeUpdate, objectPathForHistory); final JsonNode historyNode = unitAfterUpdate.findPath(History._HISTORY); final History history = new History(objectPathForHistory, getUnitVersion(unitBeforeUpdate), objectToHistory); if (historyNode.isMissingNode()) { ((ObjectNode) unitAfterUpdate).set(History._HISTORY, history.getArrayNode()); } else { ((ArrayNode) historyNode).add(history.getNode()); } } ChangesHistory(String objectPathForHistory); void addHistory(JsonNode unitBeforeUpdate, JsonNode unitAfterUpdate);  }