[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-FE-common / client / app / services / be-property-reader / be-property-reader.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 /**
21  * Created by nnaffar on 11/22/2015.
22  */
23 'use strict';
24
25 (function () {
26     class BeReaderService {
27         constructor($q, $log, $http, conf, uuid, utilsService) {
28             this.$q = $q;
29             this.$log = $log;
30             this.$http = $http;
31             this.conf = conf;
32             this.uuid = uuid;
33             this.utilsService = utilsService;
34         }
35
36         getProperty(property) {
37             let deferred = this.$q.defer();
38             //this.$log.info('BeReaderService::get all applications admins list');
39             
40             let url = this.conf.api.beProperty + "?key=" + property;
41             this.$http({
42                     method: "GET",
43                     cache: false,
44                     url: url,
45                     headers: {
46                         'X-ECOMP-RequestID':this.uuid.generate()
47                     }
48                 })
49                 .then( res => {
50                     // If response comes back as a redirected HTML page which IS NOT a success
51                     //if (this.utilsService.isValidJSON(res)=== false) {
52                     //  this.$log.error('BeReaderService::getAccountAdmins Failed');
53                     //    deferred.reject("BeReaderService::getAccountAdmins Failed");
54                     //} else {
55                         // this.$log.info('BeReaderService::getAccountAdmins Succeeded');
56                     deferred.resolve(res.data);
57                     //}
58                 })
59                 .catch( status => {
60                         this.$log.error('BeReaderService::getAccountAdmins Failed', status);
61                     deferred.reject(status);
62                 });
63            
64             return deferred.promise;
65
66         }
67     }
68     BeReaderService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
69     angular.module('ecompApp').service('beReaderService', BeReaderService)
70 })();