private String getCondition(Flow flow) { String conditionWords = flow.getCondition() .map(condition -> (WHEN + getLowerCaseWordsOfClassName(condition.getClass()))).orElse(""); return conditionWords; } }
private void enableStartOfIncludedFlow(Flow includedFlow) { Optional<FlowStep> optionalFirstStepOfIncludedFlow = includedFlow.getFirstStep(); optionalFirstStepOfIncludedFlow.ifPresent(this::enableStartOfFirstStepOfIncludedFlowAfterIncludeStep); }
private FlowStep getLastStepOf(Flow flow) { List<FlowStep> stepsOfFlow = flow.getSteps(); int lastStepIndex = stepsOfFlow.size() - 1; FlowStep lastStepOfFlow = stepsOfFlow.get(lastStepIndex); return lastStepOfFlow; } }
/** * Creates a new flow in this use case. * * @param flowName * the name of the flow to be created. * @return the newly created flow * @throws ElementAlreadyInModel * if a flow with the specified name already exists in the use case */ Flow newFlow(String flowName) { Flow flow = new Flow(flowName, this); saveModelElement(flow, nameToFlowMap); return flow; }
/** * Returns the steps contained in this flow. Do not modify the returned * collection directly. * * @return a collection of the steps */ public List<FlowStep> getSteps() { List<FlowStep> steps = getUseCase().getModifiableSteps().stream() .filter(step -> step instanceof FlowStep) .map(step -> (FlowStep)step) .filter(step -> this.equals(step.getFlow())) .collect(Collectors.toList()); return Collections.unmodifiableList(steps); }
private String getFlowPosition(Flow flow) { FlowPosition flowPosition = flow.getFlowPosition(); String result = ""; if (flowPosition != null) { Step step = flowPosition.getStep(); boolean isNonDefaultFlowPosition = isNonDefaultFlowCondition(flowPosition, step); if (isNonDefaultFlowPosition) { String stepName = step != null ? step.getName() : ""; String flowPositionWords = getLowerCaseWordsOfClassName(flowPosition.getClass()); String flowPositionWithStepName = flowPositionWords + " " + stepName; result = flowPositionWithStepName.trim(); } } return result; }
/** * Returns the first step of the flow * * @return the first step of the flow, or an empty optional if the flow has no * steps. */ public Optional<FlowStep> getFirstStep() { List<FlowStep> steps = getSteps(); return steps.size() > 0 ? Optional.of(steps.get(0)) : Optional.empty(); }
/** * Convenience method that returns the position of the flow (as defined e.g. by * "InsteadOf"). * * <p> * Internally this calls the method of the same name of the first step in the * flow. * * @return the flow position, or null if the flow is empty. */ public FlowPosition getFlowPosition() { FlowPosition flowPosition = getFirstStep().map(step -> step.getFlowPosition()).orElse(null); return flowPosition; }
@Test public void createsSingleStepThatHandlesUserCommandWithCondition() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); useCasePart.basicFlow().condition(() -> textIsAvailable()) .step(CUSTOMER_ENTERS_TEXT).user(EntersText.class).system(displaysEnteredText()) .build(); UseCase useCase = useCasePart.getUseCase(); assertTrue(useCase.getBasicFlow().getCondition().isPresent()); }
private void appendToLastStepOfFlow() { List<FlowStep> flowSteps = getFlow().getSteps(); FlowStep lastFlowStep = flowSteps.isEmpty() ? null : flowSteps.get(flowSteps.size() - 1); setPreviousStepInFlow(lastFlowStep); setFlowPosition(new After(lastFlowStep)); }
/** * Convenience method that returns the condition of the flow. * * <p> * Internally this calls the method of the same name of the first step in the * flow. * * @return the condition */ public Optional<Condition> getCondition() { Optional<Condition> condition = getFirstStep().flatMap(step -> step.getCondition()); return condition; } }
@Test public void createsSingleStepThatHandlesUserCommandWithFlow() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); Model model = useCasePart.basicFlow() .step(CUSTOMER_ENTERS_TEXT).user(EntersText.class).system(displaysEnteredText()) .build(); UseCase useCase = useCasePart.getUseCase(); assertFalse(useCase.getBasicFlow().getCondition().isPresent()); Collection<Step> steps = useCase.getSteps(); assertEquals(1, steps.size()); Step step = steps.iterator().next(); assertEquals(CUSTOMER_ENTERS_TEXT, step.getName()); assertEquals(USE_CASE, step.getUseCase().getName()); assertEquals(model.getUserActor(), step.getActors()[0]); }
@Test public void createsTwoStepsInBasicFlowAndCheckIfTheyExistByIndex() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); useCasePart.basicFlow() .step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()) .step(SYSTEM_DISPLAYS_TEXT_AGAIN).system(displaysConstantText()); List<FlowStep> steps = useCasePart.getUseCase().getBasicFlow().getSteps(); assertEquals(2, steps.size()); assertEquals(SYSTEM_DISPLAYS_TEXT, steps.get(0).getName()); assertEquals(SYSTEM_DISPLAYS_TEXT_AGAIN, steps.get(1).getName()); }
@Test public void implicitlyCreatesEmptyBasicFlow() { modelBuilder.useCase(USE_CASE); Model model = modelBuilder.build(); UseCase useCase = model.findUseCase(USE_CASE); Collection<Flow> flows = useCase.getFlows(); assertEquals(1, flows.size()); assertEquals(useCase.getBasicFlow(), flows.iterator().next()); assertFalse(useCase.getBasicFlow().getFirstStep().isPresent()); }
@Test public void createsOneStepInAlternativeFlowAndCheckIfItExistsByIndex() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); useCasePart.basicFlow() .step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()).flow(ALTERNATIVE_FLOW) .step(SYSTEM_DISPLAYS_TEXT_AGAIN).system(displaysConstantText()); List<FlowStep> steps = useCasePart.getUseCase().findFlow(ALTERNATIVE_FLOW).getSteps(); assertEquals(1, steps.size()); assertEquals(SYSTEM_DISPLAYS_TEXT_AGAIN, steps.get(0).getName()); }