Skip to content

Commit a1a55b4

Browse files
authored
[Fix #1596] Update to latest schema (#1597)
Revert "[Fix #1596] Update to latest schema" This reverts commit 0982f1d. [Fix 1596] Schema updates Signed-off-by: Francisco Javier Tirado Sarti <ftirados@ibm.com>
1 parent e165418 commit a1a55b4

11 files changed

Lines changed: 198 additions & 39 deletions

File tree

‎api/src/main/java/io/serverlessworkflow/api/ValidationReader.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package io.serverlessworkflow.api;
1717

18+
import com.fasterxml.jackson.core.exc.StreamReadException;
19+
import com.fasterxml.jackson.databind.DatabindException;
1820
import com.fasterxml.jackson.databind.JsonNode;
1921
import com.networknt.schema.Error;
2022
import com.networknt.schema.InputFormat;
@@ -65,12 +67,13 @@ public Workflow read(String input, WorkflowFormat format) throws IOException {
6567
return validate(format.mapper().readValue(input, JsonNode.class), format);
6668
}
6769

68-
private Workflow validate(JsonNode value, WorkflowFormat format) {
70+
private Workflow validate(JsonNode value, WorkflowFormat format)
71+
throws StreamReadException, DatabindException, IOException {
6972
Collection<Error> validationErrors = schemaObject.validate(value);
7073
if (!validationErrors.isEmpty()) {
7174
throw new IllegalArgumentException(
7275
validationErrors.stream().map(Error::toString).collect(Collectors.joining("\n")));
7376
}
74-
return format.mapper().convertValue(value, Workflow.class);
77+
return format.mapper().treeToValue(value, Workflow.class);
7578
}
7679
}

‎api/src/main/java/io/serverlessworkflow/api/WorkflowReader.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ private static class ValidationHolder {
216216
}
217217

218218
/**
219-
* Returns the default {@link WorkflowReaderOperations} instance (no validation).
219+
* Returns the default {@link WorkflowReaderOperations} instance
220220
*
221221
* @return the default reader
222222
*/
223223
private static WorkflowReaderOperations defaultReader() {
224-
return NoValidationHolder.instance;
224+
return ValidationHolder.instance;
225225
}
226226

227227
private WorkflowReader() {}

‎fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/BaseTryTaskBuilder.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public CatchErrorsBuilder title(final String title) {
178178
}
179179

180180
public CatchErrorsBuilder details(final String details) {
181-
this.errorFilter.setDetails(details);
181+
this.errorFilter.setDetail(details);
182182
return this;
183183
}
184184

‎fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/ForEachTaskBuilder.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import io.serverlessworkflow.api.types.ForTask;
1919
import io.serverlessworkflow.api.types.ForTaskConfiguration;
20+
import io.serverlessworkflow.api.types.In;
2021
import io.serverlessworkflow.api.types.TaskItem;
2122
import io.serverlessworkflow.fluent.spec.spi.ForEachTaskFluent;
2223
import java.util.List;
@@ -48,7 +49,7 @@ public ForEachTaskBuilder<T> each(String each) {
4849
}
4950

5051
public ForEachTaskBuilder<T> in(String in) {
51-
this.forTaskConfiguration.setIn(in);
52+
this.forTaskConfiguration.setIn(new In().withForInExpression(in));
5253
return this;
5354
}
5455

‎fluent/spec/src/test/java/io/serverlessworkflow/fluent/spec/dsl/TryCatchDslTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ void when_try_catch_match_details() {
329329
assertThat(tryTask).isNotNull();
330330
var cat = tryTask.getCatch();
331331
assertThat(cat).isNotNull();
332-
assertThat(cat.getErrors().getWith().getDetails())
332+
assertThat(cat.getErrors().getWith().getDetail())
333333
.isEqualTo("Enforcement Failure - invalid email");
334334
}
335335

‎impl/core/src/main/java/io/serverlessworkflow/impl/executors/ForExecutor.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package io.serverlessworkflow.impl.executors;
1717

1818
import io.serverlessworkflow.api.types.ForTask;
19+
import io.serverlessworkflow.api.types.In;
1920
import io.serverlessworkflow.impl.TaskContext;
2021
import io.serverlessworkflow.impl.WorkflowContext;
2122
import io.serverlessworkflow.impl.WorkflowDefinition;
@@ -50,9 +51,11 @@ protected Optional<WorkflowPredicate> buildWhileFilter() {
5051
}
5152

5253
protected WorkflowValueResolver<Collection<?>> buildCollectionFilter() {
54+
In in = task.getFor().getIn();
5355
return application
5456
.expressionFactory()
55-
.resolveCollection(ExpressionDescriptor.from(task.getFor().getIn()));
57+
.resolveCollection(
58+
new ExpressionDescriptor(in.getForInExpression(), in.getForInInlineArray()));
5659
}
5760

5861
@Override

‎impl/core/src/main/java/io/serverlessworkflow/impl/executors/TryExecutor.java‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private CompletableFuture<WorkflowModel> handleException(
187187
taskContext,
188188
workflow.definition().application().modelFactory().fromAny(error))) {
189189
if (errorVariable != null) {
190-
taskContext.variables().put(errorVariable, WorkflowErrorExpr.from(error));
190+
taskContext.variables().put(errorVariable, error);
191191
}
192192
if (catchTaskExecutor.isPresent()) {
193193
completable =
@@ -213,14 +213,6 @@ private CompletableFuture<WorkflowModel> handleException(
213213
return CompletableFuture.failedFuture(e);
214214
}
215215

216-
private static record WorkflowErrorExpr(
217-
String type, int status, String instance, String title, String details) {
218-
static WorkflowErrorExpr from(WorkflowError error) {
219-
return new WorkflowErrorExpr(
220-
error.type(), error.status(), error.instance(), error.title(), error.detail());
221-
}
222-
}
223-
224216
private static Optional<Predicate<WorkflowError>> buildErrorFilter(CatchErrors errors) {
225217
return errors != null
226218
? Optional.of(error -> filterError(error, errors.getWith()))
@@ -232,7 +224,7 @@ private static boolean filterError(WorkflowError error, ErrorFilter errorFilter)
232224
&& (errorFilter.getStatus() <= 0 || error.status() == errorFilter.getStatus())
233225
&& compareString(errorFilter.getInstance(), error.instance())
234226
&& compareString(errorFilter.getTitle(), error.title())
235-
&& compareString(errorFilter.getDetails(), error.detail());
227+
&& compareString(errorFilter.getDetail(), error.detail());
236228
}
237229

238230
private static boolean compareString(String one, String other) {

‎impl/test/src/test/resources/workflows-samples/try-catch-error-variable.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ do:
1717
do:
1818
- handleError:
1919
set:
20-
errorMessage: ${$caughtError.details}
20+
errorMessage: ${$caughtError.detail}

‎impl/test/src/test/resources/workflows-samples/try-catch-match-details.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ do:
1717
with:
1818
type: https://example.com/errors/transient
1919
status: 503
20-
details: Enforcement Failure - invalid email
20+
detail: Enforcement Failure - invalid email
2121
do:
2222
- handleError:
2323
set:

‎impl/test/src/test/resources/workflows-samples/try-catch-not-match-details.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ do:
1717
with:
1818
type: https://example.com/errors/security
1919
status: 403
20-
details: User not found in tenant catalog
20+
detail: User not found in tenant catalog

0 commit comments

Comments
 (0)