added svcapi ui and camunda code
[it/otf.git] / otf-frontend / server / src / lib / music.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 config = require('../config/default.json');\r
18 const btoa = require('btoa');\r
19 \r
20 module.exports.parser = function (response) {\r
21         var jsonObject = {\r
22                 data: [],\r
23                 status: ''\r
24         };\r
25 \r
26         if (response.result) {\r
27                 // loop through musics rusults and make it into an array\r
28                 for (var key in response.result) {\r
29                         if (response.result.hasOwnProperty(key)) {\r
30                                 jsonObject.data.push(response.result[key]);\r
31                         }\r
32                 }\r
33         }\r
34 \r
35         // set store status in new reponse\r
36         jsonObject.status = response.status;\r
37 \r
38         return jsonObject;\r
39 };\r
40 \r
41 module.exports.stringifyParams = function (params) {\r
42         var string = '';\r
43         var count = 0;\r
44 \r
45         for (var key in params.query) {\r
46                 if (params.query.hasOwnProperty(key) && key[0] != '$') {\r
47                         if (count > 0) {\r
48                                 string += '&&';\r
49                         }\r
50                         string += key + '=' + params.query[key];\r
51                         count++;\r
52                 }\r
53         }\r
54 \r
55         return string;\r
56 };\r
57 \r
58 module.exports.musicHeaders = {\r
59         'Content-Type': 'application/json',\r
60         'ns': config.music.ns,\r
61         'X-minorVersion': config.music['X-minorVersion'],\r
62         'X-patchVersion': config.music['X-patchVersion'],\r
63         'Authorization': 'Basic ' + btoa(config.music.username + ':' + config.music.password)\r
64 };\r
65 \r
66 module.exports.musicUrl = config.music.url;\r