Fix next handling in ComponentFlow

- This fixes a bug where returning null from a next()
  didn't stop a flow.
- Fixes #510
This commit is contained in:
Janne Valkealahti
2022-08-22 13:06:13 +01:00
parent 52baaa3f86
commit 7c4700b7b5
10 changed files with 128 additions and 20 deletions

View File

@@ -421,11 +421,19 @@ public interface ComponentFlow {
context = node.data.getOperation().apply(context);
if (node.data.next != null) {
Optional<String> n = node.data.next.apply(context);
if (n.isPresent()) {
if (n == null) {
// actual function returned null optional which is case
// when no next function was set. this is different
// than when null is returned for next.
node = node.next;
}
else if (n.isPresent()) {
// user returned value
node = oiol.get(n.get());
}
else {
node = node.next;
// user returned null
node = null;
}
}
else {
@@ -474,7 +482,7 @@ public interface ComponentFlow {
Function<StringInputContext, String> f1 = input.getNext();
Function<ComponentContext<?>, Optional<String>> f2 = context -> f1 != null
? Optional.ofNullable(f1.apply(selector.getThisContext(context)))
: Optional.empty();
: null;
return OrderedInputOperation.of(input.getId(), input.getOrder(), operation, f2);
});
}
@@ -512,7 +520,7 @@ public interface ComponentFlow {
Function<PathInputContext, String> f1 = input.getNext();
Function<ComponentContext<?>, Optional<String>> f2 = context -> f1 != null
? Optional.ofNullable(f1.apply(selector.getThisContext(context)))
: Optional.empty();
: null;
return OrderedInputOperation.of(input.getId(), input.getOrder(), operation, f2);
});
}
@@ -550,7 +558,7 @@ public interface ComponentFlow {
Function<ConfirmationInputContext, String> f1 = input.getNext();
Function<ComponentContext<?>, Optional<String>> f2 = context -> f1 != null
? Optional.ofNullable(f1.apply(selector.getThisContext(context)))
: Optional.empty();
: null;
return OrderedInputOperation.of(input.getId(), input.getOrder(), operation, f2);
});
}
@@ -609,7 +617,7 @@ public interface ComponentFlow {
Function<SingleItemSelectorContext<String, SelectorItem<String>>, String> f1 = input.getNext();
Function<ComponentContext<?>, Optional<String>> f2 = context -> f1 != null
? Optional.ofNullable(f1.apply(selector.getThisContext(context)))
: Optional.empty();
: null;
return OrderedInputOperation.of(input.getId(), input.getOrder(), operation, f2);
});
}
@@ -654,7 +662,7 @@ public interface ComponentFlow {
Function<MultiItemSelectorContext<String, SelectorItem<String>>, String> f1 = input.getNext();
Function<ComponentContext<?>, Optional<String>> f2 = context -> f1 != null
? Optional.ofNullable(f1.apply(selector.getThisContext(context)))
: Optional.empty();
: null;
return OrderedInputOperation.of(input.getId(), input.getOrder(), operation, f2);
});
}

View File

@@ -105,7 +105,8 @@ public interface ConfirmationInputSpec extends BaseInputSpec<ConfirmationInputSp
ConfirmationInputSpec storeResult(boolean store);
/**
* Define a function which may return id of a next component to go.
* Define a function which may return id of a next component to go. Returning a
* {@code null} or non existent id indicates that flow should stop.
*
* @param next next component function
* @return a builder

View File

@@ -124,7 +124,8 @@ public interface MultiItemSelectorSpec extends BaseInputSpec<MultiItemSelectorSp
MultiItemSelectorSpec storeResult(boolean store);
/**
* Define a function which may return id of a next component to go.
* Define a function which may return id of a next component to go. Returning a
* {@code null} or non existent id indicates that flow should stop.
*
* @param next next component function
* @return a builder

View File

@@ -107,7 +107,8 @@ public interface PathInputSpec extends BaseInputSpec<PathInputSpec> {
PathInputSpec storeResult(boolean store);
/**
* Define a function which may return id of a next component to go.
* Define a function which may return id of a next component to go. Returning a
* {@code null} or non existent id indicates that flow should stop.
*
* @param next next component function
* @return a builder

View File

@@ -142,7 +142,8 @@ public interface SingleItemSelectorSpec extends BaseInputSpec<SingleItemSelector
SingleItemSelectorSpec storeResult(boolean store);
/**
* Define a function which may return id of a next component to go.
* Define a function which may return id of a next component to go. Returning a
* {@code null} or non existent id indicates that flow should stop.
*
* @param next next component function
* @return a builder

View File

@@ -114,7 +114,8 @@ public interface StringInputSpec extends BaseInputSpec<StringInputSpec> {
StringInputSpec storeResult(boolean store);
/**
* Define a function which may return id of a next component to go.
* Define a function which may return id of a next component to go. Returning a
* {@code null} or non existent id indicates that flow should stop.
*
* @param next next component function
* @return a builder