Merge "Add proxy support in DockerFile"
[portal.git] / ecomp-portal-FE-common / client / app / services / recommendation / recommendation.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 wl849v on 12/14/2016.
22  */
23 'use strict';
24 (function () {
25     class RecommendationService {
26         constructor($q, $log, $http, conf, uuid,utilsService) {
27             this.$q = $q;
28             this.$log = $log;
29             this.$http = $http;
30             this.conf = conf;
31             this.uuid = uuid;
32             this.recommendationCount = {count:0};
33             this.refreshCount = 0;
34             this.maxCount = 0;
35             this.utilsService = utilsService;            
36         }       
37         getRecommendationCount() {
38                  return this.recommendationCount;
39          }
40         setRecommendationCount(count) {
41                 this.recommendationCount.count = count;
42         }
43         getRefreshCount() {
44             return this.refreshCount;
45         }
46         setRefreshCount(count){
47             this.refreshCount = count;
48         }
49         setMaxRefreshCount(count){
50             this.maxCount = count;
51         }
52         decrementRefreshCount(){
53             this.refreshCount = this.refreshCount - 1;
54         }
55         
56         
57         getRecommendations(){
58                 let deferred = this.$q.defer();
59             this.$http({
60                     method: "GET",
61                     cache: false,
62                     url: this.conf.api.getRecommendations,
63                     headers: {
64                         'X-ECOMP-RequestID':this.uuid.generate()
65                     }
66                 })
67                 .then( res => {
68                     // If response comes back as a redirected HTML page which IS NOT a success                  
69                     if (this.utilsService.isValidJSON(res.data)=== false) {
70                         this.$log.error('NotificationService::getRecommendations Failed');
71                         deferred.reject("NotificationService::getRecommendations Failed");
72                     } else {
73                         deferred.resolve(res);
74                     }
75                 })
76                 .catch( status => {
77                         this.$log.error('NotificationService::getRecommendations Failed', status);
78                     deferred.reject(status);
79                 });
80            
81             return deferred.promise;
82         }
83         
84        
85     }
86     RecommendationService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4','utilsService'];
87     angular.module('ecompApp').service('recommendationService', RecommendationService)
88 })();