diff --git a/components/bpmn-q/modeler-component/extensions/pattern/modeling/PatternReplaceMenuProvider.js b/components/bpmn-q/modeler-component/extensions/pattern/modeling/PatternReplaceMenuProvider.js index fa0c58ad..54f8e0a6 100644 --- a/components/bpmn-q/modeler-component/extensions/pattern/modeling/PatternReplaceMenuProvider.js +++ b/components/bpmn-q/modeler-component/extensions/pattern/modeling/PatternReplaceMenuProvider.js @@ -159,17 +159,19 @@ export default class PatternReplaceMenuProvider { }); if (element.host.type === quantmeConsts.QUANTUM_CIRCUIT_LOADING_TASK) { - filteredOptionsBasedOnAttachers = - quantmeReplaceOptions.AUGMENTATION_PATTERN.filter((option) => { + filteredOptionsBasedOnAttachers = filteredOptionsBasedOnAttachers.filter( + (option) => { return option.target.type === consts.BIASED_INITIAL_STATE; - }); + } + ); } if (element.host.type === quantmeConsts.QUANTUM_CIRCUIT_EXECUTION_TASK) { - filteredOptionsBasedOnAttachers = - quantmeReplaceOptions.AUGMENTATION_PATTERN.filter((option) => { + filteredOptionsBasedOnAttachers = filteredOptionsBasedOnAttachers.filter( + (option) => { return option.target.type !== consts.BIASED_INITIAL_STATE; - }); + } + ); } // error correction is not allowed with error mitigation diff --git a/components/bpmn-q/modeler-component/extensions/pattern/modeling/PatternRules.js b/components/bpmn-q/modeler-component/extensions/pattern/modeling/PatternRules.js index 536567e5..fe54cb0e 100644 --- a/components/bpmn-q/modeler-component/extensions/pattern/modeling/PatternRules.js +++ b/components/bpmn-q/modeler-component/extensions/pattern/modeling/PatternRules.js @@ -92,6 +92,21 @@ export default class PatternRules extends RuleProvider { } } + if ( + attachedElementTypesWithPolicy === 1 && + target.type === quantmeConsts.QUANTUM_CIRCUIT_LOADING_TASK + ) { + return false; + } + + if (target.type === quantmeConsts.QUANTUM_CIRCUIT_EXECUTION_TASK) { + // we cannot attach behavioral pattern to any task + attachedElementTypesWithPolicy += consts.BEHAVIORAL_PATTERNS.length; + + // we cannot attach the biased initial state + attachedElementTypesWithPolicy += 1; + } + for (let i = 0; i < target.attachers.length; i++) { if (specificPolicies.includes(target.attachers[i].type)) { specificPolicies = specificPolicies.filter( @@ -139,8 +154,7 @@ export default class PatternRules extends RuleProvider { } if ( shapeToAttach.type.includes("pattern") && - (target.type === "bpmn:ServiceTask" || - target.type === "bpmn:SubProcess") + target.type === "bpmn:SubProcess" ) { return true; } diff --git a/components/bpmn-q/modeler-component/extensions/pattern/replacement/PatternTransformator.js b/components/bpmn-q/modeler-component/extensions/pattern/replacement/PatternTransformator.js index 7c59300b..70f04939 100644 --- a/components/bpmn-q/modeler-component/extensions/pattern/replacement/PatternTransformator.js +++ b/components/bpmn-q/modeler-component/extensions/pattern/replacement/PatternTransformator.js @@ -479,40 +479,44 @@ export function attachPatternsToSuitableTasks( // contains all flowElements of the parent and its children let children = new Set(); - patterns[j].attachedToRef.flowElements.forEach((flowElement) => - children.add(flowElement.id) - ); + let hostFlowElements = patterns[j].attachedToRef.flowElements; + if (hostFlowElements !== undefined) { + hostFlowElements.forEach((flowElement) => children.add(flowElement.id)); - patterns[j].attachedToRef.flowElements.forEach((child) => { - if ( - (child.$type && child.$type === "bpmn:SubProcess") || - (child.type && child.type === "bpmn:SubProcess") - ) { - // Recursively retrieve the subprocess's flowElements - let subProcessFlowElements = retrieveFlowElements( - child.flowElements, - elementRegistry - ); - subProcessFlowElements.forEach((flowElement) => - children.add(flowElement) - ); - } - }); + hostFlowElements.forEach((child) => { + if ( + (child.$type && child.$type === "bpmn:SubProcess") || + (child.type && child.type === "bpmn:SubProcess") + ) { + // Recursively retrieve the subprocess's flowElements + let subProcessFlowElements = retrieveFlowElements( + child.flowElements, + elementRegistry + ); + subProcessFlowElements.forEach((flowElement) => + children.add(flowElement) + ); + } + }); - children.values().forEach((id) => { - attachPatternsToSuitableConstruct( - elementRegistry.get(id), - pattern.type, - modeling - ); - }); + children.values().forEach((id) => { + attachPatternsToSuitableConstruct( + elementRegistry.get(id), + pattern.type, + modeling + ); + }); + } } } for (let i = 0; i < patterns.length; i++) { - // behavioral patterns are deleted after acting on the optimization candidate - if (!constants.BEHAVIORAL_PATTERNS.includes(patterns[i].task.$type)) { - modeling.removeShape(elementRegistry.get(patterns[i].task.id)); + let hostFlowElements = patterns[i].attachedToRef.flowElements; + if (hostFlowElements !== undefined) { + // behavioral patterns are deleted after acting on the optimization candidate + if (!constants.BEHAVIORAL_PATTERNS.includes(patterns[i].task.$type)) { + modeling.removeShape(elementRegistry.get(patterns[i].task.id)); + } } } }