Skip to content

Commit f10ddf4

Browse files
authored
Merge pull request #31 from codaxy/feat/master/add-subworkflow-in-decision
add subworkflow in decision builder
2 parents 05671c5 + def9459 commit f10ddf4

6 files changed

Lines changed: 167 additions & 1 deletion

File tree

src/ConductorSharp.Engine/Builders/DecisionTaskBuilder.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ public DecisionTaskBuilder<TWorkflow> AddCase(string caseName)
2828
return this;
2929
}
3030

31+
public DecisionTaskBuilder<TWorkflow> WithTask<F, G>(
32+
Expression<Func<TWorkflow, SubWorkflowTaskModel<F, G>>> referrence,
33+
Expression<Func<TWorkflow, F>> input
34+
) where F : IRequest<G>
35+
{
36+
var builder = new SubWorkflowTaskBuilder<F, G>(referrence.Body, input.Body);
37+
_caseDictionary[_currentCaseName].Add(builder);
38+
39+
return this;
40+
}
41+
3142
public DecisionTaskBuilder<TWorkflow> WithTask<F, G>(
3243
Expression<Func<TWorkflow, LambdaTaskModel<F, G>>> taskSelector,
3344
Expression<Func<TWorkflow, F>> expression,

test/ConductorSharp.Engine.Tests/ConductorSharp.Engine.Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<None Remove="Samples\Tasks\CustomerGet.json" />
1111
<None Remove="Samples\Tasks\EmailPrepare.json" />
1212
<None Remove="Samples\Workflows\Arrays.json" />
13+
<None Remove="Samples\Workflows\ConditionallySendCustomerNotificationOutput.json" />
1314
<None Remove="Samples\Workflows\NestedObjects.json" />
1415
<None Remove="Samples\Workflows\SendCustomerNotification.json" />
1516
<None Remove="Samples\Workflows\StringInterpolation.json" />
@@ -41,4 +42,8 @@
4142
<ProjectReference Include="..\..\src\ConductorSharp.Engine\ConductorSharp.Engine.csproj" />
4243
</ItemGroup>
4344

45+
<ItemGroup>
46+
<EmbeddedResource Include="Samples\Workflows\ConditionallySendCustomerNotificationOutput.json" />
47+
</ItemGroup>
48+
4449
</Project>

test/ConductorSharp.Engine.Tests/Integration/WorkflowBuilderTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,16 @@ public void BuilderReturnsCorrectDefinitionArrayTask()
4949

5050
Assert.Equal(expectedDefinition, definition);
5151
}
52+
53+
[Fact]
54+
public void BuilderReturnsCorrectDefinitionSubworkflowInDecision()
55+
{
56+
var definition = SerializationUtil.SerializeObject(new ConditionallySendCustomerNotification().GetDefinition());
57+
var expectedDefinition = EmbeddedFileHelper.GetLinesFromEmbeddedFile(
58+
"~/Samples/Workflows/ConditionallySendCustomerNotificationOutput.json"
59+
);
60+
61+
Assert.Equal(expectedDefinition, definition);
62+
}
5263
}
5364
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace ConductorSharp.Engine.Tests.Samples.Workflows;
2+
3+
#region models
4+
public class ConditionallySendCustomerNotificationInput : WorkflowInput<ConditionallySendCustomerNotificationOutput>
5+
{
6+
public dynamic ShouldSendNotification { get; set; }
7+
public dynamic CustomerId { get; set; }
8+
}
9+
10+
public class ConditionallySendCustomerNotificationOutput : WorkflowOutput { }
11+
#endregion
12+
[OriginalName("NOTIFICATION_conditionally_send_to_customer")]
13+
public class ConditionallySendCustomerNotification : Workflow<ConditionallySendCustomerNotificationInput, ConditionallySendCustomerNotificationOutput>
14+
{
15+
public DecisionTaskModel SendNotificationDecision { get; set; }
16+
public SendCustomerNotificationV1 SendNotificationSubworkflow { get; set; }
17+
18+
public override WorkflowDefinition GetDefinition()
19+
{
20+
var builder = new WorkflowDefinitionBuilder<ConditionallySendCustomerNotification>();
21+
22+
builder.AddTask(
23+
wf => wf.SendNotificationDecision,
24+
wf => new() { CaseValueParam = wf.WorkflowInput.ShouldSendNotification },
25+
("YES", builder => builder.WithTask(c => c.SendNotificationSubworkflow, wf => new() { CustomerId = wf.WorkflowInput.CustomerId }))
26+
);
27+
28+
return builder.Build(opts => opts.Version = 1);
29+
}
30+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"ownerApp": null,
3+
"createTime": 0,
4+
"updateTime": 0,
5+
"createdBy": null,
6+
"updatedBy": null,
7+
"name": "NOTIFICATION_conditionally_send_to_customer",
8+
"description": "{\"description\":null,\"labels\":null}",
9+
"version": 1,
10+
"tasks": [
11+
{
12+
"queryExpression": null,
13+
"name": "DECISION_send_notification_decision",
14+
"taskReferenceName": "send_notification_decision",
15+
"description": null,
16+
"inputParameters": {
17+
"case_value_param": "${workflow.input.should_send_notification}"
18+
},
19+
"type": "DECISION",
20+
"dynamicTaskNameParam": null,
21+
"caseValueParam": "case_value_param",
22+
"caseExpression": null,
23+
"expression": null,
24+
"evaluatorType": null,
25+
"scriptExpression": null,
26+
"decisionCases": {
27+
"YES": [
28+
{
29+
"queryExpression": null,
30+
"name": "NOTIFICATION_send_to_customer",
31+
"taskReferenceName": "send_notification_subworkflow",
32+
"description": "{\"description\":null}",
33+
"inputParameters": {
34+
"customer_id": "${workflow.input.customer_id}"
35+
},
36+
"type": "SUB_WORKFLOW",
37+
"dynamicTaskNameParam": null,
38+
"caseValueParam": null,
39+
"caseExpression": null,
40+
"expression": null,
41+
"evaluatorType": null,
42+
"scriptExpression": null,
43+
"decisionCases": null,
44+
"dynamicForkJoinTasksParam": null,
45+
"dynamicForkTasksParam": null,
46+
"dynamicForkTasksInputParamName": null,
47+
"defaultCase": null,
48+
"forkTasks": null,
49+
"startDelay": 0,
50+
"subWorkflowParam": {
51+
"name": "NOTIFICATION_send_to_customer",
52+
"version": 1,
53+
"taskToDomain": null,
54+
"workflowDefinition": null
55+
},
56+
"joinOn": null,
57+
"sink": null,
58+
"optional": false,
59+
"taskDefinition": null,
60+
"rateLimited": false,
61+
"defaultExclusiveJoinTask": null,
62+
"asyncComplete": false,
63+
"loopCondition": null,
64+
"loopOver": null
65+
}
66+
]
67+
},
68+
"dynamicForkJoinTasksParam": null,
69+
"dynamicForkTasksParam": null,
70+
"dynamicForkTasksInputParamName": null,
71+
"defaultCase": null,
72+
"forkTasks": null,
73+
"startDelay": 0,
74+
"subWorkflowParam": null,
75+
"joinOn": null,
76+
"sink": null,
77+
"optional": false,
78+
"taskDefinition": null,
79+
"rateLimited": false,
80+
"defaultExclusiveJoinTask": null,
81+
"asyncComplete": false,
82+
"loopCondition": null,
83+
"loopOver": null
84+
}
85+
],
86+
"inputParameters": [
87+
"{\"should_send_notification\":{\"value\":\"\",\"description\":\" (optional)\"},\"customer_id\":{\"value\":\"\",\"description\":\" (optional)\"}}"
88+
],
89+
"outputParameters": null,
90+
"failureWorkflow": null,
91+
"schemaVersion": 2,
92+
"restartable": true,
93+
"workflowStatusListenerEnabled": true,
94+
"ownerEmail": null,
95+
"timeoutPolicy": null,
96+
"timeoutSeconds": 0,
97+
"variables": null
98+
}

test/ConductorSharp.Engine.Tests/Samples/Workflows/SendCustomerNotification.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
namespace ConductorSharp.Engine.Tests.Samples.Workflows;
22

3+
#region models
4+
public class SendNotificationInput : IRequest<SendNotificationOutput>
5+
{
6+
public dynamic CustomerId { get; set; }
7+
}
8+
9+
public class SendNotificationOutput { }
10+
11+
[OriginalName("NOTIFICATION_send_to_customer")]
12+
public class SendCustomerNotificationV1 : SubWorkflowTaskModel<SendNotificationInput, SendNotificationOutput> { }
13+
314
public class SendCustomerNotificationInput : WorkflowInput<SendCustomerNotificationOutput>
415
{
516
public dynamic CustomerId { get; set; }
@@ -9,7 +20,7 @@ public class SendCustomerNotificationOutput : WorkflowOutput
920
{
1021
public dynamic EmailBody { get; set; }
1122
}
12-
23+
#endregion
1324
[OriginalName("NOTIFICATION_send_to_customer")]
1425
public class SendCustomerNotification : Workflow<SendCustomerNotificationInput, SendCustomerNotificationOutput>
1526
{

0 commit comments

Comments
 (0)