diff --git a/components/bpmn-q/modeler-component/extensions/opentosca/modeling/OpenTOSCARules.js b/components/bpmn-q/modeler-component/extensions/opentosca/modeling/OpenTOSCARules.js index 7c4b0376..1387c423 100644 --- a/components/bpmn-q/modeler-component/extensions/opentosca/modeling/OpenTOSCARules.js +++ b/components/bpmn-q/modeler-component/extensions/opentosca/modeling/OpenTOSCARules.js @@ -18,6 +18,25 @@ export default class OpenTOSCARules extends RuleProvider { super(eventBus); this.modeling = modeling; + function updateOnDemandStatus(elements, isOnDemand) { + elements?.forEach((element) => { + if (element?.type === consts.ON_DEMAND_POLICY) { + let host = element.host; + if (host !== null) { + host.businessObject.onDemand = isOnDemand; + } + } + }); + } + + eventBus.on("commandStack.elements.delete.preExecute", function (context) { + updateOnDemandStatus(context.context.elements, false); + }); + + eventBus.on("commandStack.elements.delete.reverted", function (context) { + updateOnDemandStatus(context.context.elements, true); + }); + this.addRule("shape.create", 10000, function (context) { let shape = context.shape; diff --git a/components/bpmn-q/modeler-component/extensions/opentosca/utilities/Utilities.js b/components/bpmn-q/modeler-component/extensions/opentosca/utilities/Utilities.js index 0b3be294..1f9c7d71 100644 --- a/components/bpmn-q/modeler-component/extensions/opentosca/utilities/Utilities.js +++ b/components/bpmn-q/modeler-component/extensions/opentosca/utilities/Utilities.js @@ -62,7 +62,7 @@ export function synchronousPostRequest(url, type, body) { * * @param modeler the modeler to which the ServiceTask belongs to * @param serviceTaskId the ID of the ServiceTask - * @returns {{}} the list of retrived policies + * @returns {{}} the list of retrieved policies */ export function getPolicies(modeler, serviceTaskId) { console.log("Retrieving policies for ServiceTask with ID: ", serviceTaskId); @@ -146,6 +146,7 @@ export function movePolicies(modeler, newTargetId, policies) { onDemand: true, }); } + policy.di.id = policy.id + "_di"; }); } diff --git a/components/bpmn-q/modeler-component/extensions/quantme/replacement/QuantMETransformator.js b/components/bpmn-q/modeler-component/extensions/quantme/replacement/QuantMETransformator.js index c4cc18ae..7d0b3aae 100644 --- a/components/bpmn-q/modeler-component/extensions/quantme/replacement/QuantMETransformator.js +++ b/components/bpmn-q/modeler-component/extensions/quantme/replacement/QuantMETransformator.js @@ -325,7 +325,7 @@ async function replaceByFragment( let policies = getPolicies(modeler, task.id); console.log("Found %i polices attached to QuantME task!", policies.length); let attachersPlaceholder; - if (policies.length > 0) { + if (policies.length > 0 && replacementElement.$type !== "bpmn:SubProcess") { attachersPlaceholder = modeling.createShape( { type: "bpmn:Task" }, { x: 50, y: 50 }, @@ -367,71 +367,74 @@ async function replaceByFragment( "Replacement was ServiceTask or QuantME task. Attaching policies..." ); movePolicies(modeler, resultShape.id, policies); - } else { - if (resultShape.businessObject.$type === "bpmn:SubProcess") { - console.log( - "Attaching policies within subprocess: ", - resultShape.businessObject - ); + } - // get flow elements to check if they support policy attachment - let flowElements = resultShape.businessObject.flowElements; - console.log( - "Subprocess contains %i flow elements...", - flowElements.length - ); - flowElements = flowElements.filter( - (flowElement) => - (flowElement.$type === "bpmn:ServiceTask" && - flowElement.deploymentModelUrl) || - flowElement.$type.startsWith("quantme:") - ); - console.log( - "Found %i ServiceTasks or QuantME tasks...", - flowElements.length + let attachers = attachersPlaceholder.attachers; + + // if all policies are moved to the new target + if (attachers.length == 0) { + modeling.removeShape(attachersPlaceholder); + } + } + + if (resultShape.businessObject.$type === "bpmn:SubProcess") { + console.log( + "Attaching policies within subprocess: ", + resultShape.businessObject + ); + + // get flow elements to check if they support policy attachment + let flowElements = resultShape.businessObject.flowElements; + console.log("Subprocess contains %i flow elements...", flowElements.length); + flowElements = flowElements.filter( + (flowElement) => + (flowElement.$type === "bpmn:ServiceTask" && + flowElement.deploymentModelUrl) || + flowElement.$type.startsWith("quantme:") + ); + console.log( + "Found %i ServiceTasks or QuantME tasks...", + flowElements.length + ); + + flowElements.forEach((flowElement) => { + let task = elementRegistry.get(flowElement.id); + console.log("Adding policies to task: ", task); + policies.forEach((policy) => { + console.log("Adding policy : ", policy); + + if (policy.type === openToscaConsts.ON_DEMAND_POLICY) { + task.businessObject[openToscaConsts.ON_DEMAND] = "true"; + } + + let newPolicyShape = modeling.createShape( + { type: policy.type }, + { x: 50, y: 50 }, + task, + { attach: true } ); - flowElements.forEach((flowElement) => { - let task = elementRegistry.get(flowElement.id); - console.log("Adding policies to task: ", task); - policies.forEach((policy) => { - console.log("Adding policy : ", policy); - - if (policy.type === openToscaConsts.ON_DEMAND_POLICY) { - task.businessObject[openToscaConsts.ON_DEMAND] = "true"; - } - - let newPolicyShape = modeling.createShape( - { type: policy.type }, - { x: 50, y: 50 }, - task, - { attach: true } - ); - - // extract the properties of for the specific policy type - let properties = OpenTOSCAProps(newPolicyShape); - - if (properties !== undefined) { - let propertyEntries = {}; - properties.forEach((propertyEntry) => { - let entryId = propertyEntry.id; - propertyEntries[entryId] = policy.businessObject[entryId]; - }); - modeling.updateProperties( - elementRegistry.get(newPolicyShape.id), - propertyEntries - ); - } + // extract the properties of for the specific policy type + let properties = OpenTOSCAProps(newPolicyShape); + + if (properties !== undefined) { + let propertyEntries = {}; + properties.forEach((propertyEntry) => { + let entryId = propertyEntry.id; + propertyEntries[entryId] = policy.businessObject[entryId]; }); - }); - } else { - console.log( - "Type not supported for policy attachment: ", - resultShape.businessObject.$type - ); - } - } - modeling.removeShape(attachersPlaceholder); + modeling.updateProperties( + elementRegistry.get(newPolicyShape.id), + propertyEntries + ); + } + }); + }); + } else { + console.log( + "Type not supported for policy attachment: ", + resultShape.businessObject.$type + ); } return result["success"];