Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
fixes Add support for deploying Forms #332
Browse files Browse the repository at this point in the history
  • Loading branch information
jwulf committed Oct 24, 2023
1 parent 38abf47 commit b739a98
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/__tests__/integration/Client-DeployResource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,14 @@ test('deploys a DMN table', async () => {
})
expect(result.deployments[0].decision.decisionKey).not.toBeNull()
})
test('deploys a Form', async () => {
const form = fs.readFileSync(
'./src/__tests__/testdata/form_1.form'
)
const result = await zbc.deployResource({
form,
name: 'form_1.form',
})
expect(result.deployments[0].form).not.toBeNull()
console.log(result.deployments[0].form)
})
43 changes: 43 additions & 0 deletions src/__tests__/testdata/form_1.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"components": [
{
"label": "Number",
"type": "number",
"layout": {
"row": "Row_1h8ufhy",
"columns": null
},
"id": "Field_1qlk4je",
"key": "field_19ab8r7"
},
{
"label": "Text area",
"type": "textarea",
"layout": {
"row": "Row_08n9bxz",
"columns": null
},
"id": "Field_1xphwg1",
"key": "field_0t0ghcb"
},
{
"label": "Checkbox",
"type": "checkbox",
"layout": {
"row": "Row_0shlcir",
"columns": null
},
"id": "Field_07ux5ad",
"key": "field_0oqjpgs"
}
],
"type": "default",
"id": "Form_07zfo8o",
"executionPlatform": "Camunda Cloud",
"executionPlatformVersion": "8.2.0",
"exporter": {
"name": "Camunda Modeler",
"version": "5.14.0"
},
"schemaVersion": 10
}
60 changes: 54 additions & 6 deletions src/zb/ZBClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,17 +766,25 @@ export class ZBClient extends TypedEmitter<typeof ConnectionStatusEvent> {
| { decisionFilename: string, tenantId?: string }
| { name: string; decision: Buffer, tenantId?: string },
): Promise<Grpc.DeployResourceResponse<Grpc.DecisionDeployment>>
public async deployResource(
resource:
| { formFilename: string, tenantId?: string }
| { name: string; form: Buffer, tenantId?: string }
): Promise<Grpc.DeployResourceResponse<Grpc.FormDeployment>>
async deployResource(
resource:
| { processFilename: string, tenantId?: string }
| { name: string; process: Buffer, tenantId?: string }
| { processFilename: string, tenantId?: string }
| { name: string; decision: Buffer, tenantId?: string }
| { decisionFilename: string, tenantId?: string },
| { decisionFilename: string, tenantId?: string }
| { name: string; form: Buffer, tenantId?: string }
| { formFilename: string, tenantId?: string }
): Promise<
Grpc.DeployResourceResponse<
| Grpc.ProcessDeployment
| Grpc.DecisionDeployment
| Grpc.DecisionRequirementsDeployment
| Grpc.FormDeployment
>
> {
if (!!resource.tenantId) {
Expand All @@ -794,6 +802,19 @@ export class ZBClient extends TypedEmitter<typeof ConnectionStatusEvent> {
maybeDecision: any
): maybeDecision is { decision: Buffer; name: string } =>
!!maybeDecision.decision
const isDecisionFilename = (
maybeDecisionFilename: any
): maybeDecisionFilename is { decisionFilename: string } =>
!!maybeDecisionFilename.decisionFilename
// default fall-through
/* const isForm = ( maybeForm: any ): maybeForm is { form: Buffer; name: string } =>
!!maybeForm.form
*/
const isFormFilename = (
maybeFormFilename: any
): maybeFormFilename is {formFilename: string} =>
!!maybeFormFilename.formFilename

if (isProcessFilename(resource)) {
const filename = resource.processFilename
const process = readFileSync(filename)
Expand All @@ -820,6 +841,20 @@ export class ZBClient extends TypedEmitter<typeof ConnectionStatusEvent> {
tenantId: resource.tenantId ?? this.tenantId
})
)
} else if (isDecisionFilename(resource)) {
const filename = resource.decisionFilename
const decision = readFileSync(filename)
return this.executeOperation('deployResource', () =>
this.grpc.deployResourceSync({
resources: [
{
name: filename,
content: decision,
},
],
tenantId: resource.tenantId ?? this.tenantId
})
)
} else if (isDecision(resource)) {
return this.executeOperation('deployResource', () =>
this.grpc.deployResourceSync({
Expand All @@ -832,20 +867,33 @@ export class ZBClient extends TypedEmitter<typeof ConnectionStatusEvent> {
tenantId: resource.tenantId ?? this.tenantId
})
)
} else {
const filename = resource.decisionFilename
const decision = readFileSync(filename)
} else if (isFormFilename(resource)) {
const filename = resource.formFilename
const form = readFileSync(filename)
return this.executeOperation('deployResource', () =>
this.grpc.deployResourceSync({
resources: [
{
name: filename,
content: decision,
content: form,
},
],
tenantId: resource.tenantId ?? this.tenantId
})
)
} else /* if (isForm(resource)) */ {
// default fall-through
return this.executeOperation('deployResource', () =>
this.grpc.deployResourceSync({
resources: [
{
name: resource.name,
content: resource.form
}
],
tenantId: resource.tenantId ?? this.tenantId
})
)
}
}

Expand Down

0 comments on commit b739a98

Please sign in to comment.