From 0bc2255b5c4dbea14f6eb3410b993f73631fd585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ognjen=20Kati=C4=87?= <44910579+ognjenkatic@users.noreply.github.com> Date: Tue, 13 Jun 2023 13:20:58 +0200 Subject: [PATCH 1/3] add builder --- .../Builders/HumanTaskBuilder.cs | 43 +++++++++++++++++++ .../Model/HumanTaskModel.cs | 9 ++++ 2 files changed, 52 insertions(+) create mode 100644 src/ConductorSharp.Engine/Builders/HumanTaskBuilder.cs create mode 100644 src/ConductorSharp.Engine/Model/HumanTaskModel.cs diff --git a/src/ConductorSharp.Engine/Builders/HumanTaskBuilder.cs b/src/ConductorSharp.Engine/Builders/HumanTaskBuilder.cs new file mode 100644 index 00000000..773c6b38 --- /dev/null +++ b/src/ConductorSharp.Engine/Builders/HumanTaskBuilder.cs @@ -0,0 +1,43 @@ +using ConductorSharp.Client.Model.Common; +using ConductorSharp.Engine.Interface; +using ConductorSharp.Engine.Model; +using ConductorSharp.Engine.Util.Builders; +using Newtonsoft.Json.Linq; +using System; +using System.Linq.Expressions; + +namespace ConductorSharp.Engine.Builders +{ + public static class HumanTaskExtensions + { + public static ITaskOptionsBuilder AddTask( + this ITaskSequenceBuilder builder, + Expression> reference, + Expression> input + ) where TWorkflow : ITypedWorkflow + { + var taskBuilder = new HumanTaskBuilder(reference.Body, input.Body, builder.BuildConfiguration); + builder.AddTaskBuilderToSequence(taskBuilder); + return taskBuilder; + } + } + + internal class HumanTaskBuilder : BaseTaskBuilder + { + public HumanTaskBuilder(Expression taskExpression, Expression inputExpression, BuildConfiguration buildConfiguration) + : base(taskExpression, inputExpression, buildConfiguration) { } + + public override WorkflowDefinition.Task[] Build() => + new[] + { + new WorkflowDefinition.Task + { + Name = $"HUMAN_{_taskRefferenceName}", + TaskReferenceName = _taskRefferenceName, + Type = "HUMAN", + InputParameters = _inputParameters, + Description = new JObject { new JProperty("description", _description) }.ToString(Newtonsoft.Json.Formatting.None), + } + }; + } +} diff --git a/src/ConductorSharp.Engine/Model/HumanTaskModel.cs b/src/ConductorSharp.Engine/Model/HumanTaskModel.cs new file mode 100644 index 00000000..0b9d2010 --- /dev/null +++ b/src/ConductorSharp.Engine/Model/HumanTaskModel.cs @@ -0,0 +1,9 @@ +using MediatR; +using Newtonsoft.Json; + +namespace ConductorSharp.Engine.Model +{ + public class HumanTaskInput : IRequest { } + + public class HumanTaskModel : TaskModel { } +} From 005b3c615f4a46076b9dfddd049da7720d325d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ognjen=20Kati=C4=87?= <44910579+ognjenkatic@users.noreply.github.com> Date: Tue, 13 Jun 2023 14:33:09 +0200 Subject: [PATCH 2/3] add tests --- .../ConductorSharp.Engine.Tests.csproj | 2 + .../Integration/WorkflowBuilderTests.cs | 10 ++++ .../Samples/Workflows/HumanTask.json | 55 +++++++++++++++++++ .../Samples/Workflows/HumanTaskWorkflow.cs | 27 +++++++++ 4 files changed, 94 insertions(+) create mode 100644 test/ConductorSharp.Engine.Tests/Samples/Workflows/HumanTask.json create mode 100644 test/ConductorSharp.Engine.Tests/Samples/Workflows/HumanTaskWorkflow.cs diff --git a/test/ConductorSharp.Engine.Tests/ConductorSharp.Engine.Tests.csproj b/test/ConductorSharp.Engine.Tests/ConductorSharp.Engine.Tests.csproj index d0f601bb..55625c1c 100644 --- a/test/ConductorSharp.Engine.Tests/ConductorSharp.Engine.Tests.csproj +++ b/test/ConductorSharp.Engine.Tests/ConductorSharp.Engine.Tests.csproj @@ -16,6 +16,7 @@ + @@ -30,6 +31,7 @@ + Never diff --git a/test/ConductorSharp.Engine.Tests/Integration/WorkflowBuilderTests.cs b/test/ConductorSharp.Engine.Tests/Integration/WorkflowBuilderTests.cs index adbde384..4407f3e1 100644 --- a/test/ConductorSharp.Engine.Tests/Integration/WorkflowBuilderTests.cs +++ b/test/ConductorSharp.Engine.Tests/Integration/WorkflowBuilderTests.cs @@ -46,6 +46,7 @@ public WorkflowBuilderTests() _containerBuilder.RegisterWorkflow(); _containerBuilder.RegisterWorkflow(); _containerBuilder.RegisterWorkflow(); + _containerBuilder.RegisterWorkflow(); _container = _containerBuilder.Build(); } @@ -224,6 +225,15 @@ public void BuilderReturnsCorrectDefinitionPassthroughTaskWorkflow() Assert.Equal(expectedDefinition, definition); } + [Fact] + public void BuilderReturnsCorrectDefinitionHumanWorkflow() + { + var definition = GetDefinitionFromWorkflow(); + var expectedDefinition = EmbeddedFileHelper.GetLinesFromEmbeddedFile("~/Samples/Workflows/HumanTask.json"); + + Assert.Equal(expectedDefinition, definition); + } + private string GetDefinitionFromWorkflow() where TNameable : INameable { var workflow = _container.Resolve>().First(a => a.Name == NamingUtil.NameOf()); diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/HumanTask.json b/test/ConductorSharp.Engine.Tests/Samples/Workflows/HumanTask.json new file mode 100644 index 00000000..5214d645 --- /dev/null +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/HumanTask.json @@ -0,0 +1,55 @@ +{ + "ownerApp": null, + "createTime": 0, + "updateTime": 0, + "createdBy": null, + "updatedBy": null, + "name": "human_task_workflow", + "description": "{\"description\":null,\"labels\":null}", + "version": 1, + "tasks": [ + { + "queryExpression": null, + "name": "HUMAN_human_task", + "taskReferenceName": "human_task", + "description": "{\"description\":null}", + "inputParameters": {}, + "type": "HUMAN", + "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": null, + "joinOn": null, + "sink": null, + "optional": false, + "taskDefinition": null, + "rateLimited": false, + "defaultExclusiveJoinTask": null, + "asyncComplete": false, + "loopCondition": null, + "loopOver": null + } + ], + "inputParameters": [ + "{}" + ], + "outputParameters": null, + "failureWorkflow": null, + "schemaVersion": 2, + "restartable": true, + "workflowStatusListenerEnabled": true, + "ownerEmail": null, + "timeoutPolicy": null, + "timeoutSeconds": 0, + "variables": null +} \ No newline at end of file diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/HumanTaskWorkflow.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/HumanTaskWorkflow.cs new file mode 100644 index 00000000..163aeb43 --- /dev/null +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/HumanTaskWorkflow.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConductorSharp.Engine.Tests.Samples.Workflows +{ + public class HumanTaskWorkflowInput : WorkflowInput { } + + public class HumanTaskWorkflowOutput : WorkflowOutput { } + + public class HumanTaskWorkflow : Workflow + { + public HumanTaskModel HumanTask { get; set; } + + public HumanTaskWorkflow(WorkflowDefinitionBuilder builder) + : base(builder) { } + + public override void BuildDefinition() + { + base.BuildDefinition(); + + _builder.AddTask(wf => wf.HumanTask, wf => new() { }); + } + } +} From b4f2394ee4ee13d562ffd2b0cd2b1c008540cec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ognjen=20Kati=C4=87?= <44910579+ognjenkatic@users.noreply.github.com> Date: Wed, 14 Jun 2023 09:48:57 +0200 Subject: [PATCH 3/3] deduplicate --- .../ConductorSharp.Engine.Tests.csproj | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/ConductorSharp.Engine.Tests/ConductorSharp.Engine.Tests.csproj b/test/ConductorSharp.Engine.Tests/ConductorSharp.Engine.Tests.csproj index efd0d971..9a7ed0aa 100644 --- a/test/ConductorSharp.Engine.Tests/ConductorSharp.Engine.Tests.csproj +++ b/test/ConductorSharp.Engine.Tests/ConductorSharp.Engine.Tests.csproj @@ -34,9 +34,6 @@ - - Never - Never