Skip to content

Commit f512fb7

Browse files
Ticket #7 : Start to support Process Task
1 parent 44e4c2d commit f512fb7

80 files changed

Lines changed: 1232 additions & 363 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Doc.docx

-870 Bytes
Binary file not shown.

src/CaseManagement.BPMN/ProcessInstance/Processors/BPMNServiceTaskProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public async Task Handle(ProcessFlowInstance pf, ProcessFlowInstanceElement pfe)
1616
pf.LaunchElement(pfe);
1717
var serviceTask = (BPMNServiceTask)pfe;
1818
var type = Type.GetType(serviceTask.FullQualifiedName);
19-
var instance = Activator.CreateInstance(type) as WorkflowTaskDelegate;
20-
await instance.Handle(pf);
19+
// var instance = Activator.CreateInstance(type) as WorkflowTaskDelegate;
20+
// await instance.Handle(pf);
2121
pf.CompleteElement(pfe);
2222
}
2323
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
using CaseManagement.Workflow.Domains;
2-
using CaseManagement.Workflow.Infrastructure;
1+
using CaseManagement.CMMN.CaseProcess.ProcessHandlers;
2+
using CaseManagement.CMMN.Infrastructures;
33
using System.Threading.Tasks;
44

55
namespace CaseManagement.CMMN.Host.Delegates
66
{
7-
public class SendEmailTaskDelegate : WorkflowTaskDelegate
7+
public class SendEmailTaskDelegate : CaseProcessDelegate
88
{
9-
public override Task Handle(ProcessFlowInstance context)
9+
public override Task<CaseProcessResponse> Handle(CaseProcessParameter parameter)
1010
{
11-
return Task.FromResult(0);
11+
return Task.FromResult(new CaseProcessResponse());
1212
}
1313
}
1414
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace CaseManagement.CMMN.Apis
4+
{
5+
[Route(CMMNConstants.RouteNames.CaseInstances)]
6+
public class CaseProcessesController : Controller
7+
{
8+
}
9+
}

src/CaseManagement.CMMN/CMMNConstants.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ public static class RouteNames
66
{
77
public const string CaseDefinitions = "case-definitions";
88
public const string CaseInstances = "case-instances";
9+
public const string CaseProcesses = "case-processes";
10+
}
11+
12+
public static class ProcessImplementationTypes
13+
{
14+
public const string BMNN20 = "http://www.omg.org/spec/CMMN/ProcessType/BPMN20";
15+
public const string XPDL2 = "http://www.omg.org/spec/CMMN/ProcessType/XPDL2";
16+
public const string WSBPEL20 = "http://www.omg.org/spec/CMMN/ProcessType/WSBPEL20";
17+
public const string WSBPEL1 = "http://www.omg.org/spec/CMMN/ProcessType/WSBPEL1";
18+
public const string CASEMANAGEMENTCALLBACK = "https://github.com/simpleidserver/CaseManagement/callback";
919
}
1020
}
1121
}

src/CaseManagement.CMMN/CMMNServerBuilder.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CaseManagement.CMMN.Persistence;
1+
using CaseManagement.CMMN.Domains;
2+
using CaseManagement.CMMN.Persistence;
23
using CaseManagement.CMMN.Persistence.InMemory;
34
using CaseManagement.Workflow;
45
using Microsoft.Extensions.DependencyInjection;
@@ -24,5 +25,11 @@ public CMMNServerBuilder AddDefinitions(ICollection<tDefinitions> defs)
2425
Services.AddSingleton<ICMMNDefinitionsQueryRepository>(new InMemoryCMMNDefinitionsQueryRepository(defs));
2526
return this;
2627
}
28+
29+
public CMMNServerBuilder AddCaseProcesses(ICollection<ProcessAggregate> caseProcesses)
30+
{
31+
Services.AddSingleton<IProcessQueryRepository>(new InMemoryProcessQueryRepository(caseProcesses));
32+
return this;
33+
}
2734
}
2835
}

src/CaseManagement.CMMN/CaseInstance/CommandHandlers/CreateCaseInstanceCommandHandler.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,52 @@ private static CMMNPlanItemDefinition BuildPlanItemDefinition(tPlanItemDefinitio
9797
return BuildHumanTask((tHumanTask)planItemDef);
9898
}
9999

100+
if (planItemDef is tTask)
101+
{
102+
return BuildTask((tTask)planItemDef);
103+
}
104+
100105
return null;
101106
}
102107

108+
private static CMMNTask BuildTask(tTask task)
109+
{
110+
return new CMMNTask(task.name);
111+
}
112+
103113
private static CMMNPlanItemDefinition BuildProcessTask(tProcessTask processTask)
104114
{
105-
return new CMMNProcessTask(processTask.name) { AssemblyQualifiedName = processTask.assemblyQualifiedName, IsBlocking = processTask.isBlocking };
115+
var result = new CMMNProcessTask(processTask.name) { AssemblyQualifiedName = processTask.assemblyQualifiedName, IsBlocking = processTask.isBlocking };
116+
if (processTask.parameterMapping != null)
117+
{
118+
foreach(var pm in processTask.parameterMapping)
119+
{
120+
result.Mappings.Add(new CMMNParameterMapping
121+
{
122+
SourceRef = new CMMNParameter { Name = pm.sourceRef },
123+
TargetRef = new CMMNParameter { Name = pm.targetRef },
124+
Transformation = pm.transformation == null ? null : new CMMNExpression(pm.transformation.language)
125+
{
126+
Body = pm.transformation.Text == null ? null : pm.transformation.Text.First()
127+
}
128+
});
129+
}
130+
}
131+
132+
if (processTask.processRef != null)
133+
{
134+
result.ProcessRef = processTask.processRef.Name;
135+
}
136+
137+
if (processTask.processRefExpression != null)
138+
{
139+
result.ProcessRefExpression = new CMMNExpression(processTask.processRefExpression.language)
140+
{
141+
Body = processTask.processRefExpression.Text.First()
142+
};
143+
}
144+
145+
return result;
106146
}
107147

108148
private static CMMNPlanItemDefinition BuildHumanTask(tHumanTask humanTask)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using CaseManagement.CMMN.Domains;
2+
using CaseManagement.Workflow.Domains;
3+
using CaseManagement.Workflow.Engine;
4+
using System;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
8+
namespace CaseManagement.CMMN.CaseInstance.Processors
9+
{
10+
public abstract class BaseCMMNTaskProcessor : ICMMNPlanItemDefinitionProcessor
11+
{
12+
public abstract Type PlanItemDefinitionType { get; }
13+
14+
public async Task<bool> Handle(CMMNPlanItem cmmnPlanItem, ProcessFlowInstance pf)
15+
{
16+
var processTask = cmmnPlanItem.PlanItemDefinition as CMMNTask;
17+
if (cmmnPlanItem.ExitCriterions.Any() && cmmnPlanItem.ExitCriterions.Any(s => CheckCriterion(s, pf)))
18+
{
19+
cmmnPlanItem.Terminate();
20+
return true;
21+
}
22+
23+
if (processTask.State == CMMNTaskStates.Available)
24+
{
25+
if (cmmnPlanItem.EntryCriterions.Any() && cmmnPlanItem.EntryCriterions.All(s => !CheckCriterion(s, pf)))
26+
{
27+
return false;
28+
}
29+
30+
if (cmmnPlanItem.PlanItemControl != null)
31+
{
32+
var manualActivationRule = cmmnPlanItem.PlanItemControl as CMMNManualActivationRule;
33+
if (manualActivationRule != null)
34+
{
35+
// Note : at the moment the ContextRef is ignored.
36+
if (ExpressionParser.IsValid(manualActivationRule.Expression.Body, pf))
37+
{
38+
cmmnPlanItem.Enable();
39+
return false;
40+
}
41+
}
42+
}
43+
44+
cmmnPlanItem.Start();
45+
}
46+
47+
if (processTask.State == CMMNTaskStates.Active)
48+
{
49+
return await Run(cmmnPlanItem, pf);
50+
}
51+
52+
return true;
53+
}
54+
55+
public abstract Task<bool> Run(CMMNPlanItem cmmnPlanItem, ProcessFlowInstance pf);
56+
57+
private bool CheckCriterion(CMMNCriterion sCriterion, ProcessFlowInstance pf)
58+
{
59+
foreach (var onPart in sCriterion.SEntry.OnParts)
60+
{
61+
if (onPart is CMMNPlanItemOnPart)
62+
{
63+
if (!string.IsNullOrWhiteSpace(onPart.SourceRef))
64+
{
65+
var elt = pf.GetPlanItem(onPart.SourceRef);
66+
if (elt == null || elt.Events.Last().Transition != onPart.StandardEvent)
67+
{
68+
return false;
69+
}
70+
}
71+
}
72+
}
73+
74+
if (sCriterion.SEntry.IfPart != null)
75+
{
76+
return ExpressionParser.IsValid(sCriterion.SEntry.IfPart.Condition, pf);
77+
}
78+
79+
return true;
80+
}
81+
}
82+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using CaseManagement.CMMN.Domains;
4+
using CaseManagement.Workflow.Domains;
5+
using CaseManagement.Workflow.Domains.Process;
6+
using CaseManagement.Workflow.Persistence;
7+
8+
namespace CaseManagement.CMMN.CaseInstance.Processors
9+
{
10+
public class CMMNHumanTaskProcessor : BaseCMMNTaskProcessor
11+
{
12+
private readonly IFormQueryRepository _formQueryRepository;
13+
14+
public CMMNHumanTaskProcessor(IFormQueryRepository formQueryRepository)
15+
{
16+
_formQueryRepository = formQueryRepository;
17+
}
18+
19+
public override Type PlanItemDefinitionType => typeof(CMMNHumanTask);
20+
21+
public override async Task<bool> Run(CMMNPlanItem cmmnPlanItem, ProcessFlowInstance pf)
22+
{
23+
var humanTask = cmmnPlanItem.PlanItemDefinition as CMMNHumanTask;
24+
if (cmmnPlanItem.FormInstance != null && cmmnPlanItem.FormInstance.Status == ProcessFlowInstanceElementFormStatus.Complete)
25+
{
26+
cmmnPlanItem.Complete();
27+
return true;
28+
}
29+
30+
var form = await _formQueryRepository.FindFormById(humanTask.FormId);
31+
cmmnPlanItem.SetFormInstance(form);
32+
if (humanTask.IsBlocking)
33+
{
34+
return false;
35+
}
36+
37+
cmmnPlanItem.Complete();
38+
return true;
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)