]> git.somenet.org - pub/jan/aic18.git/blob - service-website/src/services/CamundaService.js
Enable CORS for localhost:3000 for React dev server
[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     getPdfDownloadLink(id) {
44         const downloadUrl = this.baseUrl + 'process-instance/' + id + '/variables/reportPDF/data';
45         console.log('download: ' + downloadUrl);
46         this.callback(downloadUrl);
47     }
48
49     completeTask(id) {
50         const completeTaskUrl = 'task/' + id + '/complete';
51         this.axiosInstance
52             .post(completeTaskUrl)
53             .then(response => {
54                 const data = response.data;
55                 console.log(data);
56             })
57             .catch(error => {
58                 console.log(error);
59             })
60     }
61 }
62
63 export default CamundaService;