-
Notifications
You must be signed in to change notification settings - Fork 5
/
Guidelines.js
423 lines (395 loc) · 22.7 KB
/
Guidelines.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
import { is } from '../datamodelmodeler/util/ModelUtil';
import { type } from '../util/Util';
import { getClassDependencies, getClassDependents, getConnectedByExistentialAssociation, getConnectedElements, startDoCreation } from './GuidelineUtils';
export const SEVERITY = {
ERROR : {
cssClass : 'errorElement',
label : 'Errors'
},
WARNING : {
cssClass : 'warningElement',
label : 'Warnings'
},
INFORMATION : {
cssClass : 'informationElement',
label : 'Information'
}
}
const severityKeys = Object.keys(SEVERITY)
severityKeys.forEach(key => SEVERITY[key].key = key);
SEVERITY.forEach = function(lambda) {
return severityKeys.map(key => SEVERITY[key]).forEach(lambda);
}
SEVERITY.filter = function(lambda) {
return severityKeys.map(key => SEVERITY[key]).filter(lambda);
}
export default [
{
title : 'GS2: Include all relevant data objects in the goal',
id : 'GS2',
getViolations(mediator) {
const hook = mediator.goalStateModelerHook;
const literals = hook.modeler.getLiterals();
if (literals && literals.length === 0) {
return [{
element : hook.getRootObject(),
message : 'Please include at least one data object configuration as literal in the goal state.'
}];
} else {
return [];
}
},
severity : SEVERITY.ERROR,
link : 'https://github.com/bptlab/fCM-design-support/wiki/Goal-State#gs2---include-all-relevant-data-objects-in-the-goal-state'
},
{
title: 'F9: Do not use gateways at the beginning of a fragment',
id: 'F9',
getViolations(mediator) {
const gateways = mediator.fragmentModelerHook.modeler.get('elementRegistry').filter(element => is(element, 'bpmn:Gateway'));
gateways.filter(gateway => gateway.incoming.length === 0);
return gateways.filter(gateway => gateway.incoming.length === 0).map(gateway => ({
element: gateway.businessObject,
message: 'Please do not use a gateway at the start of a fragment.'
}));
},
severity: SEVERITY.ERROR,
link: 'https://github.com/bptlab/fCM-design-support/wiki/Fragments#f9---do-not-use-gateways-at-the-beginning-of-a-fragment'
},
{
title: 'F3: Use at least one activity for a fragment',
id: 'F3',
getViolations(mediator) {
const elements = mediator.fragmentModelerHook.modeler.get('elementRegistry').filter(element => (is(element, 'bpmn:FlowNode') || is(element, 'bpmn:DataObjectReference')) && element.type !== 'label');
const connectedElements = new Set();
const activities = mediator.fragmentModelerHook.modeler.get('elementRegistry').filter(element => is(element, 'bpmn:Activity'));
for (const activity of activities) {
if (connectedElements.has(activity)) {
continue;
}
getConnectedElements(activity).forEach(element => connectedElements.add(element.id));
}
return elements.filter(element => !connectedElements.has(element.id)).map(element => ({
element: element.businessObject,
message: 'Please connect this ' + type(element.businessObject) + ' to a component with an activity.'
}));
},
severity: SEVERITY.ERROR,
link: 'https://github.com/bptlab/fCM-design-support/wiki/Fragments#f3---use-at-least-one-activity-for-a-fragment'
},
{
title: 'F11: Label notations elements',
id: 'F11',
getViolations(mediator) {
const elements = mediator.fragmentModelerHook.modeler.get('elementRegistry').filter(element =>
is(element, 'bpmn:Activity') || is(element, 'bpmn:Event') || (is(element, 'bpmn:DataObjectReference') && !(element.type === 'label')));
return elements.filter(element => !element.businessObject.name).map(element => ({
element: element.businessObject,
message: 'Please provide a label for each fragment element.'
}));
},
severity: SEVERITY.ERROR,
link: 'https://github.com/bptlab/fCM-design-support/wiki/Fragments#f11---label-notation-elements'
},
{
title: 'F11.1: No empty states for data objects',
id: 'F11.1',
getViolations(mediator) {
const fragmentModeler = mediator.fragmentModelerHook.modeler;
const dataObjects = fragmentModeler.get('elementRegistry').filter(element => is(element, 'bpmn:DataObjectReference') && !(element.type === 'label')).map(element => element.businessObject);
return dataObjects.filter(dataObject => !dataObject.states || dataObject.states.length === 0).map(dataObject => ({
element: dataObject,
message: 'Please provide at least one state for data object references.'
}));
},
severity: SEVERITY.WARNING,
link: 'https://github.com/bptlab/fCM-design-support/wiki/Fragments#f11---label-notation-elements'
},
{
title : 'Use states instead of attributes for important data changes',
id : 'D5',
getViolations(mediator) {
const dataModeler = mediator.dataModelerHook.modeler;
const clazzes = dataModeler.get('elementRegistry').getAll().filter(element => is(element, 'od:Class'));
return clazzes.filter(element => element.businessObject.attributeValues).map(clazz => ({
element : clazz.businessObject,
message : 'Attributes are only used very rarely. Consider using states instead.'
}));
},
severity : SEVERITY.INFORMATION,
link : 'https://github.com/bptlab/fCM-design-support/wiki/Data-Model#d5---use-states-instead-of-attributes-for-important-data-changes'
},
{
title: 'F4: Use data objects to model pre- and postconditions',
id: 'F4',
getViolations(mediator) {
const activities = mediator.fragmentModelerHook.modeler.get('elementRegistry').filter(element =>
is(element, 'bpmn:Activity'));
const activites_with_data = [];
for (let i = 0; i < activities.length; i++) {
for (let y = 0; y < activities[i].outgoing.length; y++) {
if (activities[i].outgoing[y].type === 'bpmn:DataOutputAssociation') {
activites_with_data.push(activities[i]);
}
}
for (let z = 0; z < activities[i].incoming.length; z++) {
if (activities[i].incoming[z].type === 'bpmn:DataInputAssociation') {
activites_with_data.push(activities[i]);
}
}
}
return activities.filter(element => !activites_with_data.includes(element)).map(element => ({
element: element.businessObject,
message: 'Consider using a data object to model a pre- and postcondition for this activity.'
}));
},
severity: SEVERITY.WARNING,
link: 'https://github.com/bptlab/fCM-design-support/wiki/Fragments#f4---use-data-objects-to-model-pre--and-postconditions'
},
{
title: 'F6A: Use at least one start event',
id: 'F6A',
getViolations(mediator) {
const hook = mediator.fragmentModelerHook;
const startEvents = hook.modeler.get('elementRegistry').filter(element => is(element, 'bpmn:StartEvent') && element.type !== 'label');
if (startEvents.length === 0) {
return [{
element: hook.getRootObject(),
message: 'Please use at least one start event in the fragment model.'
}];
} else {
return [];
}
},
severity: SEVERITY.ERROR,
link: 'https://github.com/bptlab/fCM-design-support/wiki/Fragments#f6---use-start-events-only-in-initial-fragments'
},
{
title: 'F6B: Use multiple start events carefully',
id: 'F6B',
getViolations(mediator) {
const hook = mediator.fragmentModelerHook;
const startEvents = hook.modeler.get('elementRegistry').filter(element => is(element, 'bpmn:StartEvent') && element.type !== 'label');
if (startEvents.length > 1) {
return startEvents.map(element => ({
element: element.businessObject,
message: 'Your process has multiple start events. Please ensure that this is intended.'
}));
} else {
return [];
}
},
severity: SEVERITY.INFORMATION,
link: 'https://github.com/bptlab/fCM-design-support/wiki/Fragments#f6---use-start-events-only-in-initial-fragments'
},
{
title: 'F6C: Start fragment does not create case class',
id: 'F6C',
getViolations(mediator) {
const dataModeler = mediator.dataModelerHook.modeler;
const fragmentModeler = mediator.fragmentModelerHook.modeler;
const startEvents = fragmentModeler.get('elementRegistry').filter(element => is(element, 'bpmn:StartEvent') && element.type !== 'label');
const caseClasses = dataModeler.get('elementRegistry')
.filter(element => is(element, 'od:Class'))
.map(element => element.businessObject)
.filter(clazz => clazz.caseClass);
if (caseClasses.length === 0) {return [];}
return startEvents.flatMap(startEvent => {
const connectedElements = getConnectedElements(startEvent);
// get according connected dataobjects
const createdClasses = connectedElements.filter(element => is(element, 'bpmn:DataObjectReference')).map(element => element.businessObject.dataclass);
const caseClassConnected = createdClasses.some(createdClass => caseClasses.includes(createdClass));
if (!caseClassConnected) {
return [{
element: startEvent.businessObject,
message: 'Please make one of the nodes of this start fragment create an object of one of the case classes: ' + caseClasses.map(clazz => '"' + clazz.name + '"').join(', '),
quickFixes : caseClasses.flatMap(caseClass => connectedElements.filter(element => is(element, 'bpmn:Activity') || is(element, 'bpmn:StartEvent')).map(element => (
{
label : 'Add data object reference that writes case class "' + caseClass.name + '" to node "' + element.businessObject.name + '"',
action : (event) => fragmentModeler.startDoCreation(event, element, caseClass)
}
)))
}];
} else {
return [];
}
});
},
severity: SEVERITY.ERROR,
link: 'https://github.com/bptlab/fCM-design-support/wiki/Fragments#f6---use-start-events-only-in-initial-fragments'
},
{
title : 'Have each fragment state transition in olc',
id : 'C3',
getViolations(mediator) {
const fragmentModeler = mediator.fragmentModelerHook.modeler;
const olcModeler = mediator.olcModelerHook.modeler;
const activities = fragmentModeler.get('elementRegistry').filter(element => is(element, 'bpmn:Activity'));
return activities.map(activity => activity.businessObject).flatMap(activity => {
// TODO improve after introduction of IO-Sets
const statesPerClass = {};
activity.dataInputAssociations?.map(assoc => assoc.sourceRef[0]).filter(dataObjectReference => dataObjectReference.dataclass && dataObjectReference.states).forEach(dataObjectReference => {
if (!statesPerClass[dataObjectReference.dataclass.id]) {
statesPerClass[dataObjectReference.dataclass.id] = {clazz : dataObjectReference.dataclass, incoming : [], outgoing : []};
}
statesPerClass[dataObjectReference.dataclass.id].incoming.push(...dataObjectReference.states);
});
activity.dataOutputAssociations?.map(assoc => assoc.targetRef).filter(dataObjectReference => dataObjectReference.dataclass && dataObjectReference.states).forEach(dataObjectReference => {
if (!statesPerClass[dataObjectReference.dataclass.id]) {
statesPerClass[dataObjectReference.dataclass.id] = {clazz : dataObjectReference.dataclass, incoming : [], outgoing : []};
}
statesPerClass[dataObjectReference.dataclass.id].outgoing.push(...dataObjectReference.states);
});
const uncovered = Object.keys(statesPerClass).map(classId => {
const olc = olcModeler.getOlcByClass(statesPerClass[classId].clazz);
const transitionsInOlc = olc.get('Elements').filter(element => is(element, 'olc:Transition'));
function transitionsMatching (sourceState, targetState) {
return transitionsInOlc.filter(transition => transition.sourceState === sourceState && transition.targetState === targetState);
}
const uncoveredInputstates = statesPerClass[classId].incoming.filter(sourceState => {
// Has target states of same class and none is covered
return statesPerClass[classId].outgoing.length > 0 && statesPerClass[classId].outgoing.filter(targetState => {
return sourceState === targetState || transitionsMatching(sourceState, targetState).length > 0;
}).length === 0;
});
const uncoveredOutputstates = statesPerClass[classId].outgoing.filter(targetState => {
// Has source states of same class and none is covered
return statesPerClass[classId].incoming.length > 0 && statesPerClass[classId].incoming.filter(sourceState => {
return sourceState === targetState || transitionsMatching(sourceState, targetState).length > 0;
}).length === 0;
});
return {
classId: classId,
uncoveredInputstates,
uncoveredOutputstates
}
}).filter(({uncoveredInputstates, uncoveredOutputstates}) => (uncoveredInputstates.length + uncoveredOutputstates.length) > 0);
function stringifyUncovered({uncoveredInputstates, uncoveredOutputstates}) {
return ''
+ (uncoveredInputstates.length > 0 && 'input state(s) ' + uncoveredInputstates.map(state => '"' + state.name + '"').join(', ') || '')
+ (uncoveredInputstates.length > 0 && uncoveredOutputstates.length > 0 && ' and ' || '')
+ (uncoveredOutputstates.length > 0 && 'output state(s) ' + uncoveredOutputstates.map(state => '"' + state.name + '"').join(', ') || '')
+ ' of class "' + (uncoveredInputstates[0] || uncoveredOutputstates[0])?.$parent.name + '"';
}
function stringifyTransition(sourceState, targetState) {
return '\[' + sourceState.name + ' → ' + targetState.name + '\]';
}
function transitionToQuickFix(sourceState, targetState) {
return {
label : 'Create transition: ' + stringifyTransition(sourceState, targetState) + ' in OLC ' + sourceState.$parent.name,
action : () => mediator.olcModelerHook.modeler.createTransition(sourceState, targetState)
}
}
if (uncovered.length > 0) {
return [{
element : activity,
message : 'Please cover the ' + uncovered.map(stringifyUncovered).join(', ') + ' with valid transitions in the OLC.',
quickFixes : uncovered.flatMap(({classId, uncoveredInputstates, uncoveredOutputstates}) => [
... uncoveredInputstates.flatMap(sourceState => statesPerClass[classId].outgoing.map(targetState => ({sourceState, targetState}))),
... uncoveredOutputstates.flatMap(targetState => statesPerClass[classId].incoming.filter(sourceState => !uncoveredInputstates.includes(sourceState)).map(sourceState => ({sourceState, targetState})))
].map(({sourceState, targetState}) => transitionToQuickFix(sourceState, targetState)))
}];
} else {
return [];
}
});
},
severity : SEVERITY.ERROR,
link : 'https://github.com/bptlab/fCM-design-support/wiki/Consistency#c3---use-state-labels-and-state-transitions-of-data-objects-consistently-in-olcs-and-fragments'
},
{
title: 'C5: Provide existential objects',
id: 'C5',
getViolations(mediator) {
const classDependencies = getClassDependencies(mediator);
const fragmentModeler = mediator.fragmentModelerHook.modeler;
const activities = fragmentModeler.get('elementRegistry').filter(element => is(element, 'bpmn:Activity')).map(activity => activity.businessObject);
return activities.flatMap(activity => {
// TODO rework when IO sets are implemented (classes might be created in specific io configurations)
const writtenClasses = new Set(activity.dataOutputAssociations?.filter(assoc => assoc.targetRef.dataclass).map(assoc => assoc.targetRef.dataclass));
const readClasses = new Set(activity.dataInputAssociations?.map(assoc => assoc.sourceRef[0].dataclass));
const createdClasses = [...writtenClasses].filter(clazz => !readClasses.has(clazz));
const missingAssociations = createdClasses.flatMap(createdClass => {
return (classDependencies[createdClass.id] || []).filter(contextClass => !writtenClasses.has(contextClass) && !readClasses.has(contextClass)).map(contextClass => ({createdClass, contextClass}));
});
function stringifyMissing({createdClass, contextClass}) {
return 'to \"' + contextClass.name + '\" for \"' + createdClass.name + '\"';
}
if (missingAssociations.length > 0) {
const activityShape = fragmentModeler.get('elementRegistry').get(activity.id);
return [{
element: activity,
// Maybe we can also add to the error message, which classes are missing their context class?
message: 'In activity "' + activity.name + '", please add references to the following context classes: ' + missingAssociations.map(stringifyMissing).join(', '),
quickFixes : missingAssociations.flatMap(({contextClass}) => (
[{
label : 'Add reading data object reference of class \"' + contextClass.name + '\" to activity \"' + activity.name + '\"',
action : (event) => fragmentModeler.startDoCreation(event, activityShape, contextClass, true)
},{
label : 'Add writing data object reference of class \"' + contextClass.name + '\" to activity \"' + activity.name + '\"',
action : (event) => fragmentModeler.startDoCreation(event, activityShape, contextClass)
}]
))
}];
} else {
return [];
}
});
},
severity: SEVERITY.ERROR,
link: 'https://github.com/bptlab/fCM-design-support/wiki/Consistency#c5---provide-context-data-objects-from-data-model-on-data-object-creation-in-fragments'
},
{
title : 'Specify a Case Class.',
id : 'D2',
getViolations(mediator) {
const hook = mediator.dataModelerHook;
const dataModeler = hook.modeler;
const clazzes = dataModeler.get('elementRegistry').getAll().filter(element => is(element, 'od:Class'));
const caseClasses = dataModeler.get('elementRegistry')
.filter(element => is(element, 'od:Class'))
.map(element => element.businessObject)
.filter(clazz => clazz.caseClass);
if (!caseClasses.length) {
return [{
element : hook.getRootObject(),
message : 'Please specify a case class.',
quickFixes : clazzes.map(clazz => (
{
label : 'Make class "' + clazz.businessObject.name + '" a case class',
action : (action) => dataModeler.updateProperty(clazz, {caseClass: true})
}
))
}];
} else {
return [];
}
},
severity : SEVERITY.ERROR,
link : 'https://github.com/bptlab/fCM-design-support/wiki/Data-Model#d2---specify-a-case-class'
},
{
title : 'Connect the Case Class to Every Other Class.',
id : 'D3',
getViolations(mediator) {
const dataModeler = mediator.dataModelerHook.modeler;
const classDependents = getClassDependents(mediator);
const clazzes = dataModeler.get('elementRegistry')
.filter(element => is(element, 'od:Class'))
.map(element => element.businessObject);
const caseClasses = clazzes.filter(clazz => clazz.caseClass);
if (!caseClasses.length) {
return [];
}
const connectedWithCaseClass = getConnectedByExistentialAssociation(caseClasses[0], classDependents);
const notConnectedClasses = clazzes.filter(clazz => connectedWithCaseClass.indexOf(clazz) === -1);
return notConnectedClasses.map(clazz => ({
element: clazz,
message: 'Please connect class "' + clazz.name + '" to the case class via a path of existential associations.'
}
))
},
severity : SEVERITY.ERROR,
link : 'https://github.com/bptlab/fCM-design-support/wiki/Data-Model#d3---connect-the-case-class-to-every-other-class'
},
]