ReorderStepsUtils { boolean isStepOrderInvalid(List<AppendStep> appendSteps) { final Set<String> notYetAvailableColumnsIds = appendSteps .stream() .flatMap(step -> step.getDiff().getCreatedColumns().stream()) .collect(Collectors.toSet()); return appendSteps.stream().noneMatch(step -> { for (Action action : step.getActions()) { final Map<String, String> parameters = action.getParameters(); String[] columnIds = { parameters.get(ImplicitParameters.COLUMN_ID.getKey()) }; if (ActionScope.MULTI_COLUMNS .getDisplayName() .equals(action.getParameters().get(ImplicitParameters.SCOPE.getKey()))) { columnIds = ActionsUtils.extractColumnsId(parameters.get(COLUMN_IDS)); } notYetAvailableColumnsIds.removeAll(step.getDiff().getCreatedColumns()); for (String columnId : columnIds) { if (notYetAvailableColumnsIds.contains(columnId)) { return true; } if (StringUtils.equalsIgnoreCase(DeleteColumn.DELETE_COLUMN_ACTION_NAME, action.getName())) { notYetAvailableColumnsIds.add(columnId); } } } return false; }); }    }
@Test public void useAColumnBeforeCreationOrAfterDeletion_coherentStepsList() throws Exception { List<AppendStep> steps = new ArrayList<>(); steps.add(createAppendStep("0002", asList("0003", "0004"))); steps.add(createAppendStep("0003", emptyList())); assertTrue(reorderStepsUtils.isStepOrderInvalid(steps)); }
@Test public void useAColumnBeforeCreationOrAfterDeletion_incoherentStepsList() throws Exception { List<AppendStep> steps = new ArrayList<>(); steps.add(createAppendStep("0003", emptyList())); steps.add(createAppendStep("0002", asList("0003", "0004"))); assertFalse(reorderStepsUtils.isStepOrderInvalid(steps)); }
@Test public void useColumnsBeforeCreationOrAfterDeletion_coherentStepsList() throws Exception { List<AppendStep> steps = new ArrayList<>(); steps.add(createAppendStep("0002", asList("0003", "0004"))); AppendStep step = createAppendStepMultiColumn("[\"0003\",\"0004\"]", emptyList()); step.getActions().get(0).getParameters().put("scope", "multi_columns"); steps.add(step); assertTrue(reorderStepsUtils.isStepOrderInvalid(steps)); }
@Test public void useColumnsBeforeCreationOrAfterDeletion_incoherentStepsList() throws Exception { List<AppendStep> steps = new ArrayList<>(); AppendStep step = createAppendStepMultiColumn("[\"0003\",\"0004\"]", emptyList()); step.getActions().get(0).getParameters().put("scope", "multi_columns"); steps.add(step); steps.add(createAppendStep("0002", asList("0003", "0004"))); assertFalse(reorderStepsUtils.isStepOrderInvalid(steps)); }