]> git.somenet.org - pub/jan/aic18.git/blob - service-website/src/services/CamundaService.js
updated design
[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                     this.callback(downloadUrl);
57                 })
58                 .catch(error => {                
59                     this.delay(5000)
60                     .then(() => {
61                         this.getPdfDownloadLink(id);
62                     });   
63                     
64                 })
65             
66     }
67
68     completeTask(id) {
69         const completeTaskUrl = 'task/' + id + '/complete';
70         this.axiosInstance
71             .post(completeTaskUrl)
72             .then(response => {
73                 const data = response.data;
74                 console.log(data);
75             })
76             .catch(error => {
77                 console.log(error);
78             })
79     }
80 }
81
82 export default CamundaService;