Skip to content

Commit

Permalink
fix(replace): add moddle extension for canCopyProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
azeghers committed Nov 16, 2020
1 parent 9b5ebca commit 32af48f
Show file tree
Hide file tree
Showing 4 changed files with 380 additions and 4 deletions.
76 changes: 76 additions & 0 deletions lib/extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
'use strict';

var isFunction = require('min-dash').isFunction,
isObject = require('min-dash').isObject,
some = require('min-dash').some;

var WILDCARD = '*';


function ZeebeModdleExtension(eventBus) {

var self = this;

eventBus.on('moddleCopy.canCopyProperty', function(context) {
var property = context.property,
parent = context.parent;

return self.canCopyProperty(property, parent);
});
}

ZeebeModdleExtension.$inject = [ 'eventBus' ];

ZeebeModdleExtension.prototype.canCopyProperty = function(property, parent) {

// check if property is allowed in parent
if (isObject(property) && !isAllowedInParent(property, parent)) {

return false;
}
};

module.exports = ZeebeModdleExtension;

// helpers //////////

function is(element, type) {
return element && isFunction(element.$instanceOf) && element.$instanceOf(type);
}

function getParent(element, type) {
if (!type) {
return element.$parent;
}

if (is(element, type)) {
return element;
}

if (!element.$parent) {
return;
}

return getParent(element.$parent, type);
}

function isAllowedInParent(property, parent) {

// (1) find property descriptor
var descriptor = property.$type && property.$model.getTypeDescriptor(property.$type);

var allowedIn = descriptor && descriptor.meta && descriptor.meta.allowedIn;

if (!allowedIn || isWildcard(allowedIn)) {
return true;
}

// (2) check if property has parent of allowed type
return some(allowedIn, function(type) {
return getParent(parent, type);
});
}

function isWildcard(allowedIn) {
return allowedIn.indexOf(WILDCARD) !== -1;
}
6 changes: 6 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = {
__init__: [ 'zeebeModdleExtension' ],
zeebeModdleExtension: [ 'type', require('./extension') ]
};
30 changes: 26 additions & 4 deletions resources/zeebe.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"types": [
{
"name": "ZeebeServiceTask",
"extends": [ "bpmn:ServiceTask"],
"extends": [
"bpmn:ServiceTask"
],
"properties": [
{
"name": "retryCounter",
Expand Down Expand Up @@ -70,11 +72,31 @@
},
{
"name": "Input",
"superClass": [ "InputOutputParameter" ]
"superClass": [
"InputOutputParameter"
],
"meta": {
"allowedIn": [
"bpmn:CallActivity",
"bpmn:ServiceTask",
"bpmn:SubProcess"
]
}
},
{
"name": "Output",
"superClass": [ "InputOutputParameter" ]
"superClass": [
"InputOutputParameter"
],
"meta": {
"allowedIn": [
"bpmn:CallActivity",
"bpmn:Event",
"bpmn:ReceiveTask",
"bpmn:ServiceTask",
"bpmn:SubProcess"
]
}
},
{
"name": "TaskHeaders",
Expand Down Expand Up @@ -194,4 +216,4 @@
]
}
]
}
}
Loading

0 comments on commit 32af48f

Please sign in to comment.