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 * ================================================================================
23 class UserProfileService {
25 constructor($q, $log, $http, conf, uuid, utilsService) {
31 this.utilsService = utilsService;
32 this.userProfile = null;
38 this.$log.debug('UserProfileService::getUserProfile: get logged user profile');
39 let deferred = this.$q.defer();
40 let url = this.conf.api.userProfile;
46 'X-ECOMP-RequestID':this.uuid.generate()
51 this.$log.debug('UserProfileService::getUserProfile: result is ' + JSON.stringify(res));
52 // Res is always JSON, but the data object might be an HTML error page.
53 if (! this.utilsService.isValidJSON(res.data)) {
54 var msg = 'UserProfileService::getUserProfile: result data is not JSON';
60 this.$log.debug('UserProfileService::getUserProfile: success');
61 this.userProfile = res.data;
62 deferred.resolve(res.data);
66 this.$log.error('UserProfileService::getUserProfile caught exception: ' + JSON.stringify(status));
67 deferred.reject(status);
69 return deferred.promise;
72 getSortedUserIdCombination(user1, user2) {
76 combination = user1+"-"+user2;
77 } else if (user1>user2){
78 combination = user2+"-"+user1;
84 var collaborateUrl = 'opencollaboration?chat_id=' + combination ;
86 return collaborateUrl;
92 getFunctionalMenuStaticInfo() {
94 this.$log.debug('UserProfileService::getFunctionalMenuStaticInfo: start');
95 let deferred = this.$q.defer();
96 let url = this.conf.api.functionalMenuStaticInfo;
102 'X-ECOMP-RequestID':this.uuid.generate()
106 this.$log.debug('UserProfileService::getFunctionalMenuStaticInfo: result is ' + JSON.stringify(res));
107 // Res is always JSON, but the data object might be an HTML error page.
108 if (! this.utilsService.isValidJSON(res.data)) {
109 var msg = 'UserProfileService::getFunctionalMenuStaticInfo: result data is not JSON';
111 this.$log.debug(msg);
112 deferred.reject(msg);
115 this.$log.debug('UserProfileService::getFunctionalMenuStaticInfo Succeeded');
116 deferred.resolve(res.data);
118 }).catch( status => {
119 this.$log.error('UserProfileService::getFunctionalMenuStaticInfo caught exception: ' + JSON.stringify(status));
120 deferred.reject(status);
122 return deferred.promise;
127 this.$log.debug('UserProfileService::getActiveUser: start');
128 let deferred = this.$q.defer();
129 let url = this.conf.api.getActiveUser;
135 'X-ECOMP-RequestID': this.uuid.generate()
139 this.$log.debug('UserProfileService::getActiveUser: result is ' + JSON.stringify(res));
140 this.$log.debug('UserProfileService::getActiveUser: isValidJSON is ' + this.utilsService.isValidJSON(res.data));
142 // Res is always JSON, but the data object might be an HTML error page.
143 // res.data should be a list of Org IDs; an empty list is NOT an error.
144 if (! this.utilsService.isValidJSON(res.data)) {
145 var msg = 'UserProfileService::getActiveUser: result data is not JSON';
147 this.$log.debug(msg);
148 deferred.reject(msg);
152 this.$log.debug('UserProfileService::getActiveUser: success');
153 deferred.resolve(res.data);
155 }).catch( status => {
156 this.$log.error('UserProfileService::getActiveUser caught exception: ' + JSON.stringify(status));
157 deferred.reject(status);
159 return deferred.promise;
163 getUserAppRoles(userId) {
165 this.$log.debug('UserProfileService::getUserAppRoles: get logged user profile');
166 let deferred = this.$q.defer();
169 url: this.conf.api.userApplicationRoles,
170 params: {userId:userId},
173 'X-ECOMP-RequestID':this.uuid.generate()
178 this.$log.debug('UserProfileService::getUserAppRoles: result is ' + JSON.stringify(res));
179 // Res is always JSON, but the data object might be an HTML error page.
180 if (! this.utilsService.isValidJSON(res.data)) {
181 var msg = 'UserProfileService::getUserAppRoles: result data is not JSON';
183 this.$log.debug(msg);
184 deferred.reject(msg);
187 this.$log.debug('UserProfileService::getUserAppRoles: success');
188 deferred.resolve(res.data);
192 this.$log.error('UserProfileService::getUserAppRoles caught exception: ' + JSON.stringify(status));
193 deferred.reject(status);
196 return deferred.promise;
202 UserProfileService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4', 'utilsService'];
203 angular.module('ecompApp').service('userProfileService', UserProfileService)