Skip to content

Commit

Permalink
squash: sep out logic for io and script
Browse files Browse the repository at this point in the history
  • Loading branch information
abdul99ahad committed Dec 11, 2024
1 parent 43276ba commit aef4558
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/zeebe/VariableResolver.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getProcessVariables } from '@bpmn-io/extract-process-variables/zeebe';
import { BaseVariableResolver } from '../base/VariableResolver';
import { parseVariables, getScriptExpression, getIoExpression } from './util/feelUtility';
import { parseVariables, isScriptResultVariable, isOutputVariable } from './util/feelUtility';
import {
getBusinessObject,
is
Expand Down Expand Up @@ -29,14 +29,14 @@ export default class ZeebeVariableResolver extends BaseVariableResolver {
// filter based on resultVariable if output exists.

const outputExists = variables.some(variable =>
getIoExpression(variable, variable.origin[0]) && variable.scope === bo
isOutputVariable(variable, variable.origin[0]) && variable.scope === bo
);

if (outputExists && !moddleElement) {

// remove script variable if exists from variables.
const filteredVariables = variables.filter(
variable => !getScriptExpression(variable, variable.origin[0])
variable => !isScriptResultVariable(variable, variable.origin[0])
);

return filteredVariables;
Expand Down
37 changes: 36 additions & 1 deletion lib/zeebe/util/feelUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,31 @@ export function getIoExpression(variable, origin) {

}

export function isOutputVariable(variable, origin) {
const ioMapping = getExtensionElementsList(origin, 'zeebe:IoMapping')[0];

if (!ioMapping) {
return;
}

let mappings;
if (origin != variable.scope) {
mappings = ioMapping.outputParameters;
}

if (!mappings) {
return;
}

const mapping = mappings.find(mapping => mapping.target === variable.name);
if (mapping) {
return true;
}

return;
}


/**
* Given a Variable and a specific origin, return the mapping expression for script
* task result variable. Returns undefined if no mapping exists for the given origin.
Expand All @@ -218,7 +243,7 @@ export function getIoExpression(variable, origin) {
export function getScriptExpression(variable, origin) {
const script = getExtensionElementsList(origin, 'zeebe:Script')[0];

if (!script) {
if (!script || !script.expression) {
return;
}

Expand All @@ -227,6 +252,16 @@ export function getScriptExpression(variable, origin) {
}
}

export function isScriptResultVariable(variable, origin) {
const script = getExtensionElementsList(origin, 'zeebe:Script')[0];

if (script && script.resultVariable === variable.name) {
return true;
}

return;
}

/**
* Traverses the parseTree and returns all `VariableName` nodes with no value
*
Expand Down

0 comments on commit aef4558

Please sign in to comment.