2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
24 class UserProfileService {
25 constructor($q, $log, $http, conf, uuid,$rootScope) {
30 this.userProfile = null;
32 this.$rootScope = $rootScope;
36 broadCastUpdatedUserInfo() {
37 this.$rootScope.$broadcast('handleUpdateUserInfo');
40 refreshUserBusinessCard(){
41 this.$rootScope.$broadcast('refreshUserBusinessCard');
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);
56 'X-ECOMP-RequestID':this.uuid.generate()
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);
65 this.userProfile = res.data;
66 deferred.resolve(res.data);
70 deferred.reject(status);
72 return deferred.promise;
75 getSortedUserIdCombination(user1, user2) {
79 combination = user1+"-"+user2;
80 } else if (user1>user2){
81 combination = user2+"-"+user1;
87 var collaborateUrl = 'opencollaboration?chat_id=' + combination ;
89 return collaborateUrl;
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);
107 'X-ECOMP-RequestID':this.uuid.generate()
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);
116 deferred.resolve(res.data);
120 deferred.reject(status);
122 return deferred.promise;
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);
137 'X-ECOMP-RequestID':this.uuid.generate()
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);
146 deferred.resolve(res.data);
150 deferred.reject(status);
152 return deferred.promise;
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;
165 'X-ECOMP-RequestID':this.uuid.generate()
168 if (Object.keys(res.data).length == 0) {
169 deferred.reject("UserProfileService::getFunctionalMenuStaticInfo Failed");
171 this.userProfile = res.data;
172 this.$log.info('UserProfileService::getFunctionalMenuStaticInfo Succeeded');
173 deferred.resolve(res.data);
175 }).catch( status => {
176 this.$log.error('UserProfileService::getFunctionalMenuStaticInfo error');
177 deferred.reject(status);
179 return deferred.promise;
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;
192 'X-ECOMP-RequestID':this.uuid.generate()
195 if (res.data.message != "success") {
196 deferred.reject("UserProfileService::resetFunctionalMenuStaticInfo Failed");
198 this.userProfile = res.data;
199 this.$log.info('UserProfileService::resetFunctionalMenuStaticInfo Succeeded');
200 deferred.resolve(res.data);
202 }).catch( status => {
203 this.$log.error('UserProfileService::resetFunctionalMenuStaticInfo error');
204 deferred.reject(status);
206 return deferred.promise;
211 this.$log.info('ecomp::getActiveUser::get active users');
212 let deferred = this.$q.defer();
213 let url = this.conf.api.getActiveUser;
220 'X-ECOMP-RequestID':this.uuid.generate()
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");
227 this.$log.info('ecomp::userProfile-service::getActiveUser Succeeded');
228 deferred.resolve(res.data);
230 }).catch( status => {
231 this.$log.error('ecomp::getActiveUser error');
232 deferred.reject(status);
234 return deferred.promise;
238 UserProfileService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4', '$rootScope'];
239 angular.module('ecompApp').service('userProfileService', UserProfileService)