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============================================
39 * Created by doritrieur on 12/8/15.
45 constructor($q, $log, $http, conf, uuid, utilsService) {
51 this.utilsService = utilsService;
55 searchUsers(queryString) {
56 let canceller = this.$q.defer();
61 this.$log.debug('UsersService::searchUsers: canceling the request');
67 let deferred = this.$q.defer();
69 return deferred.reject(new Error('query string is mandatory'));
74 url: this.conf.api.queryUsers,
75 params: {search: queryString},
77 timeout: canceller.promise,
79 'X-ECOMP-RequestID':this.uuid.generate()
82 // If response comes back as a redirected HTML page which IS NOT a success
83 if (this.utilsService.isValidJSON(res)== false) {
84 deferred.reject('UsersService::queryUsers Failed');
86 //this.$log.info('UsersService::queryUsers Succeeded');
88 deferred.resolve(res.data);
92 deferred.reject('UsersService::searchUsers:: API Failed with status: ' + status);
94 return deferred.promise;
104 getAccountUsers(appId) {
105 let deferred = this.$q.defer();
107 // this.$log.debug('UsersService::getAccountUsers for appId: ' + appId);
109 let url = this.conf.api.accountUsers.replace(':appId', appId);
115 'X-ECOMP-RequestID':this.uuid.generate()
118 // If response comes back as a redirected HTML page which IS NOT a success
119 if (this.utilsService.isValidJSON(res)== false) {
120 deferred.reject('UsersService::getAccountUsers for appId Failed');
122 // log.info('UsersService::getAccountUsers(appId) Succeeded');
123 deferred.resolve(res.data);
127 log.error('getAccountUsers(appId) $http error = ', status);
128 deferred.reject(status);
131 return deferred.promise;
134 getUserAppRoles(appid, orgUserId, extRequestValue,isSystemUser){
135 let canceller = this.$q.defer();
136 let isActive = false;
140 this.$log.debug('UsersService::getUserAppRoles: canceling the request');
145 let promise = () => {
146 let deferred = this.$q.defer();
150 url: this.conf.api.userAppRoles,
151 params: {user: orgUserId, app: appid, externalRequest: extRequestValue,isSystemUser: isSystemUser},
154 'X-ECOMP-RequestID':this.uuid.generate()
157 if (!this.utilsService.isValidJSON(res.data)) {
158 deferred.reject('UsersService::getUserAppRoles: Failed');
161 deferred.resolve(res.data);
166 deferred.reject(status);
169 return deferred.promise;
178 updateUserAppRoles(newUserAppRoles) {
179 // let deferred = this.$q.defer();
180 let canceller = this.$q.defer();
181 let isActive = false;
185 this.$log.debug('UsersService::updateUserAppRoles: canceling the request');
190 // this.$log.info('UsersService::updateUserAppRoles');
191 let promise = () => {
192 let deferred = this.$q.defer();
195 url: this.conf.api.userAppRoles,
196 data: newUserAppRoles,
198 'X-ECOMP-RequestID':this.uuid.generate()
201 // this.$log.debug('getUserAppRoles response: ', JSON.stringify(res))
202 // If response comes back as a redirected HTML page which IS NOT a success
203 if (this.utilsService.isValidJSON(res)== false || res.data.httpStatusCode == '500' || res.data.status == 'ERROR') {
204 deferred.reject('UsersService::updateUserAppRoles: Failed' + res.data.message);
206 // this.$log.info('UsersService::updateUserAppRoles: Succeeded');
207 deferred.resolve(res.data);
211 deferred.reject(status);
214 return deferred.promise;
225 let deferred = this.$q.defer();
228 url: this.conf.api.loggedinUser,
231 'X-ECOMP-RequestID':this.uuid.generate(),
232 'Content-Type': 'application/json'
236 if (res.data==null || !this.utilsService.isValidJSON(res.data)) {
237 deferred.reject('MenusService::getLoggedInUser rest call failed');
239 if(res.data.status!='OK' && res.data.message!=null)
240 deferred.reject('MenusService::getLoggedInUser rest call failed ' + res.data.message);
242 deferred.resolve(res.data);
246 this.$log.error('MenusService::getLoggedInUser rejection:' + status);
247 deferred.reject(status);
250 return deferred.promise;
253 modifyLoggedInUser (profileDetail) {
254 let deferred = this.$q.defer();
257 url: this.conf.api.modifyLoggedinUser,
260 'X-ECOMP-RequestID':this.uuid.generate(),
261 'Content-Type': 'application/json'
265 if (res.data==null || !this.utilsService.isValidJSON(res.data)) {
266 deferred.reject('MenusService::getLoggedInUser rest call failed');
268 if(res.data.status!='OK' && res.data.message!=null)
269 deferred.reject('MenusService::getLoggedInUser rest call failed ' + res.data.message);
271 deferred.resolve(res.data);
276 this.$log.error('MenusService::getLoggedInUser rejection:' + status);
277 deferred.reject(status);
280 return deferred.promise;
284 UsersService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
285 angular.module('ecompApp').service('usersService', UsersService)