[PORTAL-7] Rebase
[portal.git] / ecomp-portal-FE-common / client / app / services / external-request-access-service / external-request-access-service.js
1 /*-\r
2  * ================================================================================\r
3  * ECOMP Portal\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ================================================================================\r
19  */\r
20 'use strict';\r
21 \r
22 (function () {\r
23     class ExternalRequestAccessService {\r
24         constructor($q, $log, $http, conf, uuid, utilsService) {\r
25             this.$q = $q;\r
26             this.$log = $log;\r
27             this.$http = $http;\r
28             this.conf = conf;\r
29             this.uuid = uuid;\r
30             this.utilsService = utilsService;\r
31         }\r
32 \r
33         getExternalRequestAccessServiceInfo() {\r
34             let deferred = this.$q.defer();\r
35             var _this = this;\r
36             let url = this.conf.api.externalRequestAccessSystem;\r
37             this.$http({\r
38                     method: "GET",\r
39                     cache: false,\r
40                     url: url,\r
41                     headers: {\r
42                         'X-ECOMP-RequestID':this.uuid.generate()\r
43                     }\r
44                 })\r
45                 .then( res => {\r
46                         if (res == null || res.data == null || _this.utilsService.isValidJSON(res.data) == false) {\r
47                         deferred.reject("ExternalRequestAccessService::getExternalRequestAccessServiceInfo Failed");\r
48                     }else{\r
49                     deferred.resolve(res.data);\r
50                     }\r
51                 })\r
52                 .catch( status => {\r
53                         this.$log.error('ExternalRequestAccessService::getExternalRequestAccessServiceInfo Failed', status);\r
54                     deferred.reject(status);\r
55                 });\r
56            \r
57             return deferred.promise;\r
58 \r
59         }\r
60     }\r
61     ExternalRequestAccessService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];\r
62     angular.module('ecompApp').service('ExternalRequestAccessService', ExternalRequestAccessService)\r
63 })();\r