nexus site path corrected
[portal.git] / ecomp-portal-FE / client / app / services / userProfile / userProfile.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 'use strict';
22
23 (function () {
24     class UserProfileService {
25         constructor($q, $log, $http, conf, uuid,$rootScope) {
26             this.$q = $q;
27             this.$log = $log;
28             this.$http = $http;
29             this.conf = conf;
30             this.userProfile = null;
31             this.uuid = uuid;
32             this.$rootScope = $rootScope;
33         }
34
35
36         broadCastUpdatedUserInfo() {
37             this.$rootScope.$broadcast('handleUpdateUserInfo');
38         }
39
40         refreshUserBusinessCard(){
41             this.$rootScope.$broadcast('refreshUserBusinessCard');
42         }
43
44         getUserProfile() {
45             this.$log.info('UserProfileService::getUserProfile: get logged user profile');
46             let deferred = this.$q.defer();
47             let url = this.conf.api.userProfile;
48             // if(this.userProfile){
49             //     return deferred.resolve(this.userProfile);
50             // }
51             this.$http({
52                     method: "GET",
53                     url: url,
54                     cache: false,
55                     headers: {
56                         'X-ECOMP-RequestID':this.uuid.generate()
57                     }
58                 })
59                 .then( res => {
60                     // If response comes back as a redirected HTML page which IS NOT a success
61                         // this.$log.debug('Profile-service::getUserProfile: res: ', res);
62                     if (Object.keys(res.data).length == 0) {
63                         deferred.reject('UserProfileService::getUserProfile unexpected result: ', res);
64                     } else {
65                         this.userProfile = res.data;
66                         deferred.resolve(res.data);
67                     }
68                 })
69                 .catch( status => {
70                     deferred.reject(status);
71                 });
72             return deferred.promise;
73         }
74         
75         getSortedUserIdCombination(user1, user2) {
76                 
77                 var combination = "";
78                 if(user1<user2) {
79                         combination =  user1+"-"+user2;
80                 } else if (user1>user2){
81                         combination =  user2+"-"+user1;
82                 } else {
83                         
84                         return "self";
85                 }
86                 
87                 var collaborateUrl =  'opencollaboration?chat_id=' + combination ;
88                 
89                 return collaborateUrl;
90                 
91                 
92                 
93         }
94         
95         getCurrentUserProfile(loginId) {
96             this.$log.info('UserProfileService::getCurrentUserProfile: get logged user profile');
97             let deferred = this.$q.defer();
98             let url = this.conf.api.currentUserProfile + '/' + loginId;
99             // if(this.userProfile){
100             //     return deferred.resolve(this.userProfile);
101             // }
102             this.$http({
103                     method: "GET",
104                     url: url,
105                     cache: false,
106                     headers: {
107                         'X-ECOMP-RequestID':this.uuid.generate()
108                     }
109                 })
110                 .then( res => {
111                     // If response comes back as a redirected HTML page which IS NOT a success
112                         // this.$log.debug('Profile-service::getUserProfile: res: ', res);
113                     if (Object.keys(res.data).length == 0) {
114                         deferred.reject('UserProfileService::CurrentgetUserProfile unexpected result: ', res);
115                     } else {
116                         deferred.resolve(res.data);
117                     }
118                 })
119                 .catch( status => {
120                     deferred.reject(status);
121                 });
122             return deferred.promise;
123         }
124         
125         updateRemoteUserProfile(loginId,appId) {
126             this.$log.info('UserProfileService::updateRemoteUserProfile: update remote user profile');
127             let deferred = this.$q.defer();
128             let url = this.conf.api.updateRemoteUserProfile + "?loginId=" + loginId + '&appId=' + appId;
129             // if(this.userProfile){
130             //     return deferred.resolve(this.userProfile);
131             // }
132             this.$http({
133                     method: "GET",
134                     url: url,
135                     cache: false,
136                     headers: {
137                         'X-ECOMP-RequestID':this.uuid.generate()
138                     }
139                 })
140                 .then( res => {
141                     // If response comes back as a redirected HTML page which IS NOT a success
142                         // this.$log.debug('Profile-service::getUserProfile: res: ', res);
143                     if (Object.keys(res.data).length == 0) {
144                         deferred.reject('UserProfileService::update remote user profile unexpected result: ', res);
145                     } else {
146                         deferred.resolve(res.data);
147                     }
148                 })
149                 .catch( status => {
150                     deferred.reject(status);
151                 });
152             return deferred.promise;
153         }
154         
155         getFunctionalMenuStaticInfo() {
156             this.$log.info('UserProfileService::getFunctionalMenuStaticInfo: get logged user profile');
157             let deferred = this.$q.defer();
158             let url = this.conf.api.functionalMenuStaticInfo;
159
160             this.$http({
161                     method: "GET",
162                     url : url,
163                     cache: false,
164                     headers: {
165                         'X-ECOMP-RequestID':this.uuid.generate()
166                     }
167                 }).then( res => {
168                     if (Object.keys(res.data).length == 0) {
169                         deferred.reject("UserProfileService::getFunctionalMenuStaticInfo Failed");
170                     } else {
171                         this.userProfile = res.data;
172                         this.$log.info('UserProfileService::getFunctionalMenuStaticInfo Succeeded');
173                         deferred.resolve(res.data);
174                     }
175                 }).catch( status => {
176                     this.$log.error('UserProfileService::getFunctionalMenuStaticInfo error');
177                     deferred.reject(status);
178                 });
179             return deferred.promise;
180         }
181
182         resetFunctionalMenuStaticInfo() {
183             this.$log.info('UserProfileService::getFunctionalMenuStaticInfo: get logged user profile');
184             let deferred = this.$q.defer();
185             let url = this.conf.api.resetFunctionalMenuStaticInfo;
186
187             this.$http({
188                     method: "GET",
189                     url : url,
190                     cache: false,
191                     headers: {
192                         'X-ECOMP-RequestID':this.uuid.generate()
193                     }
194                 }).then( res => {
195                     if (res.data.message != "success") {
196                         deferred.reject("UserProfileService::resetFunctionalMenuStaticInfo Failed");
197                     } else {
198                         this.userProfile = res.data;
199                         this.$log.info('UserProfileService::resetFunctionalMenuStaticInfo Succeeded');
200                         deferred.resolve(res.data);
201                     }
202                 }).catch( status => {
203                     this.$log.error('UserProfileService::resetFunctionalMenuStaticInfo error');
204                     deferred.reject(status);
205                 });
206             return deferred.promise;
207         }
208
209
210         getActiveUser() {       
211             this.$log.info('ecomp::getActiveUser::get active users');
212             let deferred = this.$q.defer();
213             let url = this.conf.api.getActiveUser;
214             
215             this.$http({
216                     method: "GET",
217                     url : url,
218                     cache: false,
219                     headers: {
220                         'X-ECOMP-RequestID':this.uuid.generate()
221                     }
222                 }).then( res => {
223                     // If response comes back as a redirected HTML page which IS NOT a success
224                     if (Object.keys(res.data).length == 0) {
225                         deferred.reject("ecomp::userProfile-service::getActiveUser Failed");
226                     } else {
227                         this.$log.info('ecomp::userProfile-service::getActiveUser Succeeded');
228                         deferred.resolve(res.data);
229                     }
230                 }).catch( status => {
231                     this.$log.error('ecomp::getActiveUser error');
232                     deferred.reject(status);
233                 });
234             return deferred.promise;
235         }
236         
237     }
238     UserProfileService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4', '$rootScope'];
239     angular.module('ecompApp').service('userProfileService', UserProfileService)
240 })();