forked from bptlab/fCM-design-support
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GuidelineUtils.js
103 lines (81 loc) · 3.24 KB
/
GuidelineUtils.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
import {is} from '../common/util/ModelUtil';
export function getConnectedElements(element) {
let visited = [];
function visit(element) {
if (visited.includes(element)) {
return;
}
visited.push(element);
element.incoming.forEach(flow => {
visit(flow.source);
});
element.outgoing.forEach(flow => {
visit(flow.target);
});
}
visit(element);
return visited;
}
export function getConnectedByExistentialAssociation(caseClass, classDependents) {
let visited = [];
function visit(element) {
if (visited.includes(element)) {
return;
}
visited.push(element);
(classDependents[element.id] || []).forEach(visit);
}
visit(caseClass);
return visited;
}
/**
* Get for each class the other classes that depend on it
*/
export function getClassDependents(mediator) {
const classDependents = {};
function addClassDependent(dependentClass, contextClass) {
if (!classDependents[contextClass.id]) {
classDependents[contextClass.id] = [];
}
classDependents[contextClass.id].push(dependentClass);
}
forEachExistentialAssociation(mediator, addClassDependent);
return classDependents;
}
/**
* Get for each class the other classes that it depends on
*/
export function getClassDependencies(mediator) {
const classDependencies = {};
function addClassDependency(dependentClass, contextClass) {
if (!classDependencies[dependentClass.id]) {
classDependencies[dependentClass.id] = [];
}
classDependencies[dependentClass.id].push(contextClass);
}
forEachExistentialAssociation(mediator, addClassDependency);
return classDependencies;
}
/**
* Call handler for each existential association with parameters dependentClass and contextClass
*/
export function forEachExistentialAssociation(mediator, handler) {
const dataModeler = mediator.dataModelerHook.modeler;
const classDependencies = {};
const associations = dataModeler.get('elementRegistry').filter(element => is(element, 'od:Association') && element.type !== 'label').map(association => association.businessObject);
associations
.filter(association => association.sourceCardinality && association.targetCardinality) // TODO this is an hotfix
.forEach(association => {
const [sourceLowerBound, sourceUpperBound] = association.sourceCardinality.split('..');
const [targetLowerBound, targetUpperBound] = association.targetCardinality.split('..');
if (parseInt(sourceLowerBound) > 0) {
// The lower bound for the association source class is positive, which means the target class is dependent of it
handler(association.targetRef, association.sourceRef);
}
if (parseInt(targetLowerBound) > 0) {
// The lower bound for the association target class is positive, which means the source class is dependent of it
handler(association.sourceRef, association.targetRef);
}
});
return classDependencies;
}