[PORTAL-7] Rebase
[portal.git] / ecomp-portal-FE-common / client / app / services / support / getAccess / get-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 GetAccessService {
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         getListOfApp(searchStr) {
33             //this.$log.info('GetAccessService::getListOfApp: get all app list');
34             let deferred = this.$q.defer();
35             //this.$log.info('GetAccessService::getListOfApp: searchStr', searchStr);
36             //this.$log.info('GetAccessService::getListOfApp: ', this.conf.api.listOfApp);
37             this.$http({
38                 method: 'GET',
39                 url: this.conf.api.listOfApp,
40                 params: {search:searchStr},
41                 cache: false
42             }).then( res => {
43                 // If response comes back as a redirected HTML page which IS NOT a success
44 //              this.$log.info('GetAccessService::getListOfApp response: ', res);
45                 if (this.utilsService.isValidJSON(res)== false) {
46                     deferred.reject('GetAccessService::getListOfApp: Failed');
47                 } else {
48                     // this.$log.debug('GetAccessService::getListOfApp: query results: ', res);
49                     // this.$log.info('GetAccessService::getListOfApp Succeeded');
50                     deferred.resolve(res);
51                 }
52             }).catch( status => {
53                 this.$log.error('GetAccessService::getListOfApp: query error: ',status);
54                 deferred.reject(status);
55             });
56             return deferred.promise;           
57         }
58
59     }
60     GetAccessService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
61     angular.module('ecompApp').service('getAccessService', GetAccessService)
62 })();