added svcapi ui and camunda code
[it/otf.git] / otf-frontend / server / src / feathers / services / test-execution-status / test-execution-status.class.js
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\r
3 #   Licensed under the Apache License, Version 2.0 (the "License");            #\r
4 #   you may not use this file except in compliance with the License.           #\r
5 #   You may obtain a copy of the License at                                    #\r
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\r
9 #   Unless required by applicable law or agreed to in writing, software        #\r
10 #   distributed under the License is distributed on an "AS IS" BASIS,          #\r
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
12 #   See the License for the specific language governing permissions and        #\r
13 #   limitations under the License.                                             #\r
14 ##############################################################################*/\r
15 \r
16 \r
17 const axios = require('axios');\r
18 const { parseString, Builder } = require('xml2js');\r
19 const pickleRick = require('pickle-rick');\r
20 const Response = require('http-response-object');\r
21 const request = require('request');\r
22 const util = require('../../../lib/otf-util');\r
23 \r
24 /* eslint-disable no-unused-vars */\r
25 class Service {\r
26         constructor (options) {\r
27                 this.options = options || {};\r
28         }\r
29 \r
30         async find (params) {\r
31 \r
32         }\r
33 \r
34         // Check process definition key to see if unique\r
35         async get (id, params) {\r
36                 // return await axios.get(this.options.app.get('camundaApi').url + 'otf/tcu/process-instance-completion-check/v1/' + id,\r
37                 //      {\r
38                 //              headers: {\r
39                 //                      Authorization: 'Basic ' +\r
40                 //              util.base64Encode(\r
41                 //                      this.options.app.get('serviceApi').aafId + ':' +\r
42                 //                      this.options.app.get('serviceApi').aafPassword)\r
43                 //              }\r
44                 //      })\r
45                 //      .then(result => {\r
46                 //              return new Response(200, {}, result.data);\r
47                 //      })\r
48                 //      .catch(err => {\r
49                 //              console.log(err);\r
50                 //      });\r
51                 \r
52                 let options = {\r
53                         url: this.options.app.get('camundaApi').url + 'otf/tcu/process-instance-completion-check/v1/' + id,\r
54                         headers: {\r
55                                 'Authorization': 'Basic ' + util.base64Encode(this.options.app.get('serviceApi').aafId + ':' + this.options.app.get('serviceApi').aafPassword),\r
56                                 'Content-Type': "application/json"\r
57                         },\r
58                         rejectUnauthorized: false\r
59                 }\r
60                 \r
61                 return await new Promise((resolve, reject) => {\r
62                         request.get(options, (err, res, body) => {\r
63                                 if(err){\r
64                                         reject(err);\r
65                                 }\r
66                                 if(res && res.body){\r
67                                         res.body = JSON.parse(res.body);\r
68                                 }\r
69                                 resolve(res);\r
70                         });\r
71                 }).then(\r
72                         res => {\r
73                                 return res;\r
74                         }\r
75                 ).catch(\r
76                         err => {\r
77                                 console.log(err);\r
78                         }\r
79                 );\r
80         }\r
81 \r
82         async create (data, params) {\r
83                 if (Array.isArray(data)) {\r
84                         return Promise.all(data.map(current => this.create(current, params)));\r
85                 }\r
86         }\r
87 \r
88         async update (id, data, params) {\r
89                 return data;\r
90         }\r
91 \r
92         async patch (id, data, params) {\r
93                 return data;\r
94         }\r
95 \r
96         async remove (id, params) {\r
97                 return { id };\r
98         }\r
99 \r
100         async parseAndUpload (data, params, method) {\r
101 \r
102         }\r
103 }\r
104 \r
105 module.exports = function (options) {\r
106         return new Service(options);\r
107 };\r
108 \r
109 module.exports.Service = Service;\r