Skip to content

Commit

Permalink
feat: parse zeebe script
Browse files Browse the repository at this point in the history
  • Loading branch information
marstamm committed Oct 24, 2024
1 parent 0351f28 commit 210043d
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 3 deletions.
28 changes: 25 additions & 3 deletions lib/zeebe/util/feelUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ export function getResultContext(expression, variables = {}) {
* @returns {{ expression: String, unresolved: Array<String> }}}
*/
function getExpressionDetails(variable, origin) {
const expression = getScriptExpression(variable, origin) || getIoExpression(variable, origin);

if (!expression) {
return;
}

const result = getResultContext(expression);

const unresolved = findUnresolvedVariables(result) ;

return { expression, unresolved };
}


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

if (!ioMapping) {
Expand All @@ -183,12 +198,19 @@ function getExpressionDetails(variable, origin) {
}

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

const result = getResultContext(expression);
function getScriptExpression(variable, origin) {
const script = getExtensionElementsList(origin, 'zeebe:Script')[0];

const unresolved = findUnresolvedVariables(result) ;
if (!script) {
return;
}

return { expression, unresolved };
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>
29 changes: 29 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,34 @@ 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

0 comments on commit 210043d

Please sign in to comment.