2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
41 class UserProfileService {
43 constructor($q, $log, $http, conf, uuid, utilsService) {
49 this.utilsService = utilsService;
50 this.userProfile = null;
56 this.$log.debug('UserProfileService::getUserProfile: get logged user profile');
57 let deferred = this.$q.defer();
58 let url = this.conf.api.userProfile;
64 'X-ECOMP-RequestID':this.uuid.generate()
69 this.$log.debug('UserProfileService::getUserProfile: result is ' + JSON.stringify(res));
70 // Res is always JSON, but the data object might be an HTML error page.
71 if (! this.utilsService.isValidJSON(res.data)) {
72 var msg = 'UserProfileService::getUserProfile: result data is not JSON';
78 this.$log.debug('UserProfileService::getUserProfile: success');
79 this.userProfile = res.data;
80 deferred.resolve(res.data);
84 this.$log.error('UserProfileService::getUserProfile caught exception: ' + JSON.stringify(status));
85 deferred.reject(status);
87 return deferred.promise;
90 getSortedUserIdCombination(user1, user2) {
94 combination = user1+"-"+user2;
95 } else if (user1>user2){
96 combination = user2+"-"+user1;
102 var collaborateUrl = 'opencollaboration?chat_id=' + combination ;
104 return collaborateUrl;
110 getFunctionalMenuStaticInfo() {
112 this.$log.debug('UserProfileService::getFunctionalMenuStaticInfo: start');
113 let deferred = this.$q.defer();
114 let url = this.conf.api.functionalMenuStaticInfo;
120 'X-ECOMP-RequestID':this.uuid.generate()
124 this.$log.debug('UserProfileService::getFunctionalMenuStaticInfo: result is ' + JSON.stringify(res));
125 // Res is always JSON, but the data object might be an HTML error page.
126 if (! this.utilsService.isValidJSON(res.data)) {
127 var msg = 'UserProfileService::getFunctionalMenuStaticInfo: result data is not JSON';
129 this.$log.debug(msg);
130 deferred.reject(msg);
133 this.$log.debug('UserProfileService::getFunctionalMenuStaticInfo Succeeded');
134 // saving the userId at session level
135 sessionStorage.userId = res.data.userId;
136 deferred.resolve(res.data);
138 }).catch( status => {
139 this.$log.error('UserProfileService::getFunctionalMenuStaticInfo caught exception: ' + JSON.stringify(status));
140 deferred.reject(status);
142 return deferred.promise;
147 this.$log.debug('UserProfileService::getActiveUser: start');
148 let deferred = this.$q.defer();
149 let url = this.conf.api.getActiveUser;
155 'X-ECOMP-RequestID': this.uuid.generate()
159 this.$log.debug('UserProfileService::getActiveUser: result is ' + JSON.stringify(res));
160 this.$log.debug('UserProfileService::getActiveUser: isValidJSON is ' + this.utilsService.isValidJSON(res.data));
162 // Res is always JSON, but the data object might be an HTML error page.
163 // res.data should be a list of Org IDs; an empty list is NOT an error.
164 if (! this.utilsService.isValidJSON(res.data)) {
165 var msg = 'UserProfileService::getActiveUser: result data is not JSON';
167 this.$log.debug(msg);
168 deferred.reject(msg);
172 this.$log.debug('UserProfileService::getActiveUser: success');
173 deferred.resolve(res.data);
175 }).catch( status => {
176 this.$log.error('UserProfileService::getActiveUser caught exception: ' + JSON.stringify(status));
177 deferred.reject(status);
179 return deferred.promise;
183 getUserAppRoles(userId) {
185 this.$log.debug('UserProfileService::getUserAppRoles: get logged user profile');
186 let deferred = this.$q.defer();
189 url: this.conf.api.userApplicationRoles,
190 params: {userId:userId},
193 'X-ECOMP-RequestID':this.uuid.generate()
198 this.$log.debug('UserProfileService::getUserAppRoles: result is ' + JSON.stringify(res));
199 // Res is always JSON, but the data object might be an HTML error page.
200 if (! this.utilsService.isValidJSON(res.data)) {
201 var msg = 'UserProfileService::getUserAppRoles: result data is not JSON';
203 this.$log.debug(msg);
204 deferred.reject(msg);
207 this.$log.debug('UserProfileService::getUserAppRoles: success');
208 deferred.resolve(res.data);
212 this.$log.error('UserProfileService::getUserAppRoles caught exception: ' + JSON.stringify(status));
213 deferred.reject(status);
216 return deferred.promise;
222 UserProfileService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4', 'utilsService'];
223 angular.module('ecompApp').service('userProfileService', UserProfileService)