Skip to content

Commit

Permalink
Fix/subprocess handling with QRM (#61)
Browse files Browse the repository at this point in the history
* expand/collapse subprocess based on replacement in QRM

* remove isExpanded attribute from shapes

* handle different namespace

* Update package-lock.json

* set isExpanded of nested subprocess

* remove isExpand attribute also from nested subprocess,

* fix test

* remove isexpanded from nested subprocess

* fix collapsed subprocess

* change repo for maxcut qrm

* fix replacement of collapsed subprocess

* enable setting camunda_endpoint via env_vars

* remove top-level isexpanded attribute

* Remove unused method and fix method comment

* Fix typo in method name

---------

Co-authored-by: Benjamin Weder <benjamin.weder@iaas.uni-stuttgart.de>
Co-authored-by: mbeisel <beiselmn@gmail.com>
  • Loading branch information
3 people authored Aug 25, 2023
1 parent 3e9ac78 commit 64100ce
Show file tree
Hide file tree
Showing 10 changed files with 432 additions and 107 deletions.
31 changes: 21 additions & 10 deletions components/bpmn-q/modeler-component/editor/ModelerHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,38 @@ export function createTempModeler() {
}

/**
* Create a Modeler with only Camunda native extensions and no additional modules
* Creates a modeler with all additional modules and extension moddles from all active plugins which is not
* saved in as the current modeler instance and load the given xml into it.
*
* @param xml the xml representing the BPMN diagram to load
*
* @returns the created bpmn-js modeler
* @returns the created modeler
*/
export function createLightweightModeler() {
return new BpmnModeler({
moddleExtensions: getExtensions(),
});
export async function createTempModelerFromXml(xml) {
// create new modeler with the custom QuantME extensions
const bpmnModeler = createTempModeler();

// import the xml containing the definitions
try {
await bpmnModeler.importXML(xml);
return bpmnModeler;
} catch (err) {
console.error(err);
}
return undefined;
}

/**
* Creates a modeler with all additional modules and extension moddles from all active plugins which is not
* saved in as the current modeler instance and load the given xml into it.
* Creates a modeler with all additional modules and extension moddles from all active plugins which is
* saved as the current modeler instance and load the given xml into it.
*
* @param xml the xml representing the BPMN diagram to load
*
* @returns the created modeler
*/
export async function createTempModelerFromXml(xml) {
export async function createModelerFromXml(xml) {
// create new modeler with the custom QuantME extensions
const bpmnModeler = createTempModeler();
const bpmnModeler = createModeler();

// import the xml containing the definitions
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {isFlowLikeElement} from './ModellingUtilities';
import {getDi, is} from 'bpmn-js/lib/util/ModelUtil';
import { isFlowLikeElement } from './ModellingUtilities';
import { getDi, is } from 'bpmn-js/lib/util/ModelUtil';

/**
* Insert the given element and all child elements into the diagram
Expand Down Expand Up @@ -30,18 +30,18 @@ export function insertShape(definitions, parent, newElement, idMap, replace, mod
if (replace) {

// replace old element to retain attached sequence flow, associations, data objects, ...
element = bpmnReplace.replaceElement(elementRegistry.get(oldElement.id), {type: newElement.$type});
element = bpmnReplace.replaceElement(elementRegistry.get(oldElement.id), { type: newElement.$type });
} else {

// create new shape for this element
element = modeling.createShape({type: newElement.$type}, {x: 50, y: 50}, parent, {});
element = modeling.createShape({ type: newElement.$type }, { x: 50, y: 50 }, parent, {});
}
} else {

// create connection between two previously created elements
let sourceElement = elementRegistry.get(idMap[newElement.sourceRef.id]);
let targetElement = elementRegistry.get(idMap[newElement.targetRef.id]);
element = modeling.connect(sourceElement, targetElement, {type: newElement.$type});
element = modeling.connect(sourceElement, targetElement, { type: newElement.$type });
}

// store id to create sequence flows
Expand All @@ -52,13 +52,11 @@ export function insertShape(definitions, parent, newElement, idMap, replace, mod

// get the shape element related to the subprocess
let shape = getDi(element);
shape.isExpanded = true;

// TODO: fix the following if, as the access to the DI of the new element is not possible with the current BPMN-JS version
/*if (shape && shape.isExpanded) {
// expand the new element
elementRegistry.get(element.id).businessObject.di.isExpanded = true;
}*/
// expand the replacement subprocess if the detector subprocess was expanded
if (shape && (newElement.isExpanded === 'true')) {
shape.isExpanded = true;
}

// preserve messages defined in ReceiveTasks
} else if (newElement.$type === 'bpmn:ReceiveTask' && newElement.messageRef) {
Expand All @@ -71,21 +69,21 @@ export function insertShape(definitions, parent, newElement, idMap, replace, mod
let message = bpmnFactory.create('bpmn:Message');
message.name = oldMessage.name;
definitions.rootElements.push(message);
modeling.updateProperties(element, {'messageRef': message});
modeling.updateProperties(element, { 'messageRef': message });

// store id if other receive tasks reference the same message
idMap[oldMessage.id] = message.id;
} else {

// reuse already created message and add it to receive task
modeling.updateProperties(element, {'messageRef': idMap[oldMessage.id]});
modeling.updateProperties(element, { 'messageRef': idMap[oldMessage.id] });
}
}

// add element to which a boundary event is attached
if (newElement.$type === 'bpmn:BoundaryEvent') {
let hostElement = elementRegistry.get(idMap[newElement.attachedToRef.id]);
modeling.updateProperties(element, {'attachedToRef': hostElement.businessObject});
modeling.updateProperties(element, { 'attachedToRef': hostElement.businessObject });
element.host = hostElement;
}

Expand All @@ -109,7 +107,7 @@ export function insertShape(definitions, parent, newElement, idMap, replace, mod
}

// return success flag and idMap with id mappings of this element and all children
return {success: success, idMap: idMap, element: element};
return { success: success, idMap: idMap, element: element };
}

/**
Expand Down Expand Up @@ -162,7 +160,7 @@ export function insertChildElements(definitions, parent, newElement, idMap, mode
}
}

return {success: success, idMap: idMap, element: parent};
return { success: success, idMap: idMap, element: parent };
}

/**
Expand Down Expand Up @@ -229,7 +227,7 @@ export function getAllElementsInProcess(processBo, elementRegistry, elementType)
for (let i = 0; i < flowElementBos.length; i++) {
let flowElementBo = flowElementBos[i];
if (flowElementBo.$type && flowElementBo.$type === elementType) {
elements.push({element: flowElementBo, parent: processElement});
elements.push({ element: flowElementBo, parent: processElement });
}

// recursively retrieve service tasks if subprocess is found
Expand Down Expand Up @@ -258,7 +256,7 @@ export function getAllElementsForProcess(processBo, elementRegistry, elementType
for (let i = 0; i < flowElements.length; i++) {
let flowElement = flowElements[i];
if (is(flowElement, elementType)) {
elements.push({element: flowElement, parent: processElement});
elements.push({ element: flowElement, parent: processElement });
}
}
return elements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const defaultConfig = {
quantmeDataConfigurationsEndpoint: process.env.DATA_CONFIG,
opentoscaEndpoint: process.env.OPENTOSCA_ENDPOINT,
wineryEndpoint: process.env.WINERY_ENDPOINT,
camundaEndpoint: process.env.CAMUNDA_ENDPOINT,
nisqAnalyzerEndpoint: process.env.NISQ_ANALYZER_ENDPOINT,
githubToken: process.env.GITHUB_TOKEN,
transformationFrameworkEndpoint: process.env.TRANSFORMATION_FRAMEWORK_ENDPOINT,
Expand Down
Loading

0 comments on commit 64100ce

Please sign in to comment.