@Test public void testGetPreviousOpObject() { OpObject originObject = null; HistoryManager.HistoryEdit previousHistoryEdit = null; HistoryManager.HistoryEdit historyEdit = new HistoryManager.HistoryEdit( Arrays.asList("user", "test1"), "sys.operation", generateTestDeletedDeltaObject(), new Date().toString(), HistoryManager.Status.DELETED, "0x" ); originObject = historyManager.getPreviousOpObject(originObject, previousHistoryEdit, historyEdit); previousHistoryEdit = historyEdit; assertNotNull(originObject); HistoryManager.HistoryEdit firstHistoryEdit = generateHistoryEdit( generateTestDeletedDeltaObject(), HistoryManager.Status.EDITED, null ); firstHistoryEdit.setDeltaChanges(generateObjEdit()); originObject = historyManager.getPreviousOpObject(originObject, previousHistoryEdit, firstHistoryEdit); previousHistoryEdit = firstHistoryEdit; assertNull(originObject.getFieldByExpr("lat")); assertEquals(originObject.getFieldByExpr("lon"), 12346); assertEquals(originObject.getFieldByExpr("addf"), 1234567); assertEquals(((List)originObject.getFieldByExpr("tags")).size(), 3); HistoryManager.HistoryEdit secondHistoryEdit = generateHistoryEdit( generateTestDeletedDeltaObject(), HistoryManager.Status.EDITED, generateSecondObjEdit() ); secondHistoryEdit.setDeltaChanges(generateSecondObjEdit()); originObject = historyManager.getPreviousOpObject(originObject, previousHistoryEdit, secondHistoryEdit); previousHistoryEdit = secondHistoryEdit; assertEquals(originObject.getFieldByExpr("lon"), 12345L); assertEquals(originObject.getFieldByExpr("lat"), "222EC"); assertNull(originObject.getFieldByExpr("addf")); assertEquals(((List)originObject.getFieldByExpr("tags")).size(), 2); HistoryManager.HistoryEdit createHistoryEdit = generateHistoryEdit( null, HistoryManager.Status.CREATED, null ); originObject = historyManager.getPreviousOpObject(originObject, previousHistoryEdit, createHistoryEdit); assertEquals(originObject.getFieldByExpr("lon"), 12344L); assertEquals(originObject.getFieldByExpr("lat"), "222EC"); assertEquals(originObject.getFieldByExpr("det"), "111EC"); assertEquals(((List)originObject.getFieldByExpr("tags")).size(), 1); }
protected OpObject getPreviousOpObject(OpObject originObject, HistoryEdit previousHistoryEdit, HistoryEdit historyEdit) { if (historyEdit.getStatus().equals(Status.DELETED)) { originObject = historyEdit.objEdit; } else if (historyEdit.getStatus().equals(Status.EDITED) && originObject == null || historyEdit.getStatus().equals(Status.CREATED) && previousHistoryEdit == null) { originObject = blocksManager.getBlockchain().getObjectByName(historyEdit.objType, historyEdit.id.subList(1, historyEdit.id.size())); historyEdit.objEdit = originObject; } else { Map<String, Object> changes = previousHistoryEdit.deltaChanges; if (changes == null) { historyEdit.objEdit = originObject; } else { originObject = generateReverseEditObject(originObject, changes); if (originObject.getFieldByExpr(OpObject.F_STATE) != null && originObject.getFieldByExpr(OpObject.F_STATE).equals(F_FINAL)) { originObject.setFieldByExpr(OpObject.F_STATE, OpObject.F_OPEN); originObject.remove(F_SUBMITTED_OP_HASH); } historyEdit.objEdit = originObject; } } return originObject; }
HistoryManager { protected OpObject getPreviousOpObject(OpObject originObject, HistoryEdit previousHistoryEdit, HistoryEdit historyEdit) { if (historyEdit.getStatus().equals(Status.DELETED)) { originObject = historyEdit.objEdit; } else if (historyEdit.getStatus().equals(Status.EDITED) && originObject == null || historyEdit.getStatus().equals(Status.CREATED) && previousHistoryEdit == null) { originObject = blocksManager.getBlockchain().getObjectByName(historyEdit.objType, historyEdit.id.subList(1, historyEdit.id.size())); historyEdit.objEdit = originObject; } else { Map<String, Object> changes = previousHistoryEdit.deltaChanges; if (changes == null) { historyEdit.objEdit = originObject; } else { originObject = generateReverseEditObject(originObject, changes); if (originObject.getFieldByExpr(OpObject.F_STATE) != null && originObject.getFieldByExpr(OpObject.F_STATE).equals(F_FINAL)) { originObject.setFieldByExpr(OpObject.F_STATE, OpObject.F_OPEN); originObject.remove(F_SUBMITTED_OP_HASH); } historyEdit.objEdit = originObject; } } return originObject; } }
HistoryManager { protected OpObject getPreviousOpObject(OpObject originObject, HistoryEdit previousHistoryEdit, HistoryEdit historyEdit) { if (historyEdit.getStatus().equals(Status.DELETED)) { originObject = historyEdit.objEdit; } else if (historyEdit.getStatus().equals(Status.EDITED) && originObject == null || historyEdit.getStatus().equals(Status.CREATED) && previousHistoryEdit == null) { originObject = blocksManager.getBlockchain().getObjectByName(historyEdit.objType, historyEdit.id.subList(1, historyEdit.id.size())); historyEdit.objEdit = originObject; } else { Map<String, Object> changes = previousHistoryEdit.deltaChanges; if (changes == null) { historyEdit.objEdit = originObject; } else { originObject = generateReverseEditObject(originObject, changes); if (originObject.getFieldByExpr(OpObject.F_STATE) != null && originObject.getFieldByExpr(OpObject.F_STATE).equals(F_FINAL)) { originObject.setFieldByExpr(OpObject.F_STATE, OpObject.F_OPEN); originObject.remove(F_SUBMITTED_OP_HASH); } historyEdit.objEdit = originObject; } } return originObject; }  }
HistoryManager { protected OpObject getPreviousOpObject(OpObject originObject, HistoryEdit previousHistoryEdit, HistoryEdit historyEdit) { if (historyEdit.getStatus().equals(Status.DELETED)) { originObject = historyEdit.objEdit; } else if (historyEdit.getStatus().equals(Status.EDITED) && originObject == null || historyEdit.getStatus().equals(Status.CREATED) && previousHistoryEdit == null) { originObject = blocksManager.getBlockchain().getObjectByName(historyEdit.objType, historyEdit.id.subList(1, historyEdit.id.size())); historyEdit.objEdit = originObject; } else { Map<String, Object> changes = previousHistoryEdit.deltaChanges; if (changes == null) { historyEdit.objEdit = originObject; } else { originObject = generateReverseEditObject(originObject, changes); if (originObject.getFieldByExpr(OpObject.F_STATE) != null && originObject.getFieldByExpr(OpObject.F_STATE).equals(F_FINAL)) { originObject.setFieldByExpr(OpObject.F_STATE, OpObject.F_OPEN); originObject.remove(F_SUBMITTED_OP_HASH); } historyEdit.objEdit = originObject; } } return originObject; }  boolean isRunning(); void saveHistoryForBlockOperations(OpBlock opBlock, DeletedObjectCtx hctx); void retrieveHistory(HistoryObjectRequest historyObjectRequest); List<HistoryEdit> generateHistoryObj(List<HistoryEdit> historyList, String sort); @SuppressWarnings("unchecked") OpObject generateReverseEditObject(OpObject originObject, Map<String, Object> changes); }
HistoryManager { protected OpObject getPreviousOpObject(OpObject originObject, HistoryEdit previousHistoryEdit, HistoryEdit historyEdit) { if (historyEdit.getStatus().equals(Status.DELETED)) { originObject = historyEdit.objEdit; } else if (historyEdit.getStatus().equals(Status.EDITED) && originObject == null || historyEdit.getStatus().equals(Status.CREATED) && previousHistoryEdit == null) { originObject = blocksManager.getBlockchain().getObjectByName(historyEdit.objType, historyEdit.id.subList(1, historyEdit.id.size())); historyEdit.objEdit = originObject; } else { Map<String, Object> changes = previousHistoryEdit.deltaChanges; if (changes == null) { historyEdit.objEdit = originObject; } else { originObject = generateReverseEditObject(originObject, changes); if (originObject.getFieldByExpr(OpObject.F_STATE) != null && originObject.getFieldByExpr(OpObject.F_STATE).equals(F_FINAL)) { originObject.setFieldByExpr(OpObject.F_STATE, OpObject.F_OPEN); originObject.remove(F_SUBMITTED_OP_HASH); } historyEdit.objEdit = originObject; } } return originObject; }  boolean isRunning(); void saveHistoryForBlockOperations(OpBlock opBlock, DeletedObjectCtx hctx); void retrieveHistory(HistoryObjectRequest historyObjectRequest); List<HistoryEdit> generateHistoryObj(List<HistoryEdit> historyList, String sort); @SuppressWarnings("unchecked") OpObject generateReverseEditObject(OpObject originObject, Map<String, Object> changes); static final String ASC_SORT; static final String DESC_SORT; static final String HISTORY_BY_USER; static final String HISTORY_BY_OBJECT; static final String HISTORY_BY_TYPE; static final String HISTORY_ALL; static final String HISTORY_BY_OPERATION_HASH; }