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