From 5ac8c58b9d6941691711dc8f437f144ddb0ff8c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ognjen=20Kati=C4=87?= <44910579+ognjenkatic@users.noreply.github.com> Date: Mon, 1 Aug 2022 13:08:05 +0200 Subject: [PATCH 1/4] add subworkflow in decision builder --- .../Builders/DecisionTaskBuilder.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ConductorSharp.Engine/Builders/DecisionTaskBuilder.cs b/src/ConductorSharp.Engine/Builders/DecisionTaskBuilder.cs index e316cd18..55284d46 100644 --- a/src/ConductorSharp.Engine/Builders/DecisionTaskBuilder.cs +++ b/src/ConductorSharp.Engine/Builders/DecisionTaskBuilder.cs @@ -28,6 +28,17 @@ public DecisionTaskBuilder AddCase(string caseName) return this; } + public DecisionTaskBuilder WithTask( + Expression>> referrence, + Expression> input + ) where F : IRequest + { + var builder = new SubWorkflowTaskBuilder(referrence.Body, input.Body); + _caseDictionary[_currentCaseName].Add(builder); + + return this; + } + public DecisionTaskBuilder WithTask( Expression>> taskSelector, Expression> expression, From fe1b9ebf9e0a46aab4658caac007f7c161b59523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ognjen=20Kati=C4=87?= <44910579+ognjenkatic@users.noreply.github.com> Date: Mon, 8 Aug 2022 21:49:20 +0200 Subject: [PATCH 2/4] add tests --- .../ConductorSharp.Engine.Tests.csproj | 5 + .../Integration/WorkflowBuilderTests.cs | 11 +++ ...itionallySendCustomerNotificationOutput.cs | 52 ++++++++++ ...ionallySendCustomerNotificationOutput.json | 98 +++++++++++++++++++ 4 files changed, 166 insertions(+) create mode 100644 test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.cs create mode 100644 test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.json diff --git a/test/ConductorSharp.Engine.Tests/ConductorSharp.Engine.Tests.csproj b/test/ConductorSharp.Engine.Tests/ConductorSharp.Engine.Tests.csproj index d5811d3b..ac1f85eb 100644 --- a/test/ConductorSharp.Engine.Tests/ConductorSharp.Engine.Tests.csproj +++ b/test/ConductorSharp.Engine.Tests/ConductorSharp.Engine.Tests.csproj @@ -10,6 +10,7 @@ + @@ -41,4 +42,8 @@ + + + + diff --git a/test/ConductorSharp.Engine.Tests/Integration/WorkflowBuilderTests.cs b/test/ConductorSharp.Engine.Tests/Integration/WorkflowBuilderTests.cs index 0b704f4c..4b7386a9 100644 --- a/test/ConductorSharp.Engine.Tests/Integration/WorkflowBuilderTests.cs +++ b/test/ConductorSharp.Engine.Tests/Integration/WorkflowBuilderTests.cs @@ -49,5 +49,16 @@ public void BuilderReturnsCorrectDefinitionArrayTask() Assert.Equal(expectedDefinition, definition); } + + [Fact] + public void BuilderReturnsCorrectDefinitionSubworkflowInDecision() + { + var definition = SerializationUtil.SerializeObject(new ConditionallySendCustomerNotification().GetDefinition()); + var expectedDefinition = EmbeddedFileHelper.GetLinesFromEmbeddedFile( + "~/Samples/Workflows/ConditionallySendCustomerNotificationOutput.json" + ); + + Assert.Equal(expectedDefinition, definition); + } } } diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.cs new file mode 100644 index 00000000..0b135ce0 --- /dev/null +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConductorSharp.Engine.Tests.Samples.Workflows +{ + #region models + public class SendNotificationInput : IRequest + { + public dynamic CustomerId { get; set; } + } + + public class SendNotificationOutput { } + + [OriginalName("NOTIFICATION_send_to_customer")] + public class SendCustomerNotificationV1 : SubWorkflowTaskModel { } + + public class ConditionallySendCustomerNotificationInput : WorkflowInput + { + public dynamic ShouldSendNotification { get; set; } + public dynamic CustomerId { get; set; } + } + + public class ConditionallySendCustomerNotificationOutput : WorkflowOutput { } + #endregion + [OriginalName("NOTIFICATION_conditionally_send_to_customer")] + public class ConditionallySendCustomerNotification + : Workflow + { + public DecisionTaskModel SendNotificationDecision { get; set; } + public SendCustomerNotificationV1 SendNotificationSubworkflow { get; set; } + + public override WorkflowDefinition GetDefinition() + { + var builder = new WorkflowDefinitionBuilder(); + + builder.AddTask( + a => a.SendNotificationDecision, + a => new() { CaseValueParam = a.WorkflowInput.ShouldSendNotification }, + ( + "YES", + decisionBuilder => + decisionBuilder.WithTask(c => c.SendNotificationSubworkflow, wf => new() { CustomerId = wf.WorkflowInput.CustomerId }) + ) + ); + + return builder.Build(opts => opts.Version = 1); + } + } +} diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.json b/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.json new file mode 100644 index 00000000..0724c90b --- /dev/null +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.json @@ -0,0 +1,98 @@ +{ + "ownerApp": null, + "createTime": 0, + "updateTime": 0, + "createdBy": null, + "updatedBy": null, + "name": "NOTIFICATION_conditionally_send_to_customer", + "description": "{\"description\":null,\"labels\":null}", + "version": 1, + "tasks": [ + { + "queryExpression": null, + "name": "DECISION_send_notification_decision", + "taskReferenceName": "send_notification_decision", + "description": null, + "inputParameters": { + "case_value_param": "${workflow.input.should_send_notification}" + }, + "type": "DECISION", + "dynamicTaskNameParam": null, + "caseValueParam": "case_value_param", + "caseExpression": null, + "expression": null, + "evaluatorType": null, + "scriptExpression": null, + "decisionCases": { + "YES": [ + { + "queryExpression": null, + "name": "NOTIFICATION_send_to_customer", + "taskReferenceName": "send_notification_subworkflow", + "description": "{\"description\":null}", + "inputParameters": { + "customer_id": "${workflow.input.customer_id}" + }, + "type": "SUB_WORKFLOW", + "dynamicTaskNameParam": null, + "caseValueParam": null, + "caseExpression": null, + "expression": null, + "evaluatorType": null, + "scriptExpression": null, + "decisionCases": null, + "dynamicForkJoinTasksParam": null, + "dynamicForkTasksParam": null, + "dynamicForkTasksInputParamName": null, + "defaultCase": null, + "forkTasks": null, + "startDelay": 0, + "subWorkflowParam": { + "name": "NOTIFICATION_send_to_customer", + "version": 1, + "taskToDomain": null, + "workflowDefinition": null + }, + "joinOn": null, + "sink": null, + "optional": false, + "taskDefinition": null, + "rateLimited": false, + "defaultExclusiveJoinTask": null, + "asyncComplete": false, + "loopCondition": null, + "loopOver": null + } + ] + }, + "dynamicForkJoinTasksParam": null, + "dynamicForkTasksParam": null, + "dynamicForkTasksInputParamName": null, + "defaultCase": null, + "forkTasks": null, + "startDelay": 0, + "subWorkflowParam": null, + "joinOn": null, + "sink": null, + "optional": false, + "taskDefinition": null, + "rateLimited": false, + "defaultExclusiveJoinTask": null, + "asyncComplete": false, + "loopCondition": null, + "loopOver": null + } + ], + "inputParameters": [ + "{\"should_send_notification\":{\"value\":\"\",\"description\":\" (optional)\"},\"customer_id\":{\"value\":\"\",\"description\":\" (optional)\"}}" + ], + "outputParameters": null, + "failureWorkflow": null, + "schemaVersion": 2, + "restartable": true, + "workflowStatusListenerEnabled": true, + "ownerEmail": null, + "timeoutPolicy": null, + "timeoutSeconds": 0, + "variables": null +} \ No newline at end of file From 70376ddf02c48269c02426392f903fdec7531fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ognjen=20Kati=C4=87?= <44910579+ognjenkatic@users.noreply.github.com> Date: Mon, 8 Aug 2022 21:54:26 +0200 Subject: [PATCH 3/4] move models to belonging workflows --- ...itionallySendCustomerNotificationOutput.cs | 72 +++++++------------ .../Workflows/SendCustomerNotification.cs | 13 +++- 2 files changed, 39 insertions(+), 46 deletions(-) diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.cs index 0b135ce0..b1bd2824 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.cs @@ -1,52 +1,34 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +namespace ConductorSharp.Engine.Tests.Samples.Workflows; -namespace ConductorSharp.Engine.Tests.Samples.Workflows +#region models +public class ConditionallySendCustomerNotificationInput : WorkflowInput { - #region models - public class SendNotificationInput : IRequest - { - public dynamic CustomerId { get; set; } - } - - public class SendNotificationOutput { } - - [OriginalName("NOTIFICATION_send_to_customer")] - public class SendCustomerNotificationV1 : SubWorkflowTaskModel { } + public dynamic ShouldSendNotification { get; set; } + public dynamic CustomerId { get; set; } +} - public class ConditionallySendCustomerNotificationInput : WorkflowInput - { - public dynamic ShouldSendNotification { get; set; } - public dynamic CustomerId { get; set; } - } +public class ConditionallySendCustomerNotificationOutput : WorkflowOutput { } +#endregion +[OriginalName("NOTIFICATION_conditionally_send_to_customer")] +public class ConditionallySendCustomerNotification : Workflow +{ + public DecisionTaskModel SendNotificationDecision { get; set; } + public SendCustomerNotificationV1 SendNotificationSubworkflow { get; set; } - public class ConditionallySendCustomerNotificationOutput : WorkflowOutput { } - #endregion - [OriginalName("NOTIFICATION_conditionally_send_to_customer")] - public class ConditionallySendCustomerNotification - : Workflow + public override WorkflowDefinition GetDefinition() { - public DecisionTaskModel SendNotificationDecision { get; set; } - public SendCustomerNotificationV1 SendNotificationSubworkflow { get; set; } - - public override WorkflowDefinition GetDefinition() - { - var builder = new WorkflowDefinitionBuilder(); - - builder.AddTask( - a => a.SendNotificationDecision, - a => new() { CaseValueParam = a.WorkflowInput.ShouldSendNotification }, - ( - "YES", - decisionBuilder => - decisionBuilder.WithTask(c => c.SendNotificationSubworkflow, wf => new() { CustomerId = wf.WorkflowInput.CustomerId }) - ) - ); - - return builder.Build(opts => opts.Version = 1); - } + var builder = new WorkflowDefinitionBuilder(); + + builder.AddTask( + a => a.SendNotificationDecision, + a => new() { CaseValueParam = a.WorkflowInput.ShouldSendNotification }, + ( + "YES", + decisionBuilder => + decisionBuilder.WithTask(c => c.SendNotificationSubworkflow, wf => new() { CustomerId = wf.WorkflowInput.CustomerId }) + ) + ); + + return builder.Build(opts => opts.Version = 1); } } diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/SendCustomerNotification.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/SendCustomerNotification.cs index 21895d79..90e16f9a 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workflows/SendCustomerNotification.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/SendCustomerNotification.cs @@ -1,5 +1,16 @@ namespace ConductorSharp.Engine.Tests.Samples.Workflows; +#region models +public class SendNotificationInput : IRequest +{ + public dynamic CustomerId { get; set; } +} + +public class SendNotificationOutput { } + +[OriginalName("NOTIFICATION_send_to_customer")] +public class SendCustomerNotificationV1 : SubWorkflowTaskModel { } + public class SendCustomerNotificationInput : WorkflowInput { public dynamic CustomerId { get; set; } @@ -9,7 +20,7 @@ public class SendCustomerNotificationOutput : WorkflowOutput { public dynamic EmailBody { get; set; } } - +#endregion [OriginalName("NOTIFICATION_send_to_customer")] public class SendCustomerNotification : Workflow { From def9459572b37905dff8fec6ff6b68c3bdae758d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ognjen=20Kati=C4=87?= <44910579+ognjenkatic@users.noreply.github.com> Date: Mon, 8 Aug 2022 21:56:26 +0200 Subject: [PATCH 4/4] rename vars --- .../ConditionallySendCustomerNotificationOutput.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.cs index b1bd2824..b798be44 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.cs @@ -20,13 +20,9 @@ public override WorkflowDefinition GetDefinition() var builder = new WorkflowDefinitionBuilder(); builder.AddTask( - a => a.SendNotificationDecision, - a => new() { CaseValueParam = a.WorkflowInput.ShouldSendNotification }, - ( - "YES", - decisionBuilder => - decisionBuilder.WithTask(c => c.SendNotificationSubworkflow, wf => new() { CustomerId = wf.WorkflowInput.CustomerId }) - ) + wf => wf.SendNotificationDecision, + wf => new() { CaseValueParam = wf.WorkflowInput.ShouldSendNotification }, + ("YES", builder => builder.WithTask(c => c.SendNotificationSubworkflow, wf => new() { CustomerId = wf.WorkflowInput.CustomerId })) ); return builder.Build(opts => opts.Version = 1);