]> git.somenet.org - pub/jan/aic18.git/blob - service-website/src/services/CamundaService.js
added spinner and waiting on camunda
[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.getPdfDownloadLink = this.getPdfDownloadLink.bind(this);
12         this.completeTask = this.completeTask.bind(this);
13     }
14
15     submitPdfForm(terms) {
16         const termsValue = [];
17         terms.forEach(term => {
18             termsValue.push({term});
19         });
20         console.log('termsValue: ', termsValue);
21         const submitFormUrl = 'process-definition/key/sentiment-analysis/submit-form';
22         const data = {
23             variables: {
24                 terms: {
25                     value: JSON.stringify(termsValue),
26                     type: "Json"
27                 }
28             }
29         };
30         this.axiosInstance
31             .post(submitFormUrl, data)
32             .then(response => {
33                 const data = response.data;
34                 console.log(data);
35                 const id = data['id'];
36                 this.getPdfDownloadLink(id)
37             })
38             .catch(error => {
39                 console.log(error);
40             })
41     }
42
43     delay(ms) {
44         return new Promise(function (resolve, reject) {
45             setTimeout(resolve, ms);
46         });
47     }
48
49     getPdfDownloadLink(id) {
50             const downloadUrl = this.baseUrl + 'process-instance/' + id + '/variables/reportPDF/data';
51             console.log('download: ' + downloadUrl);
52
53             this.axiosInstance
54                 .get(downloadUrl)
55                 .then(response => {
56                     const data = response.data;
57                     console.log(data);
58                     this.callback(downloadUrl);
59
60                 })
61                 .catch(error => {                
62                     console.log(error);
63                     this.delay(3000)
64                     .then(() => {
65                         this.getPdfDownloadLink(id);
66                     });   
67                     
68                 })
69             
70     }
71
72     completeTask(id) {
73         const completeTaskUrl = 'task/' + id + '/complete';
74         this.axiosInstance
75             .post(completeTaskUrl)
76             .then(response => {
77                 const data = response.data;
78                 console.log(data);
79             })
80             .catch(error => {
81                 console.log(error);
82             })
83     }
84 }
85
86 export default CamundaService;