-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pasting compensation activity without boundary event
Closes #2070
- Loading branch information
1 parent
61f0d72
commit e6c8ff5
Showing
2 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
lib/features/modeling/behavior/SetCompensationActivityAfterPasteBehavior.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters