]> git.somenet.org - pub/jan/aic18.git/blob - service-website/src/services/CamundaService.js
fixed merge conflicts
[pub/jan/aic18.git] / service-website / src / services / CamundaService.js
1 import axios from "axios";
2
3 class CamundaService {
4     constructor(callback) {
5         this.callback = callback;
6         this.baseUrl = 'http://localhost:8085/engine-rest/';
7         this.axiosInstance = axios.create({
8             baseURL: this.baseUrl,
9         });
10         this.submitPdfForm = this.submitPdfForm.bind(this);
11         this.delay = this.delay.bind(this);
12         this.getPdfDownloadLink = this.getPdfDownloadLink.bind(this);
13         this.completeTask = this.completeTask.bind(this);
14     }
15
16     submitPdfForm(terms) {
17         const termsValue = [];
18         terms.forEach(term => {
19             termsValue.push({term});
20         });
21         console.log('termsValue: ', termsValue);
22         const submitFormUrl = 'process-definition/key/sentiment-analysis/submit-form';
23         const data = {
24             variables: {
25                 terms: {
26                     value: JSON.stringify(termsValue),
27                     type: "Json"
28                 }
29             }
30         };
31         this.axiosInstance
32             .post(submitFormUrl, data)
33             .then(response => {
34                 const data = response.data;
35                 console.log(data);
36                 const id = data['id'];
37                 this.getPdfDownloadLink(id)
38             })
39             .catch(error => {
40                 console.log(error);
41             })
42     }
43
44     delay(ms) {
45         return new Promise((resolve, reject) => {
46             setTimeout(resolve, ms);
47         });
48     }
49
50     getPdfDownloadLink(id) {
51         const downloadUrl = this.baseUrl + 'process-instance/' + id + '/variables/reportPDF/data';
52         console.log('download: ' + downloadUrl);
53
54         this.axiosInstance
55             .get(downloadUrl)
56             .then(response => {
57                 this.callback(downloadUrl);
58             })
59             .catch(error => {
60                 this.delay(5000)
61                     .then(() => {
62                         this.getPdfDownloadLink(id);
63                     });
64             })
65     }
66
67     completeTask(id) {
68         const completeTaskUrl = 'task/' + id + '/complete';
69         this.axiosInstance
70             .post(completeTaskUrl)
71             .then(response => {
72                 const data = response.data;
73                 console.log(data);
74             })
75             .catch(error => {
76                 console.log(error);
77             })
78     }
79 }
80
81 export default CamundaService;