/
ModelUtil.js
62 lines (48 loc) · 1.15 KB
/
ModelUtil.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
import { some } from 'min-dash';
/**
* Is an element of the given DMN type?
*
* @param {tjs.model.Base|ModdleElement} element
* @param {String} type
*
* @return {Boolean}
*/
export function is(element, type) {
var bo = getBusinessObject(element);
return bo && (typeof bo.$instanceOf === 'function') && bo.$instanceOf(type);
}
export function isInput(element) {
return is(element, 'dmn:InputClause');
}
export function isOutput(element) {
return is(element, 'dmn:OutputClause');
}
export function isRule(element) {
return is(element, 'dmn:DecisionRule');
}
/**
* Return the business object for a given element.
*
* @param {tjs.model.Base|ModdleElement} element
*
* @return {ModdleElement}
*/
export function getBusinessObject(element) {
return (element && element.businessObject) || element;
}
export function getName(element) {
return getBusinessObject(element).name;
}
/**
* Return true if element has any of the given types.
*
* @param {djs.model.Base} element
* @param {Array<String>} types
*
* @return {Boolean}
*/
export function isAny(element, types) {
return some(types, function(t) {
return is(element, t);
});
}