@Test public void testProcessSecondUpdate() throws Exception { JsonNode unitBeforeSecondUpdate = JsonHandler.getFromFile(PropertiesUtils.getResourceFile("Trigger/history_unit_before_second_update.json")); JsonNode unitAfterSecondUpdate = JsonHandler.getFromFile(PropertiesUtils.getResourceFile("Trigger/history_unit_after_second_update.json")); ChangesHistory changesHistory = new ChangesHistory("_mgt.ClassificationRule"); changesHistory.addHistory(unitBeforeSecondUpdate, unitAfterSecondUpdate); String unitAfterSecondUpdateString = unitAfterSecondUpdate.toString(); JsonPath path = JsonPath.from(unitAfterSecondUpdateString); List histories = path.getList("_history"); Assert.assertEquals(2, histories.size()); Assert.assertNotNull(path.get("_history[0].ud")); Assert.assertEquals(9, path.getInt("_history[0].data._v")); Assert.assertEquals("Secret Défense", path.getString("_history[0].data._mgt.ClassificationRule.ClassificationLevel")); Assert.assertNotNull(path.get("_history[1].ud")); Assert.assertEquals(10, path.getInt("_history[1].data._v")); Assert.assertEquals("Confidentiel Défense", path.getString("_history[1].data._mgt.ClassificationRule.ClassificationLevel")); }
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);  }