This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
/
PayloadMappingsHelper.js
85 lines (74 loc) · 2.12 KB
/
PayloadMappingsHelper.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
/**
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership.
*
* Camunda licenses this file to you under the MIT; you may not use this file
* except in compliance with the MIT License.
*/
import {
getBusinessObject,
is
} from 'bpmn-js/lib/util/ModelUtil';
import extensionElementsHelper from 'bpmn-js-properties-panel/lib/helper/ExtensionElementsHelper';
function getElements(bo, type, prop) {
const elems = extensionElementsHelper.getExtensionElements(bo, type) || [];
return !prop ? elems : (elems[0] || {})[prop] || [];
}
/**
* Get a payloadMappings object from the business object
*
* @param {djs.model.Base} element
*
* @param {djs.model.Base} props
*
* @return {ModdleElement} the payloadMappings object
*/
function getParameters(element, prop) {
const inputOutput = getPayloadMappings(element);
return (inputOutput && inputOutput.get(prop)) || [];
}
/**
* Get a payloadMappings object from the business object
*
* @param {djs.model.Base} element
*
* @return {ModdleElement} the payloadMappings object
*/
export function getPayloadMappings(element) {
const bo = getBusinessObject(element);
return (getElements(bo, 'zeebe:PayloadMappings') || [])[0];
}
/**
* Return all mappings existing in the business object, and
* an empty array if none exist.
*
* @param {djs.model.Base} element
*
* @return {Array} a list of mapping objects
*/
export function getMappings(element) {
return getParameters.apply(this, [ element, 'mapping' ]);
}
/**
* Get mappings from the business object at given index
*
* @param {djs.model.Base} element
* @param {number} idx
*
* @return {ModdleElement} input parameter
*/
export function getMapping(element, idx) {
return getMappings(element)[idx];
}
/**
* Returns 'true' if the given element supports payloadmappings
*
* @param {djs.model.Base} element
*
* @return {boolean} a boolean value
*/
export function isPayloadMappingsSupported(element) {
return (is(element, 'bpmn:EndEvent'));
}