Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing context script task #41

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 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 { parseIoMappings } from './util/feelUtility';
import { parseVariables } from './util/feelUtility';
import {
getBusinessObject,
is
Expand All @@ -18,7 +18,7 @@ export default class ZeebeVariableResolver extends BaseVariableResolver {
super(eventBus, bpmnjs);
this._baseExtractor = getProcessVariables;

eventBus.on('variableResolver.parseVariables', HIGH_PRIORITY, this._resolveIoMappings);
eventBus.on('variableResolver.parseVariables', HIGH_PRIORITY, this._resolveVariables);
}

async getVariablesForElement(element, moddleElement) {
Expand Down Expand Up @@ -94,21 +94,21 @@ export default class ZeebeVariableResolver extends BaseVariableResolver {
}

/**
* Parsed the variables that have io-mappings and resolves the variable schema to kept the
* Parsed the variables and resolves the variable schema to kept the
* variable schema throughout the process.
*
* @param {Event} e
* @param {Object} context
* @param {Array<ProcessVariable>} context.variables
*/
_resolveIoMappings(e, context) {
_resolveVariables(e, context) {
const rawVariables = context.variables;

const mappedVariables = {};

for (const key in rawVariables) {
const variables = rawVariables[key];
const newVariables = parseIoMappings(variables);
const newVariables = parseVariables(variables);

mappedVariables[key] = [ ...variables, ...newVariables ];
}
Expand Down
52 changes: 44 additions & 8 deletions lib/zeebe/util/feelUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import { EntriesContext } from './VariableContext';
import { getExtensionElementsList } from '../../base/util/ExtensionElementsUtil';
import { getParents } from '../../base/util/scopeUtil';


export function parseIoMappings(variables) {
export function parseVariables(variables) {

const variablesToResolve = [];

// Step 1 - Parse all io mappings and populate all that don't have references
// to other variables io-mappings
// Step 1 - Parse all variables and populate all that don't have references
// to other variables
variables.forEach(variable => {
variable.origin.forEach(origin => {
const expressionDetails = getExpressionDetails(variable, origin);
Expand Down Expand Up @@ -159,6 +158,28 @@ export function getResultContext(expression, variables = {}) {
* @returns {{ expression: String, unresolved: Array<String> }}}
*/
function getExpressionDetails(variable, origin) {
const expression = getIoExpression(variable, origin) || getScriptExpression(variable, origin);

if (!expression) {
return;
}

const result = getResultContext(expression);

const unresolved = findUnresolvedVariables(result) ;

return { expression, unresolved };
}

/**
* Given a Variable and a specific origin, return the mapping expression for all
* input outputs mapping. Returns undefined if no mapping exists for the given origin.
*
* @param {ProcessVariable} variable
* @param {djs.model.Base} origin
* @returns { expression: String}
*/
function getIoExpression(variable, origin) {
const ioMapping = getExtensionElementsList(origin, 'zeebe:IoMapping')[0];

if (!ioMapping) {
Expand All @@ -182,13 +203,28 @@ function getExpressionDetails(variable, origin) {
return;
}

const expression = mapping.source.substring(1);
return mapping.source.substring(1);

const result = getResultContext(expression);
}

const unresolved = findUnresolvedVariables(result) ;
/**
* 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.
*
* @param {ProcessVariable} variable
* @param {djs.model.Base} origin
* @returns { expression: String}
*/
function getScriptExpression(variable, origin) {
const script = getExtensionElementsList(origin, 'zeebe:Script')[0];

return { expression, unresolved };
if (!script) {
return;
}

if (script.resultVariable === variable.name) {
return script.expression.substring(1);
}
}

/**
Expand Down
17 changes: 17 additions & 0 deletions test/fixtures/zeebe/mappings/script-task.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0qieuld" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.28.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.6.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:scriptTask id="Activity_0kxqawv" name="Script Task">
<bpmn:extensionElements>
<zeebe:script expression="={&#10; foo: 123&#10;}" resultVariable="scriptResult" />
</bpmn:extensionElements>
</bpmn:scriptTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="Activity_1g8b868_di" bpmnElement="Activity_0kxqawv">
<dc:Bounds x="160" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
30 changes: 30 additions & 0 deletions test/spec/zeebe/Mappings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import chainedMappingsXML from 'test/fixtures/zeebe/mappings/chained-mappings.bp
import primitivesXML from 'test/fixtures/zeebe/mappings/primitives.bpmn';
import mergingXML from 'test/fixtures/zeebe/mappings/merging.bpmn';
import scopeXML from 'test/fixtures/zeebe/mappings/scope.bpmn';
import scriptTaskXML from 'test/fixtures/zeebe/mappings/script-task.bpmn';

import VariableProvider from 'lib/VariableProvider';

Expand Down Expand Up @@ -316,6 +317,35 @@ describe('ZeebeVariableResolver - Variable Mappings', function() {

});


describe('Script Task', function() {

beforeEach(bootstrap(scriptTaskXML));


it('should add type annotation for script tasks', inject(async function(variableResolver, elementRegistry) {

// given
const root = elementRegistry.get('Process_1');

// when
const variables = await variableResolver.getVariablesForElement(root.businessObject);

// then
expect(variables).to.variableEqual([
{
name: 'scriptResult',
type: 'Context',
info: '',
entries: [
{ name: 'foo', type: 'Number', info: '123', entries: [] },
]
}
]);
}));

});

});

// helpers //////////////////////
Expand Down
Loading