Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package io.serverlessworkflow.api;

import com.fasterxml.jackson.core.exc.StreamReadException;
import com.fasterxml.jackson.databind.DatabindException;
import com.fasterxml.jackson.databind.JsonNode;
import com.networknt.schema.Error;
import com.networknt.schema.InputFormat;
Expand Down Expand Up @@ -65,12 +67,13 @@ public Workflow read(String input, WorkflowFormat format) throws IOException {
return validate(format.mapper().readValue(input, JsonNode.class), format);
}

private Workflow validate(JsonNode value, WorkflowFormat format) {
private Workflow validate(JsonNode value, WorkflowFormat format)
throws StreamReadException, DatabindException, IOException {
Collection<Error> validationErrors = schemaObject.validate(value);
if (!validationErrors.isEmpty()) {
throw new IllegalArgumentException(
validationErrors.stream().map(Error::toString).collect(Collectors.joining("\n")));
}
return format.mapper().convertValue(value, Workflow.class);
return format.mapper().treeToValue(value, Workflow.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ private static class ValidationHolder {
}

/**
* Returns the default {@link WorkflowReaderOperations} instance (no validation).
* Returns the default {@link WorkflowReaderOperations} instance
*
* @return the default reader
*/
private static WorkflowReaderOperations defaultReader() {
return NoValidationHolder.instance;
return ValidationHolder.instance;
}

private WorkflowReader() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public CatchErrorsBuilder title(final String title) {
}

public CatchErrorsBuilder details(final String details) {
this.errorFilter.setDetails(details);
this.errorFilter.setDetail(details);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.serverlessworkflow.api.types.ForTask;
import io.serverlessworkflow.api.types.ForTaskConfiguration;
import io.serverlessworkflow.api.types.In;
import io.serverlessworkflow.api.types.TaskItem;
import io.serverlessworkflow.fluent.spec.spi.ForEachTaskFluent;
import java.util.List;
Expand Down Expand Up @@ -48,7 +49,7 @@ public ForEachTaskBuilder<T> each(String each) {
}

public ForEachTaskBuilder<T> in(String in) {
this.forTaskConfiguration.setIn(in);
this.forTaskConfiguration.setIn(new In().withForInExpression(in));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ void when_try_catch_match_details() {
assertThat(tryTask).isNotNull();
var cat = tryTask.getCatch();
assertThat(cat).isNotNull();
assertThat(cat.getErrors().getWith().getDetails())
assertThat(cat.getErrors().getWith().getDetail())
.isEqualTo("Enforcement Failure - invalid email");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.serverlessworkflow.impl.executors;

import io.serverlessworkflow.api.types.ForTask;
import io.serverlessworkflow.api.types.In;
import io.serverlessworkflow.impl.TaskContext;
import io.serverlessworkflow.impl.WorkflowContext;
import io.serverlessworkflow.impl.WorkflowDefinition;
Expand Down Expand Up @@ -50,9 +51,11 @@ protected Optional<WorkflowPredicate> buildWhileFilter() {
}

protected WorkflowValueResolver<Collection<?>> buildCollectionFilter() {
In in = task.getFor().getIn();
return application
.expressionFactory()
.resolveCollection(ExpressionDescriptor.from(task.getFor().getIn()));
.resolveCollection(
new ExpressionDescriptor(in.getForInExpression(), in.getForInInlineArray()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private CompletableFuture<WorkflowModel> handleException(
taskContext,
workflow.definition().application().modelFactory().fromAny(error))) {
if (errorVariable != null) {
taskContext.variables().put(errorVariable, WorkflowErrorExpr.from(error));
taskContext.variables().put(errorVariable, error);
}
Comment thread
fjtirado marked this conversation as resolved.
if (catchTaskExecutor.isPresent()) {
completable =
Expand All @@ -213,14 +213,6 @@ private CompletableFuture<WorkflowModel> handleException(
return CompletableFuture.failedFuture(e);
}

private static record WorkflowErrorExpr(
String type, int status, String instance, String title, String details) {
static WorkflowErrorExpr from(WorkflowError error) {
return new WorkflowErrorExpr(
error.type(), error.status(), error.instance(), error.title(), error.detail());
}
}

private static Optional<Predicate<WorkflowError>> buildErrorFilter(CatchErrors errors) {
return errors != null
? Optional.of(error -> filterError(error, errors.getWith()))
Expand All @@ -232,7 +224,7 @@ private static boolean filterError(WorkflowError error, ErrorFilter errorFilter)
&& (errorFilter.getStatus() <= 0 || error.status() == errorFilter.getStatus())
&& compareString(errorFilter.getInstance(), error.instance())
&& compareString(errorFilter.getTitle(), error.title())
&& compareString(errorFilter.getDetails(), error.detail());
&& compareString(errorFilter.getDetail(), error.detail());
}

private static boolean compareString(String one, String other) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ do:
do:
- handleError:
set:
errorMessage: ${$caughtError.details}
errorMessage: ${$caughtError.detail}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ do:
with:
type: https://example.com/errors/transient
status: 503
details: Enforcement Failure - invalid email
detail: Enforcement Failure - invalid email
do:
- handleError:
set:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ do:
with:
type: https://example.com/errors/security
status: 403
details: User not found in tenant catalog
detail: User not found in tenant catalog
Loading
Loading