From bcc5346c6d10db576a02477b38c4b32267e7b24a Mon Sep 17 00:00:00 2001 From: Abdul Ahad Date: Wed, 4 Dec 2024 19:58:59 +0500 Subject: [PATCH 1/6] test: added testcases --- test/fixtures/zeebe/mappings/scope.bpmn | 66 +++++++++++++++++++++++-- test/spec/zeebe/Mappings.spec.js | 26 +++++++++- 2 files changed, 86 insertions(+), 6 deletions(-) diff --git a/test/fixtures/zeebe/mappings/scope.bpmn b/test/fixtures/zeebe/mappings/scope.bpmn index 1445541..2a65f14 100644 --- a/test/fixtures/zeebe/mappings/scope.bpmn +++ b/test/fixtures/zeebe/mappings/scope.bpmn @@ -1,5 +1,11 @@ - + + + + + + + @@ -17,14 +23,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + - + - + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/spec/zeebe/Mappings.spec.js b/test/spec/zeebe/Mappings.spec.js index 9d88f81..c005146 100644 --- a/test/spec/zeebe/Mappings.spec.js +++ b/test/spec/zeebe/Mappings.spec.js @@ -7,6 +7,7 @@ import { is } from 'bpmn-js/lib/util/ModelUtil'; import { bootstrapModeler, inject } from 'test/TestHelper'; import { ZeebeVariableResolverModule } from 'lib/'; +import { getInputOutput } from '../../../lib/base/util/ExtensionElementsUtil'; import chainedMappingsXML from 'test/fixtures/zeebe/mappings/chained-mappings.bpmn'; import primitivesXML from 'test/fixtures/zeebe/mappings/primitives.bpmn'; @@ -283,7 +284,7 @@ describe('ZeebeVariableResolver - Variable Mappings', function() { it('should only resolve variables in scope', inject(async function(variableResolver, elementRegistry) { // given - const root = elementRegistry.get('Process_1'); + const root = elementRegistry.get('Participant_1'); const initialVariables = [ { name: 'globalVariable', @@ -298,7 +299,7 @@ describe('ZeebeVariableResolver - Variable Mappings', function() { }); // when - const variables = await variableResolver.getVariablesForElement(root.businessObject); + const variables = await variableResolver.getVariablesForElement(root.businessObject.processRef); // then expect(variables).to.variableEqual([ @@ -316,6 +317,27 @@ describe('ZeebeVariableResolver - Variable Mappings', function() { ]); })); + + it('should only resolve the script result variable if input and result variable names conflict', inject(async function(variableResolver, elementRegistry) { + + // given + const root = elementRegistry.get('Activity_1'); + const bo = root.businessObject; + const output = getInputOutput(bo).outputParameters[0]; + + // when + const variables = await variableResolver.getVariablesForElement(root.businessObject, output); + + // then + expect(variables).to.variableEqual([ + { + name: 'foo', + type: '', + info: '', + } + ]); + })); + }); From 1b3ba3399dff31304ec2a959152f195f2a6d2b59 Mon Sep 17 00:00:00 2001 From: Abdul Ahad Date: Tue, 10 Dec 2024 22:35:15 +0500 Subject: [PATCH 2/6] fix: script resultVariable on priority when script and input co-exist --- lib/zeebe/VariableResolver.js | 42 ++++--------------------------- lib/zeebe/util/feelUtility.js | 47 ++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 38 deletions(-) diff --git a/lib/zeebe/VariableResolver.js b/lib/zeebe/VariableResolver.js index 996c9fe..5a032a6 100644 --- a/lib/zeebe/VariableResolver.js +++ b/lib/zeebe/VariableResolver.js @@ -1,6 +1,9 @@ import { getProcessVariables } from '@bpmn-io/extract-process-variables/zeebe'; import { BaseVariableResolver } from '../base/VariableResolver'; -import { parseVariables } from './util/feelUtility'; +import { + parseVariables, + getElementNamesToRemove +} from './util/feelUtility'; import { getBusinessObject, is @@ -36,42 +39,7 @@ export default class ZeebeVariableResolver extends BaseVariableResolver { return variables; } - const namesToFilter = []; - - // Input: remove all inputs defined after the current input definition - if (is(moddleElement, 'zeebe:Input')) { - const allInputs = inputOutput.inputParameters; - - const inputsToFilter = - allInputs - .slice(allInputs.indexOf(moddleElement)) - .map(o => o.target); - - namesToFilter.push(...inputsToFilter); - } - - const allOutputs = inputOutput.outputParameters; - - // Output: remove all outputs defined after the current output definition - if (is(moddleElement, 'zeebe:Output')) { - - // Get all output mappings defined after the current element, including own name - const outputsToFilter = allOutputs - .slice(allOutputs.indexOf(moddleElement)) - .map(o => o.target); - - namesToFilter.push(...outputsToFilter); - } - - // Input or general property: remove all outputs - else if (allOutputs) { - - // Input or execution-related element, remove all outputs - const outputsToFilter = allOutputs - .map(o => o.target); - - namesToFilter.push(...outputsToFilter); - } + const namesToFilter = getElementNamesToRemove(moddleElement, inputOutput); return variables.filter(v => { diff --git a/lib/zeebe/util/feelUtility.js b/lib/zeebe/util/feelUtility.js index 57c89b5..24fd387 100644 --- a/lib/zeebe/util/feelUtility.js +++ b/lib/zeebe/util/feelUtility.js @@ -6,6 +6,7 @@ import { import { EntriesContext } from './VariableContext'; import { getExtensionElementsList } from '../../base/util/ExtensionElementsUtil'; import { getParents } from '../../base/util/scopeUtil'; +import { is } from 'bpmn-js/lib/util/ModelUtil'; export function parseVariables(variables) { @@ -158,7 +159,7 @@ export function getResultContext(expression, variables = {}) { * @returns {{ expression: String, unresolved: Array }}} */ function getExpressionDetails(variable, origin) { - const expression = getIoExpression(variable, origin) || getScriptExpression(variable, origin); + const expression = getScriptExpression(variable, origin) || getIoExpression(variable, origin); if (!expression) { return; @@ -374,4 +375,48 @@ function filterForScope(context, variable) { } return scopedResults; +} + +/** + * Remove input/output element name after current definition + */ +export function getElementNamesToRemove(moddleElement, inputOutput) { + const namesToFilter = []; + + // Input: remove all inputs defined after the current input definition + if (is(moddleElement, 'zeebe:Input')) { + const allInputs = inputOutput.inputParameters; + + const inputsToFilter = + allInputs + .slice(allInputs.indexOf(moddleElement)) + .map(o => o.target); + + namesToFilter.push(...inputsToFilter); + } + + const allOutputs = inputOutput.outputParameters; + + // Output: remove all outputs defined after the current output definition + if (is(moddleElement, 'zeebe:Output')) { + + // Get all output mappings defined after the current element, including own name + const outputsToFilter = allOutputs + .slice(allOutputs.indexOf(moddleElement)) + .map(o => o.target); + + namesToFilter.push(...outputsToFilter); + } + + // Input or general property: remove all outputs + else if (allOutputs) { + + // Input or execution-related element, remove all outputs + const outputsToFilter = allOutputs + .map(o => o.target); + + namesToFilter.push(...outputsToFilter); + } + + return namesToFilter; } \ No newline at end of file From fe1ee89c0c989d8fd7a92958c74f9bcceb03d5f2 Mon Sep 17 00:00:00 2001 From: Abdul Ahad Date: Mon, 16 Dec 2024 21:39:26 +0500 Subject: [PATCH 3/6] fix: latest io mapping overwrite when duplicates --- lib/zeebe/util/feelUtility.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/zeebe/util/feelUtility.js b/lib/zeebe/util/feelUtility.js index 24fd387..ebbbb92 100644 --- a/lib/zeebe/util/feelUtility.js +++ b/lib/zeebe/util/feelUtility.js @@ -198,7 +198,7 @@ function getIoExpression(variable, origin) { return; } - const mapping = mappings.find(mapping => mapping.target === variable.name); + const mapping = mappings.filter(mapping => mapping.target === variable.name).pop(); if (!mapping || !mapping.source) { return; From cb2909fc92700f0ad452ec46d67692d7fe27069b Mon Sep 17 00:00:00 2001 From: Abdul Ahad Date: Mon, 23 Dec 2024 20:01:17 +0500 Subject: [PATCH 4/6] test: scope bpmn --- test/fixtures/zeebe/mappings/scope.bpmn | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/fixtures/zeebe/mappings/scope.bpmn b/test/fixtures/zeebe/mappings/scope.bpmn index 2a65f14..48c036a 100644 --- a/test/fixtures/zeebe/mappings/scope.bpmn +++ b/test/fixtures/zeebe/mappings/scope.bpmn @@ -5,6 +5,7 @@ + @@ -51,6 +52,27 @@ + + + + + + + + + + + + + + + + + + + + + @@ -84,6 +106,16 @@ + + + + + + + + + + From 16105429ad6763c38b4689ca3477d8250d4e3516 Mon Sep 17 00:00:00 2001 From: Abdul Ahad Date: Mon, 23 Dec 2024 23:19:30 +0500 Subject: [PATCH 5/6] test: added testcase for input output same --- test/spec/zeebe/Mappings.spec.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/spec/zeebe/Mappings.spec.js b/test/spec/zeebe/Mappings.spec.js index c005146..86b0444 100644 --- a/test/spec/zeebe/Mappings.spec.js +++ b/test/spec/zeebe/Mappings.spec.js @@ -338,6 +338,26 @@ describe('ZeebeVariableResolver - Variable Mappings', function() { ]); })); + it('should only resolve the output variable if script result variable and output names conflict', inject(async function(variableResolver, elementRegistry) { + + // given + const root = elementRegistry.get('Activity_5a'); + const bo = root.businessObject; + const output = getInputOutput(bo).outputParameters[1]; + + // when + const variables = await variableResolver.getVariablesForElement(root.businessObject, output); + + // then + expect(variables).to.variableEqual([ + { + name: 'foo', + type: '', + info: '', + } + ]); + })); + }); From 8adf68d33f115f3da790ca31c77ca9ba0b0f67b9 Mon Sep 17 00:00:00 2001 From: Abdul Ahad Date: Mon, 23 Dec 2024 23:20:05 +0500 Subject: [PATCH 6/6] fix: same input output names filter only output names --- lib/zeebe/util/feelUtility.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/zeebe/util/feelUtility.js b/lib/zeebe/util/feelUtility.js index ebbbb92..574feae 100644 --- a/lib/zeebe/util/feelUtility.js +++ b/lib/zeebe/util/feelUtility.js @@ -12,6 +12,10 @@ export function parseVariables(variables) { const variablesToResolve = []; + // remove same elements // TODO :Step 1 + filterSameVariableNames(variables); + + // Step 1 - Parse all variables and populate all that don't have references // to other variables variables.forEach(variable => { @@ -419,4 +423,19 @@ export function getElementNamesToRemove(moddleElement, inputOutput) { } return namesToFilter; +} + +function filterSameVariableNames(variables) { + const duplicateNames = variables.filter((item, index, self) => + self.findIndex(t => t.name === item.name) !== index + ).map(x => x.name); + + // removing redundant entries for input mappings if output mappings exists + duplicateNames.forEach(duplicate => { + variables.splice( + variables.findIndex(variable => + variable.name === duplicate && + variable.origin[0].id === variable.scope.id) + ,1); + }); } \ No newline at end of file