Skip to content

Commit

Permalink
fix: pasting compensation activity without boundary event
Browse files Browse the repository at this point in the history
Closes #2070
  • Loading branch information
abdul99ahad committed Aug 20, 2024
1 parent 61f0d72 commit e6c8ff5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import inherits from 'inherits-browser';

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

import { getBusinessObject, is } from '../../../util/ModelUtil';

import { hasEventDefinition } from '../../../util/DiUtil';

/**
* @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
* @typedef {import('../../rules/BpmnRules').default} BpmnRules
* @typedef {import('../Modeling').default} Modeling
*/


/**
* A behavior that sets the property of Compensation Activity after paste operation
*
* @param {EventBus} eventBus
* @param {Modeling} modeling
*/
export default function SetCompensationActivityAfterPasteBehavior(eventBus, modeling) {

CommandInterceptor.call(this, eventBus);

this.postExecuted('elements.create', function(event) {
const context = event.context,
elements = context.elements;

// check if compensation activity is connected to compensation boundary event
for (const element of elements) {
if (isForCompensation(element) && !isConnectedToCompensationBoundaryEvent(element)) {
modeling.updateProperties(element, { isForCompensation: undefined });

Check warning on line 33 in lib/features/modeling/behavior/SetCompensationActivityAfterPasteBehavior.js

View check run for this annotation

Codecov / codecov/patch

lib/features/modeling/behavior/SetCompensationActivityAfterPasteBehavior.js#L33

Added line #L33 was not covered by tests
}
}
});
}

inherits(SetCompensationActivityAfterPasteBehavior, CommandInterceptor);

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


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

function isForCompensation(element) {
const bo = getBusinessObject(element);
return bo && typeof bo.get === 'function' && bo.get('isForCompensation');
}

function isCompensationBoundaryEvent(element) {
return element && is(element, 'bpmn:BoundaryEvent') &&
hasEventDefinition(element, 'bpmn:CompensateEventDefinition');
}

function isConnectedToCompensationBoundaryEvent(element) {
const compensationAssociations = element.incoming.filter(
connection => isCompensationBoundaryEvent(connection.source)
);
if (compensationAssociations.length > 0) {
return true;
}
return false;

Check warning on line 66 in lib/features/modeling/behavior/SetCompensationActivityAfterPasteBehavior.js

View check run for this annotation

Codecov / codecov/patch

lib/features/modeling/behavior/SetCompensationActivityAfterPasteBehavior.js#L66

Added line #L66 was not covered by tests
}
7 changes: 5 additions & 2 deletions lib/features/modeling/behavior/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import ToggleElementCollapseBehaviour from './ToggleElementCollapseBehaviour';
import UnclaimIdBehavior from './UnclaimIdBehavior';
import UnsetDefaultFlowBehavior from './UnsetDefaultFlowBehavior';
import UpdateFlowNodeRefsBehavior from './UpdateFlowNodeRefsBehavior';
import SetCompensationActivityAfterPasteBehavior from './SetCompensationActivityAfterPasteBehavior';

/**
* @type { import('didi').ModuleDeclaration }
Expand Down Expand Up @@ -83,7 +84,8 @@ export default {
'toggleElementCollapseBehaviour',
'unclaimIdBehavior',
'updateFlowNodeRefsBehavior',
'unsetDefaultFlowBehavior'
'unsetDefaultFlowBehavior',
'setCompensationActivityAfterPasteBehavior'
],
adaptiveLabelPositioningBehavior: [ 'type', AdaptiveLabelPositioningBehavior ],
appendBehavior: [ 'type', AppendBehavior ],
Expand Down Expand Up @@ -124,5 +126,6 @@ export default {
toggleElementCollapseBehaviour : [ 'type', ToggleElementCollapseBehaviour ],
unclaimIdBehavior: [ 'type', UnclaimIdBehavior ],
unsetDefaultFlowBehavior: [ 'type', UnsetDefaultFlowBehavior ],
updateFlowNodeRefsBehavior: [ 'type', UpdateFlowNodeRefsBehavior ]
updateFlowNodeRefsBehavior: [ 'type', UpdateFlowNodeRefsBehavior ],
setCompensationActivityAfterPasteBehavior: [ 'type', SetCompensationActivityAfterPasteBehavior ]
};

0 comments on commit e6c8ff5

Please sign in to comment.