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 * ================================================================================
21 * Created by doritrieur on 12/8/15.
27 constructor($q, $log, $http, conf, uuid, utilsService) {
33 this.utilsService = utilsService;
37 searchUsers(queryString) {
38 let canceller = this.$q.defer();
43 this.$log.debug('UsersService::searchUsers: canceling the request');
49 let deferred = this.$q.defer();
51 return deferred.reject(new Error('query string is mandatory'));
56 url: this.conf.api.queryUsers,
57 params: {search: queryString},
59 timeout: canceller.promise,
61 'X-ECOMP-RequestID':this.uuid.generate()
64 // If response comes back as a redirected HTML page which IS NOT a success
65 if (this.utilsService.isValidJSON(res)== false) {
66 deferred.reject('UsersService::queryUsers Failed');
68 //this.$log.info('UsersService::queryUsers Succeeded');
70 deferred.resolve(res.data);
74 deferred.reject('UsersService::searchUsers:: API Failed with status: ' + status);
76 return deferred.promise;
86 getAccountUsers(appId) {
87 let deferred = this.$q.defer();
89 // this.$log.debug('UsersService::getAccountUsers for appId: ' + appId);
91 let url = this.conf.api.accountUsers.replace(':appId', appId);
97 'X-ECOMP-RequestID':this.uuid.generate()
100 // If response comes back as a redirected HTML page which IS NOT a success
101 if (this.utilsService.isValidJSON(res)== false) {
102 deferred.reject('UsersService::getAccountUsers for appId Failed');
104 // log.info('UsersService::getAccountUsers(appId) Succeeded');
105 deferred.resolve(res.data);
109 log.error('getAccountUsers(appId) $http error = ', status);
110 deferred.reject(status);
113 return deferred.promise;
116 getUserAppRoles(appid, orgUserId, extRequestValue){
117 let canceller = this.$q.defer();
118 let isActive = false;
122 this.$log.debug('UsersService::getUserAppRoles: canceling the request');
127 let promise = () => {
128 let deferred = this.$q.defer();
132 url: this.conf.api.userAppRoles,
133 params: {user: orgUserId, app: appid, externalRequest: extRequestValue},
136 'X-ECOMP-RequestID':this.uuid.generate()
139 if (!this.utilsService.isValidJSON(res.data)) {
140 deferred.reject('UsersService::getUserAppRoles: Failed');
143 deferred.resolve(res.data);
148 deferred.reject(status);
151 return deferred.promise;
160 updateUserAppRoles(newUserAppRoles) {
161 // let deferred = this.$q.defer();
162 let canceller = this.$q.defer();
163 let isActive = false;
167 this.$log.debug('UsersService::updateUserAppRoles: canceling the request');
172 // this.$log.info('UsersService::updateUserAppRoles');
173 let promise = () => {
174 let deferred = this.$q.defer();
177 url: this.conf.api.userAppRoles,
178 data: newUserAppRoles,
180 'X-ECOMP-RequestID':this.uuid.generate()
183 // this.$log.debug('getUserAppRoles response: ', JSON.stringify(res))
184 // If response comes back as a redirected HTML page which IS NOT a success
185 if (this.utilsService.isValidJSON(res)== false) {
186 deferred.reject('UsersService::updateUserAppRoles: Failed');
188 // this.$log.info('UsersService::updateUserAppRoles: Succeeded');
189 deferred.resolve(res.data);
193 deferred.reject(status);
196 return deferred.promise;
207 let deferred = this.$q.defer();
210 url: this.conf.api.loggedinUser,
213 'X-ECOMP-RequestID':this.uuid.generate(),
214 'Content-Type': 'application/json'
218 if (res.data==null || !this.utilsService.isValidJSON(res.data)) {
219 deferred.reject('MenusService::getLoggedInUser rest call failed');
221 if(res.data.status!='OK' && res.data.message!=null)
222 deferred.reject('MenusService::getLoggedInUser rest call failed ' + res.data.message);
224 deferred.resolve(res.data);
228 this.$log.error('MenusService::getLoggedInUser rejection:' + status);
229 deferred.reject(status);
232 return deferred.promise;
235 modifyLoggedInUser (profileDetail) {
236 let deferred = this.$q.defer();
239 url: this.conf.api.modifyLoggedinUser,
242 'X-ECOMP-RequestID':this.uuid.generate(),
243 'Content-Type': 'application/json'
247 if (res.data==null || !this.utilsService.isValidJSON(res.data)) {
248 deferred.reject('MenusService::getLoggedInUser rest call failed');
250 if(res.data.status!='OK' && res.data.message!=null)
251 deferred.reject('MenusService::getLoggedInUser rest call failed ' + res.data.message);
253 deferred.resolve(res.data);
258 this.$log.error('MenusService::getLoggedInUser rejection:' + status);
259 deferred.reject(status);
262 return deferred.promise;
266 UsersService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
267 angular.module('ecompApp').service('usersService', UsersService)