Skip to content

Commit

Permalink
feat(camunda8): support getVariable REST method
Browse files Browse the repository at this point in the history
  • Loading branch information
jwulf committed Jan 13, 2025
1 parent 39cc399 commit 8a7a5ee
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/__tests__/c8/rest/getVariable.rest.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import path from 'node:path'

import { CamundaRestClient } from '../../../c8/lib/CamundaRestClient'

let processDefinitionId: string
const restClient = new CamundaRestClient()

beforeAll(async () => {
const res = await restClient.deployResourcesFromFiles([
path.join('.', 'src', '__tests__', 'testdata', 'rest-get-variable.bpmn'),
])
processDefinitionId = res.processes[0].processDefinitionId
})

test('Can get a variable', (done) => {
restClient.createProcessInstance({
processDefinitionId,
variables: {
someNumberField: 8,
},
})
restClient.createJobWorker({
type: 'get-variable',
jobHandler: async (job) => {
// query variables to get the variable key
const variableKey = ''

const variable = await restClient.getVariable({
variableKey,
})
expect(variable.fullValue).toBe(8)
return job.complete().then((res) => {
done()
return res
})
},
worker: 'get-variable-worker',
timeout: 10000,
maxJobsToActivate: 10,
})
// .then(() => {
// restClient
// .getVariable({
// variableKey: 'someNumberField',
// })
// .then((variable) => {
// expect(variable).toBe(8)
// done()
// })
// })
})
48 changes: 48 additions & 0 deletions src/__tests__/testdata/rest-get-variable.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0vpl6p9" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.30.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.6.0">
<bpmn:process id="test-getVariable" name="Test getVariable method variable" isExecutable="true">
<bpmn:startEvent id="StartEvent_1" name="Test getVariable REST method">
<bpmn:outgoing>Flow_0xxocbj</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_0xxocbj" sourceRef="StartEvent_1" targetRef="Activity_1amwh0c" />
<bpmn:endEvent id="Event_07htauo" name="Tested getVariable REST method">
<bpmn:incoming>Flow_0fc59wl</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_0fc59wl" sourceRef="Activity_1amwh0c" targetRef="Event_07htauo" />
<bpmn:serviceTask id="Activity_1amwh0c" name="Get Variable">
<bpmn:extensionElements>
<zeebe:taskDefinition type="get-variable" />
</bpmn:extensionElements>
<bpmn:incoming>Flow_0xxocbj</bpmn:incoming>
<bpmn:outgoing>Flow_0fc59wl</bpmn:outgoing>
</bpmn:serviceTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="test-getVariable">
<bpmndi:BPMNShape id="StartEvent_1_di" bpmnElement="StartEvent_1">
<dc:Bounds x="182" y="102" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="161" y="145" width="79" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_07htauo_di" bpmnElement="Event_07htauo">
<dc:Bounds x="422" y="102" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="396" y="145" width="88" height="40" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_06l9sw4_di" bpmnElement="Activity_1amwh0c">
<dc:Bounds x="270" y="80" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_0xxocbj_di" bpmnElement="Flow_0xxocbj">
<di:waypoint x="218" y="120" />
<di:waypoint x="270" y="120" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0fc59wl_di" bpmnElement="Flow_0fc59wl">
<di:waypoint x="370" y="120" />
<di:waypoint x="422" y="120" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
11 changes: 11 additions & 0 deletions src/c8/lib/C8Dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,14 @@ export interface RestJob<
*/
readonly tenantId: string
}

export class GetVariableResponse {
variableKey!: string
scopeKey!: string
processInstanceKey!: string
name!: string
value!: string
fullValue!: string
tenantId!: string
isTruncated!: boolean
}
10 changes: 10 additions & 0 deletions src/c8/lib/CamundaRestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
DeployResourceResponse,
DeployResourceResponseDto,
FormDeployment,
GetVariableResponse,
JobUpdateChangeset,
MigrationRequest,
NewUserInfo,
Expand Down Expand Up @@ -931,6 +932,15 @@ export class CamundaRestClient {
)
}

public async getVariable(req: {
variableKey: string
}): Promise<GetVariableResponse> {
const headers = await this.getHeaders()
return this.rest.then((rest) =>
rest.get(`variables/${req.variableKey}`, { headers }).json()
) as Promise<GetVariableResponse>
}

private addJobMethods = <Variables, CustomHeaders>(
job: RestJob<Variables, CustomHeaders>
): RestJob<Variables, CustomHeaders> &
Expand Down

0 comments on commit 8a7a5ee

Please sign in to comment.