-
Notifications
You must be signed in to change notification settings - Fork 0
/
bpmnconstructor.js
101 lines (87 loc) · 3.09 KB
/
bpmnconstructor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const BpmnModdle = require('bpmn-moddle');
const AutoLayout = require('bpmn-auto-layout');
const moddle = new BpmnModdle();
const eventActivities = {
IntermediateCatchEvent: 'bpmn:IntermediateCatchEvent',
StartEvent: 'bpmn:StartEvent',
EndEvent: 'bpmn:EndEvent',
};
const gateways = {
ExclusiveGateway: 'bpmn:ExclusiveGateway',
InclusiveGateway: 'bpmn:InclusiveGateway',
ParallelGateway: 'bpmn:ParallelGateway',
};
const activities = {
Task: 'bpmn:Task',
ScriptTask: 'bpmn:ScriptTask',
ServiceTask: 'bpmn:ServiceTask',
UserTask: 'bpmn:UserTask',
SubProcess: 'bpmn:SubProcess',
};
const flows = {
SequenceFlow: 'bpmn:SequenceFlow',
}
const createProcess = async () => {
const startEvent = moddle.create(eventActivities.StartEvent, { id: 'start' });
const parallelGateway1 = moddle.create(gateways.ParallelGateway, { id: 'gateway1' });
const task1 = moddle.create(activities.ServiceTask, { id: 'task1', name: 'Step 1' });
const task2 = moddle.create(activities.UserTask, { id: 'task2', name: 'Step 2' });
const task3 = moddle.create(activities.ServiceTask, { id: 'task3', name: 'Step 3' });
const parallelGateway2 = moddle.create(gateways.ParallelGateway, { id: 'gateway2' });
const endEvent = moddle.create(eventActivities.EndEvent, { id: 'end' });
const bpmnProcess = moddle.create('bpmn:Process', { id: 'MyProcess_1',
flowElements: [
startEvent,
parallelGateway2,
parallelGateway1,
task1,
task2,
task3,
endEvent,
moddle.create(flows.SequenceFlow, {
id: 'flow0',
sourceRef: startEvent,
targetRef: parallelGateway1,
}),
moddle.create(flows.SequenceFlow, {
id: 'flow1',
sourceRef: parallelGateway1,
targetRef: task1,
}),
moddle.create(flows.SequenceFlow, {
id: 'flow2',
sourceRef: task1,
targetRef: task2,
}),
moddle.create(flows.SequenceFlow, {
id: 'flow3',
sourceRef: parallelGateway1,
targetRef: task3,
}),
moddle.create(flows.SequenceFlow, {
id: 'flow4',
sourceRef: task3,
targetRef: parallelGateway2,
}),
moddle.create(flows.SequenceFlow, {
id: 'flow5',
sourceRef: task2,
targetRef: parallelGateway2,
}),
moddle.create(flows.SequenceFlow, {
id: 'flow6',
sourceRef: parallelGateway2,
targetRef: endEvent,
}),
],
});
const root = moddle.create('bpmn:Definitions', { id: 'MyDefinition_1'});
root.rootElements = [bpmnProcess];
const {
xml
} = await moddle.toXML(root);
var autoLayout = new AutoLayout();
const layoutedDiagramXML = await autoLayout.layoutProcess(xml);
return layoutedDiagramXML;
}
module.exports= { createProcess};