-
Notifications
You must be signed in to change notification settings - Fork 49
[Fix #863] Adding WorkflowContext and TaskContext as additional params #864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
import io.serverlessworkflow.api.types.Workflow; | ||
import io.serverlessworkflow.api.types.func.OutputAsFunction; | ||
import io.serverlessworkflow.impl.WorkflowApplication; | ||
import io.serverlessworkflow.impl.WorkflowInstance; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ExecutionException; | ||
|
@@ -173,4 +174,62 @@ void testPOJOStringExpression() throws InterruptedException, ExecutionException | |
.isEqualTo("Francisco Javierito"); | ||
} | ||
} | ||
|
||
@Test | ||
void testPOJOStringExpressionWithContext() throws InterruptedException, ExecutionException { | ||
try (WorkflowApplication app = WorkflowApplication.builder().build()) { | ||
Workflow workflow = | ||
new Workflow() | ||
.withDocument( | ||
new Document().withNamespace("test").withName("testPojo").withVersion("1.0")) | ||
.withDo( | ||
List.of( | ||
new TaskItem( | ||
"doNothing", | ||
new Task() | ||
.withWaitTask( | ||
new WaitTask() | ||
.withWait( | ||
new TimeoutAfter() | ||
.withDurationInline( | ||
new DurationInline().withMilliseconds(10))))))) | ||
.withOutput( | ||
new Output() | ||
.withAs(new OutputAsFunction().withFunction(JavaFunctions::getContextName))); | ||
WorkflowInstance instance = | ||
app.workflowDefinition(workflow).instance(new Person("Francisco", 33)); | ||
assertThat(instance.start().get().asText().orElseThrow()) | ||
.isEqualTo("Francisco_" + instance.id()); | ||
} | ||
} | ||
|
||
@Test | ||
void testPOJOStringExpressionWithFilter() throws InterruptedException, ExecutionException { | ||
try (WorkflowApplication app = WorkflowApplication.builder().build()) { | ||
Workflow workflow = | ||
new Workflow() | ||
.withDocument( | ||
new Document().withNamespace("test").withName("testPojo").withVersion("1.0")) | ||
.withDo( | ||
List.of( | ||
new TaskItem( | ||
"doNothing", | ||
new Task() | ||
.withWaitTask( | ||
new WaitTask() | ||
.withOutput( | ||
new Output() | ||
.withAs( | ||
new OutputAsFunction() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Output associated to the task, we call three parameter function without issue |
||
.withFunction(JavaFunctions::getFilterName))) | ||
.withWait( | ||
new TimeoutAfter() | ||
.withDurationInline( | ||
new DurationInline().withMilliseconds(10))))))); | ||
WorkflowInstance instance = | ||
app.workflowDefinition(workflow).instance(new Person("Francisco", 33)); | ||
assertThat(instance.start().get().asText().orElseThrow()) | ||
.isEqualTo("Francisco_" + instance.id() + "_doNothing"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,24 @@ public <T, V> ExportAs withFunction(Function<T, V> value, Class<T> argClass) { | |
setObject(new TypedFunction<>(value, argClass)); | ||
return this; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Export also existed ;) |
||
public <T, V> ExportAs withFunction(JavaFilterFunction<T, V> value) { | ||
setObject(value); | ||
return this; | ||
} | ||
|
||
public <T, V> ExportAs withFunction(JavaFilterFunction<T, V> value, Class<T> argClass) { | ||
setObject(new TypedJavaFilterFunction<>(value, argClass)); | ||
return this; | ||
} | ||
|
||
public <T, V> ExportAs withFunction(JavaContextFunction<T, V> value) { | ||
setObject(value); | ||
return this; | ||
} | ||
|
||
public <T, V> ExportAs withFunction(JavaContextFunction<T, V> value, Class<T> argClass) { | ||
setObject(new TypedJavaContextFunction<>(value, argClass)); | ||
return this; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2020-Present The Serverless Workflow Specification Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.serverlessworkflow.api.types.func; | ||
|
||
import io.serverlessworkflow.impl.WorkflowContextData; | ||
|
||
@FunctionalInterface | ||
public interface JavaContextFunction<T, R> { | ||
R apply(T object, WorkflowContextData workflowContext); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2020-Present The Serverless Workflow Specification Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.serverlessworkflow.api.types.func; | ||
|
||
import io.serverlessworkflow.impl.TaskContextData; | ||
import io.serverlessworkflow.impl.WorkflowContextData; | ||
|
||
@FunctionalInterface | ||
public interface JavaFilterFunction<T, R> { | ||
R apply(T object, WorkflowContextData workflowContext, TaskContextData taskContext); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2020-Present The Serverless Workflow Specification Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.serverlessworkflow.api.types.func; | ||
|
||
public record TypedJavaContextFunction<T, V>( | ||
JavaContextFunction<T, V> function, Class<T> argClass) {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2020-Present The Serverless Workflow Specification Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.serverlessworkflow.api.types.func; | ||
|
||
public record TypedJavaFilterFunction<T, V>(JavaFilterFunction<T, V> function, Class<T> argClass) {} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Output associated to a workflow, we specify the two arguments function.
Important thing to know is that TaskContext will be null if the three parameter function has been specified here (we should either document that or prevent user passing the three parameter function if the input/output/export is associated to the workflow)