Skip to content

Commit

Permalink
fix(bpmn-service): fix workflow model audit fields
Browse files Browse the repository at this point in the history
  • Loading branch information
akshatdubeysf committed Jun 28, 2021
1 parent 304402b commit 6403cb8
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 42 deletions.
4 changes: 1 addition & 3 deletions sandbox/workflow-ms-example/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {BPMTask} from '@sourceloop/bpmn-service/dist/bpm-task';
import path from 'path';
import {SayHelloCommand} from './commands/sayhello.command';
import {BpmnProvider} from './providers/bpmn.provider';
import {MySequence} from './sequence';

export {ApplicationConfig};

Expand All @@ -26,7 +25,6 @@ export class WorkflowHelloworldApplication extends BootMixin(
super(options);

// Set up the custom sequence
this.sequence(MySequence);

// Set up default home page
this.static('/', path.join(__dirname, '../public'));
Expand All @@ -39,7 +37,7 @@ export class WorkflowHelloworldApplication extends BootMixin(

this.bind(WorkflowServiceBindings.Config).toDynamicValue(() => {
return {
useCustomSequence: true,
useCustomSequence: false,
workflowEngineBaseUrl: process.env.CAMUNDA_URL,
};
});
Expand Down
19 changes: 17 additions & 2 deletions sandbox/workflow-ms-example/src/providers/bpmn.provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {bind, BindingScope, Provider, service} from '@loopback/core';
import {AnyObject} from '@loopback/repository';
import {HttpErrors} from '@loopback/rest';
import {WorflowManager, Workflow, WorkflowDto} from '@sourceloop/bpmn-service';
import {WorkflowVersion} from '../../../../services/bpmn-service/dist';
import {CamundaService} from '../services/camunda.service';

@bind({scope: BindingScope.TRANSIENT})
Expand Down Expand Up @@ -52,6 +54,10 @@ export class BpmnProvider implements Provider<WorflowManager> {
)[0] as AnyObject; //NOSONAR
version = processDefinition.version;
id = processDefinition.id;
} else {
throw new HttpErrors.BadRequest(
'Workflow with same name and definition already exists',
);
}
return {
version: version,
Expand Down Expand Up @@ -86,10 +92,19 @@ export class BpmnProvider implements Provider<WorflowManager> {
fileRef: workflowDto.bpmnFile,
};
},
deleteWorkflowById: async workflow => {
await this.camunda.delete(workflow.externalIdentifier);
deleteWorkflowById: async (workflow: Workflow) => {
await this.camunda.delete(
workflow.workflowVersions.map(
(version: WorkflowVersion) => version.externalWorkflowId as string,
),
);
return workflow;
},

deleteWorkflowVersionById: async (version: WorkflowVersion) => {
await this.camunda.deleteVersion(version.externalWorkflowId);
return version;
},
};
}
}
25 changes: 15 additions & 10 deletions sandbox/workflow-ms-example/src/services/camunda.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export class CamundaService {
this.baseUrl = config?.workflowEngineBaseUrl;
}

/*
* Add service methods here
*/
async create(name: string, file: Buffer) {
const form = new FormData();
form.append(`${name}.bpmn`, file.toString('utf-8'), {
Expand All @@ -32,16 +29,24 @@ export class CamundaService {
return this.http.postFormData(`${this.baseUrl}/deployment/create`, form);
}

async delete(id: string, cascade = true) {
return this.http.delete(`${this.baseUrl}/deployment/${id}`, {
query: {
cascade: cascade,
},
});
async delete(ids: string[]) {
return Promise.all(
ids.map(id =>
this.http.delete(`${this.baseUrl}/process-definition/${id}`, {
query: {
cascade: true,
},
}),
),
);
}

async deleteVersion(id: string) {
return this.http.delete(`${this.baseUrl}/process-definition/${id}`);
}

async get(id: string) {
return this.http.get(`${this.baseUrl}/deployment/${id}`);
return this.http.get(`${this.baseUrl}/process-definition/${id}`);
}

async execute(id: string, input: AnyObject) {
Expand Down
4 changes: 3 additions & 1 deletion sandbox/workflow-ms-example/src/services/http.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export class HttpClientService {

private async handleRes(res: Response) {
if (res.status === STATUS_CODE.OK) {
return res.json();
return res.json().catch(e => ({}));
} else if (res.status === STATUS_CODE.NO_CONTENT) {
return {};
} else {
throw new HttpErrors.BadRequest(await res.text());
}
Expand Down
46 changes: 42 additions & 4 deletions services/bpmn-service/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"security": [
{
"bearerAuth": []
"HTTPBearer": []
}
],
"responses": {
Expand Down Expand Up @@ -49,6 +49,44 @@
"operationId": "WorkflowController.startWorkflow"
}
},
"/workflow/{id}/{version}": {
"delete": {
"x-controller-name": "WorkflowController",
"x-operation-name": "deleteVersionById",
"tags": [
"WorkflowController"
],
"security": [
{
"HTTPBearer": []
}
],
"responses": {
"204": {
"description": "Workflow DELETE success"
}
},
"parameters": [
{
"name": "id",
"in": "path",
"schema": {
"type": "string"
},
"required": true
},
{
"name": "version",
"in": "path",
"schema": {
"type": "number"
},
"required": true
}
],
"operationId": "WorkflowController.deleteVersionById"
}
},
"/workflow/{id}": {
"patch": {
"x-controller-name": "WorkflowController",
Expand All @@ -58,7 +96,7 @@
],
"security": [
{
"bearerAuth": []
"HTTPBearer": []
}
],
"responses": {
Expand Down Expand Up @@ -118,7 +156,7 @@
],
"security": [
{
"bearerAuth": []
"HTTPBearer": []
}
],
"responses": {
Expand Down Expand Up @@ -148,7 +186,7 @@
],
"security": [
{
"bearerAuth": []
"HTTPBearer": []
}
],
"responses": {
Expand Down
107 changes: 95 additions & 12 deletions services/bpmn-service/openapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const inputBody = '{
"input": {}
}';
const headers = {
'Content-Type':'application/json'
'Content-Type':'application/json',
'Authorization':'Bearer {access-token}'
};

fetch('/workflow/{id}/execute',
Expand All @@ -68,7 +69,8 @@ const inputBody = {
"input": {}
};
const headers = {
'Content-Type':'application/json'
'Content-Type':'application/json',
'Authorization':'Bearer {access-token}'
};
fetch('/workflow/{id}/execute',
Expand Down Expand Up @@ -111,7 +113,74 @@ fetch('/workflow/{id}/execute',

<aside class="warning">
To perform this operation, you must be authenticated by means of one of the following methods:
None
HTTPBearer
</aside>

## WorkflowController.deleteVersionById

<a id="opIdWorkflowController.deleteVersionById"></a>

> Code samples
```javascript

const headers = {
'Authorization':'Bearer {access-token}'
};

fetch('/workflow/{id}/{version}',
{
method: 'DELETE',

headers: headers
})
.then(function(res) {
return res.json();
}).then(function(body) {
console.log(body);
});

```

```javascript--nodejs
const fetch = require('node-fetch');
const headers = {
'Authorization':'Bearer {access-token}'
};
fetch('/workflow/{id}/{version}',
{
method: 'DELETE',
headers: headers
})
.then(function(res) {
return res.json();
}).then(function(body) {
console.log(body);
});
```

`DELETE /workflow/{id}/{version}`

<h3 id="workflowcontroller.deleteversionbyid-parameters">Parameters</h3>

|Name|In|Type|Required|Description|
|---|---|---|---|---|
|id|path|string|true|none|
|version|path|number|true|none|

<h3 id="workflowcontroller.deleteversionbyid-responses">Responses</h3>

|Status|Meaning|Description|Schema|
|---|---|---|---|
|204|[No Content](https://tools.ietf.org/html/rfc7231#section-6.3.5)|Workflow DELETE success|None|

<aside class="warning">
To perform this operation, you must be authenticated by means of one of the following methods:
HTTPBearer
</aside>

## WorkflowController.updateById
Expand All @@ -127,7 +196,8 @@ const inputBody = '{
"inputSchema": {}
}';
const headers = {
'Content-Type':'application/json'
'Content-Type':'application/json',
'Authorization':'Bearer {access-token}'
};

fetch('/workflow/{id}',
Expand All @@ -152,7 +222,8 @@ const inputBody = {
"inputSchema": {}
};
const headers = {
'Content-Type':'application/json'
'Content-Type':'application/json',
'Authorization':'Bearer {access-token}'
};
fetch('/workflow/{id}',
Expand Down Expand Up @@ -196,7 +267,7 @@ fetch('/workflow/{id}',

<aside class="warning">
To perform this operation, you must be authenticated by means of one of the following methods:
None
HTTPBearer
</aside>

## WorkflowController.count
Expand Down Expand Up @@ -262,10 +333,15 @@ This operation does not require authentication
```javascript

const headers = {
'Authorization':'Bearer {access-token}'
};

fetch('/workflow/{id}',
{
method: 'DELETE'
method: 'DELETE',

headers: headers
})
.then(function(res) {
return res.json();
Expand All @@ -278,10 +354,15 @@ fetch('/workflow/{id}',
```javascript--nodejs
const fetch = require('node-fetch');
const headers = {
'Authorization':'Bearer {access-token}'
};
fetch('/workflow/{id}',
{
method: 'DELETE'
method: 'DELETE',
headers: headers
})
.then(function(res) {
return res.json();
Expand All @@ -307,7 +388,7 @@ fetch('/workflow/{id}',

<aside class="warning">
To perform this operation, you must be authenticated by means of one of the following methods:
None
HTTPBearer
</aside>

## WorkflowController.create
Expand All @@ -324,7 +405,8 @@ const inputBody = '{
}';
const headers = {
'Content-Type':'application/json',
'Accept':'application/json'
'Accept':'application/json',
'Authorization':'Bearer {access-token}'
};

fetch('/workflow',
Expand All @@ -350,7 +432,8 @@ const inputBody = {
};
const headers = {
'Content-Type':'application/json',
'Accept':'application/json'
'Accept':'application/json',
'Authorization':'Bearer {access-token}'
};
fetch('/workflow',
Expand Down Expand Up @@ -416,7 +499,7 @@ fetch('/workflow',

<aside class="warning">
To perform this operation, you must be authenticated by means of one of the following methods:
None
HTTPBearer
</aside>

## WorkflowController.find
Expand Down
Loading

0 comments on commit 6403cb8

Please sign in to comment.