Skip to content

Commit

Permalink
feat(camunda-platform): add input output behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Kiefer authored and philippfromme committed Sep 15, 2021
1 parent 28da536 commit 83d8f7c
Show file tree
Hide file tree
Showing 4 changed files with 711 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import inherits from 'inherits';

import {
getBusinessObject,
is
} from 'bpmn-js/lib/util/ModelUtil';

import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';

/**
* Camunda BPMN specific `camunda:inputOutput` behavior.
*/
export default function UpdateInputOutputBehavior(eventBus, modeling) {

CommandInterceptor.call(this, eventBus);

this.postExecute([
'element.updateProperties',
'element.updateModdleProperties',
'properties-panel.update-businessobject-list'
], function(context) {
const {
element
} = context;

const businessObject = getBusinessObject(element);
const inputOutput = getInputOutput(businessObject);
const extensionElements = businessObject.get('extensionElements');

// Remove camunda:inputOutput if there are no input/output parameters anymore.
if (inputOutput && isEmpty(inputOutput)) {
const filtered = extensionElements.values.filter(function(element) {
return element !== inputOutput;
});

modeling.updateModdleProperties(element, extensionElements, {
values: filtered
});
}
}, true);
}


UpdateInputOutputBehavior.$inject = [
'eventBus',
'modeling'
];

inherits(UpdateInputOutputBehavior, CommandInterceptor);


// helper //////////////////

function getInputParameters(inputOutput) {
return inputOutput.get('inputParameters');
}

function getOutputParameters(inputOutput) {
return inputOutput.get('outputParameters');
}

function getInputOutput(businessObject) {
return (getExtensionElementsList(businessObject, 'camunda:InputOutput') || [])[0];
}

function getExtensionElementsList(businessObject, type = undefined) {
const elements = ((businessObject.get('extensionElements') &&
businessObject.get('extensionElements').get('values')) || []);

return (elements.length && type) ?
elements.filter((value) => is(value, type)) :
elements;
}

function isEmpty(inputOutput) {
const inputParameters = getInputParameters(inputOutput);
const outputParameters = getOutputParameters(inputOutput);

return inputParameters.length === 0 && outputParameters.length === 0;
}
3 changes: 3 additions & 0 deletions lib/camunda-platform/features/modeling/behavior/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import DeleteErrorEventDefinitionBehavior from './DeleteErrorEventDefinitionBehavior';
import DeleteRetryTimeCycleBehavior from './DeleteRetryTimeCycleBehavior';
import UpdateCamundaExclusiveBehavior from './UpdateCamundaExclusiveBehavior';
import UpdateInputOutputBehavior from './UpdateInputOutputBehavior';
import UpdateResultVariableBehavior from './UpdateResultVariableBehavior';
import UserTaskFormsBehavior from './UserTaskFormsBehavior';

Expand All @@ -10,11 +11,13 @@ export default {
'deleteRetryTimeCycleBehavior',
'updateCamundaExclusiveBehavior',
'updateResultVariableBehavior',
'updateInputOutputBehavior',
'userTaskFormsBehavior'
],
deleteErrorEventDefinitionBehavior: [ 'type', DeleteErrorEventDefinitionBehavior ],
deleteRetryTimeCycleBehavior: [ 'type', DeleteRetryTimeCycleBehavior ],
updateCamundaExclusiveBehavior: [ 'type', UpdateCamundaExclusiveBehavior ],
updateResultVariableBehavior: [ 'type', UpdateResultVariableBehavior ],
updateInputOutputBehavior: [ 'type', UpdateInputOutputBehavior ],
userTaskFormsBehavior: [ 'type', UserTaskFormsBehavior ]
};
Loading

0 comments on commit 83d8f7c

Please sign in to comment.