]> git.somenet.org - pub/jan/aic18.git/blob - service-website/src/services/CamundaService.js
added package-lock
[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     }
14
15     submitPdfForm(terms) {
16         const termsValue = [];
17         terms.forEach(term => {
18             termsValue.push({term});
19         });
20         const submitFormUrl = 'process-definition/key/sentiment-analysis/submit-form';
21         const data = {
22             variables: {
23                 terms: {
24                     value: JSON.stringify(termsValue),
25                     type: "Json",
26                 },
27             },
28         };
29         this.axiosInstance
30             .post(submitFormUrl, data)
31             .then(response => {
32                 const data = response.data;
33                 const id = data['id'];
34                 this.getPdfDownloadLink(id)
35             })
36             .catch(error => {
37                 console.log(error);
38             });
39     }
40
41     delay(ms) {
42         return new Promise((resolve, reject) => {
43             setTimeout(resolve, ms);
44         });
45     }
46
47     getPdfDownloadLink(id) {
48         const downloadUrl = this.baseUrl + 'process-instance/' + id + '/variables/reportPDF/data';
49         this.axiosInstance
50             .get(downloadUrl)
51             .then(response => {
52                 this.callback(downloadUrl);
53             })
54             .catch(error => {
55                 this.delay(5000)
56                     .then(() => {
57                         this.getPdfDownloadLink(id);
58                     });
59             });
60     }
61 }
62
63 export default CamundaService;