|
38 | 38 | import io.serverlessworkflow.fluent.spec.EventFilterBuilder; |
39 | 39 | import io.serverlessworkflow.fluent.spec.ScheduleBuilder; |
40 | 40 | import io.serverlessworkflow.fluent.spec.TimeoutBuilder; |
| 41 | +import io.serverlessworkflow.fluent.spec.WorkflowTaskBuilder; |
41 | 42 | import io.serverlessworkflow.fluent.spec.configurers.AuthenticationConfigurer; |
42 | 43 | import io.serverlessworkflow.fluent.spec.configurers.WorkflowConfigurer; |
43 | 44 | import io.serverlessworkflow.fluent.spec.dsl.DSL; |
44 | 45 | import io.serverlessworkflow.fluent.spec.dsl.UseSpec; |
| 46 | +import io.serverlessworkflow.fluent.spec.dsl.WorkflowSpec; |
45 | 47 | import io.serverlessworkflow.impl.TaskContextData; |
46 | 48 | import io.serverlessworkflow.impl.WorkflowContextData; |
47 | 49 | import java.net.URI; |
@@ -928,14 +930,19 @@ public static FuncTaskConfigurer switchWhen(String jqExpression, String thenTask |
928 | 930 | * @return list configurer |
929 | 931 | */ |
930 | 932 | public static <T> FuncTaskConfigurer switchWhenOrElse( |
931 | | - Predicate<T> pred, String thenTask, FlowDirectiveEnum otherwise, Class<T> predClass) { |
| 933 | + Predicate<T> pred, |
| 934 | + String thenTask, |
| 935 | + io.serverlessworkflow.api.types.FlowDirectiveEnum otherwise, |
| 936 | + Class<T> predClass) { |
932 | 937 | return list -> |
933 | 938 | list.switchCase( |
934 | 939 | FuncDSL.cases(caseOf(pred, predClass).then(thenTask), caseDefault(otherwise))); |
935 | 940 | } |
936 | 941 |
|
937 | 942 | public static <T> FuncTaskConfigurer switchWhenOrElse( |
938 | | - SerializablePredicate<T> pred, String thenTask, FlowDirectiveEnum otherwise) { |
| 943 | + SerializablePredicate<T> pred, |
| 944 | + String thenTask, |
| 945 | + io.serverlessworkflow.api.types.FlowDirectiveEnum otherwise) { |
939 | 946 | return switchWhenOrElse(pred, thenTask, otherwise, ReflectionUtils.inferInputType(pred)); |
940 | 947 | } |
941 | 948 |
|
@@ -976,7 +983,9 @@ public static <T> FuncTaskConfigurer switchWhenOrElse( |
976 | 983 | * @return list configurer |
977 | 984 | */ |
978 | 985 | public static FuncTaskConfigurer switchWhenOrElse( |
979 | | - String jqExpression, String thenTask, FlowDirectiveEnum otherwise) { |
| 986 | + String jqExpression, |
| 987 | + String thenTask, |
| 988 | + io.serverlessworkflow.api.types.FlowDirectiveEnum otherwise) { |
980 | 989 |
|
981 | 990 | Objects.requireNonNull(jqExpression, "jqExpression"); |
982 | 991 | Objects.requireNonNull(thenTask, "thenTask"); |
@@ -1079,22 +1088,103 @@ public static FuncTaskConfigurer set(Map<String, Object> map) { |
1079 | 1088 | * @param configurer configurer for the nested workflow task |
1080 | 1089 | * @return a {@link FuncTaskConfigurer} that adds a workflow task to the tasks list |
1081 | 1090 | */ |
1082 | | - public static FuncTaskConfigurer workflowTask(WorkflowConfigurer configurer) { |
| 1091 | + /** |
| 1092 | + * Create a {@link FuncTaskConfigurer} that adds a sub-workflow call task using a {@link |
| 1093 | + * WorkflowConfigurer}. |
| 1094 | + * |
| 1095 | + * <p> |
| 1096 | + * |
| 1097 | + * <pre>{@code |
| 1098 | + * tasks( |
| 1099 | + * subflow(workflow("org.acme", "sub-workflow", "0.1.0").input(...) |
| 1100 | + * ); |
| 1101 | + * }</pre> |
| 1102 | + * |
| 1103 | + * @param configurer nested workflow configurer |
| 1104 | + * @return a {@link FuncTaskConfigurer} that adds a workflow task to the tasks list |
| 1105 | + */ |
| 1106 | + public static FuncTaskConfigurer subflow(WorkflowConfigurer configurer) { |
| 1107 | + Objects.requireNonNull(configurer, "configurer"); |
| 1108 | + return list -> list.subflow(configurer); |
| 1109 | + } |
| 1110 | + |
| 1111 | + /** |
| 1112 | + * Create a {@link FuncTaskConfigurer} that adds a named sub-workflow call task. |
| 1113 | + * |
| 1114 | + * @param name task name |
| 1115 | + * @param configurer nested workflow configurer |
| 1116 | + * @return a {@link FuncTaskConfigurer} that adds a workflow task to the tasks list |
| 1117 | + */ |
| 1118 | + public static FuncTaskConfigurer subflow(String name, Consumer<WorkflowTaskBuilder> configurer) { |
| 1119 | + Objects.requireNonNull(name, "name"); |
| 1120 | + Objects.requireNonNull(configurer, "configurer"); |
| 1121 | + return list -> list.subflow(name, configurer); |
| 1122 | + } |
| 1123 | + |
| 1124 | + /** |
| 1125 | + * Create a {@link FuncTaskConfigurer} that adds an unnamed sub-workflow call task. |
| 1126 | + * |
| 1127 | + * @param configurer nested workflow configurer |
| 1128 | + * @return a {@link FuncTaskConfigurer} that adds a workflow task to the tasks list |
| 1129 | + */ |
| 1130 | + public static FuncTaskConfigurer subflow(Consumer<WorkflowTaskBuilder> configurer) { |
1083 | 1131 | Objects.requireNonNull(configurer, "configurer"); |
1084 | | - return list -> list.workflow(configurer); |
| 1132 | + return list -> list.subflow(configurer); |
| 1133 | + } |
| 1134 | + |
| 1135 | + /** |
| 1136 | + * Alias for {@link #subflow(WorkflowConfigurer)}. |
| 1137 | + * |
| 1138 | + * @param configurer nested workflow configurer |
| 1139 | + * @return a {@link FuncTaskConfigurer} that adds a workflow task to the tasks list |
| 1140 | + */ |
| 1141 | + public static FuncTaskConfigurer workflowTask(WorkflowConfigurer configurer) { |
| 1142 | + return subflow(configurer); |
1085 | 1143 | } |
1086 | 1144 |
|
1087 | 1145 | /** |
1088 | 1146 | * Create a {@link FuncTaskConfigurer} that adds a workflow subflow task. |
1089 | 1147 | * |
1090 | 1148 | * @param configurer configurer for the nested workflow task |
1091 | 1149 | * @return a {@link FuncTaskConfigurer} that adds a workflow task to the tasks list |
1092 | | - * @deprecated use {@link #workflowTask(WorkflowConfigurer)} to avoid ambiguity with spec-side |
1093 | | - * workflow factory methods |
| 1150 | + * @deprecated use {@link #subflow(WorkflowConfigurer)} to avoid ambiguity with spec-side factory |
| 1151 | + * methods |
1094 | 1152 | */ |
1095 | 1153 | @Deprecated |
1096 | 1154 | public static FuncTaskConfigurer workflow(WorkflowConfigurer configurer) { |
1097 | | - return workflowTask(configurer); |
| 1155 | + return subflow(configurer); |
| 1156 | + } |
| 1157 | + |
| 1158 | + /** |
| 1159 | + * Create a new {@link WorkflowSpec} to be used as a factory for workflow definitions. |
| 1160 | + * |
| 1161 | + * @param namespace workflow namespace |
| 1162 | + * @param name workflow name |
| 1163 | + * @param version workflow version |
| 1164 | + * @return a new {@link WorkflowSpec} instance |
| 1165 | + */ |
| 1166 | + public static WorkflowSpec workflow(String namespace, String name, String version) { |
| 1167 | + return DSL.workflow(namespace, name, version); |
| 1168 | + } |
| 1169 | + |
| 1170 | + /** |
| 1171 | + * Create a new {@link WorkflowSpec} to be used as a factory for workflow definitions. |
| 1172 | + * |
| 1173 | + * @param namespace workflow namespace |
| 1174 | + * @param name workflow name |
| 1175 | + * @return a new {@link WorkflowSpec} instance |
| 1176 | + */ |
| 1177 | + public static WorkflowSpec workflow(String namespace, String name) { |
| 1178 | + return DSL.workflow(namespace, name); |
| 1179 | + } |
| 1180 | + |
| 1181 | + /** |
| 1182 | + * Create a new {@link WorkflowSpec} to be used as a factory for workflow definitions. |
| 1183 | + * |
| 1184 | + * @return a new {@link WorkflowSpec} instance |
| 1185 | + */ |
| 1186 | + public static WorkflowSpec workflow() { |
| 1187 | + return DSL.workflow(); |
1098 | 1188 | } |
1099 | 1189 |
|
1100 | 1190 | // --------------------------------------------------------------------------- |
|
0 commit comments