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