@Test public void getLastSuccessfulStateLog() { List<FlowLog> flowLogs = new ArrayList<>(); FlowLog successfulFlowLog1 = new FlowLog(); successfulFlowLog1.setStateStatus(StateStatus.SUCCESSFUL); successfulFlowLog1.setNextEvent("NEXT_EVENT1"); successfulFlowLog1.setCreated(1L); successfulFlowLog1.setCurrentState("CURRENT_STATE1"); flowLogs.add(successfulFlowLog1); FlowLog successfulFlowLog3 = new FlowLog(); successfulFlowLog3.setStateStatus(StateStatus.SUCCESSFUL); successfulFlowLog3.setNextEvent("NEXT_EVENT3"); successfulFlowLog3.setCreated(3L); successfulFlowLog3.setCurrentState("CURRENT_STATE3"); flowLogs.add(successfulFlowLog3); FlowLog successfulFlowLog2 = new FlowLog(); successfulFlowLog2.setStateStatus(StateStatus.SUCCESSFUL); successfulFlowLog2.setNextEvent("NEXT_EVENT1"); successfulFlowLog2.setCreated(2L); successfulFlowLog2.setCurrentState("CURRENT_STATE1"); flowLogs.add(successfulFlowLog2); FlowLog failedFlowLog = new FlowLog(); failedFlowLog.setStateStatus(StateStatus.FAILED); failedFlowLog.setCurrentState("FAILED_CURRENT_STATE"); failedFlowLog.setCreated(4L); flowLogs.add(failedFlowLog); FlowLog lastSuccessfulFlowLog = FlowRetryUtil.getLastSuccessfulStateLog("FAILED_CURRENT_STATE", flowLogs); assertEquals(successfulFlowLog3, lastSuccessfulFlowLog); }
public static FlowLog getLastSuccessfulStateLog(String failedState, List<FlowLog> flowLogs) { List<FlowLog> reversedOrderedFlowLog = flowLogs.stream() .sorted(Comparator.comparing(FlowLog::getCreated).reversed()) .collect(Collectors.toList()); for (int i = 0; i < reversedOrderedFlowLog.size(); i++) { if (failedState.equals(reversedOrderedFlowLog.get(i).getCurrentState())) { if (reversedOrderedFlowLog.size() < (i + 1)) { return reversedOrderedFlowLog.get(i); } else { return reversedOrderedFlowLog.get(i + 1); } } } return reversedOrderedFlowLog.get(0); }
FlowRetryUtil { public static FlowLog getLastSuccessfulStateLog(String failedState, List<FlowLog> flowLogs) { List<FlowLog> reversedOrderedFlowLog = flowLogs.stream() .sorted(Comparator.comparing(FlowLog::getCreated).reversed()) .collect(Collectors.toList()); for (int i = 0; i < reversedOrderedFlowLog.size(); i++) { if (failedState.equals(reversedOrderedFlowLog.get(i).getCurrentState())) { if (reversedOrderedFlowLog.size() < (i + 1)) { return reversedOrderedFlowLog.get(i); } else { return reversedOrderedFlowLog.get(i + 1); } } } return reversedOrderedFlowLog.get(0); } }
FlowRetryUtil { public static FlowLog getLastSuccessfulStateLog(String failedState, List<FlowLog> flowLogs) { List<FlowLog> reversedOrderedFlowLog = flowLogs.stream() .sorted(Comparator.comparing(FlowLog::getCreated).reversed()) .collect(Collectors.toList()); for (int i = 0; i < reversedOrderedFlowLog.size(); i++) { if (failedState.equals(reversedOrderedFlowLog.get(i).getCurrentState())) { if (reversedOrderedFlowLog.size() < (i + 1)) { return reversedOrderedFlowLog.get(i); } else { return reversedOrderedFlowLog.get(i + 1); } } } return reversedOrderedFlowLog.get(0); } private  FlowRetryUtil(); }
FlowRetryUtil { public static FlowLog getLastSuccessfulStateLog(String failedState, List<FlowLog> flowLogs) { List<FlowLog> reversedOrderedFlowLog = flowLogs.stream() .sorted(Comparator.comparing(FlowLog::getCreated).reversed()) .collect(Collectors.toList()); for (int i = 0; i < reversedOrderedFlowLog.size(); i++) { if (failedState.equals(reversedOrderedFlowLog.get(i).getCurrentState())) { if (reversedOrderedFlowLog.size() < (i + 1)) { return reversedOrderedFlowLog.get(i); } else { return reversedOrderedFlowLog.get(i + 1); } } } return reversedOrderedFlowLog.get(0); } private  FlowRetryUtil(); static FlowLog getLastSuccessfulStateLog(String failedState, List<FlowLog> flowLogs); static Optional<FlowLog> getMostRecentFailedLog(List<FlowLog> flowLogs); static boolean isFlowPending(List<FlowLog> flowLogs); }
FlowRetryUtil { public static FlowLog getLastSuccessfulStateLog(String failedState, List<FlowLog> flowLogs) { List<FlowLog> reversedOrderedFlowLog = flowLogs.stream() .sorted(Comparator.comparing(FlowLog::getCreated).reversed()) .collect(Collectors.toList()); for (int i = 0; i < reversedOrderedFlowLog.size(); i++) { if (failedState.equals(reversedOrderedFlowLog.get(i).getCurrentState())) { if (reversedOrderedFlowLog.size() < (i + 1)) { return reversedOrderedFlowLog.get(i); } else { return reversedOrderedFlowLog.get(i + 1); } } } return reversedOrderedFlowLog.get(0); } private  FlowRetryUtil(); static FlowLog getLastSuccessfulStateLog(String failedState, List<FlowLog> flowLogs); static Optional<FlowLog> getMostRecentFailedLog(List<FlowLog> flowLogs); static boolean isFlowPending(List<FlowLog> flowLogs);  }