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 * ================================================================================
25 constructor($q, $log, $http, conf,uuid) {
34 searchUsers(queryString) {
35 let canceller = this.$q.defer();
40 this.$log.debug('UsersService::searchUsers: canceling the request');
46 let deferred = this.$q.defer();
48 return deferred.reject(new Error('query string is mandatory'));
53 url: this.conf.api.queryUsers,
54 params: {search: queryString},
56 timeout: canceller.promise,
58 'X-ECOMP-RequestID':this.uuid.generate()
61 if (Object.keys(res.data).length == 0) {
62 deferred.reject("UsersService::queryUsers Failed");
64 this.$log.info('UsersService::queryUsers Succeeded');
66 deferred.resolve(res.data);
70 deferred.reject('UsersService::searchUsers:: API Failed with status: ' + status);
72 return deferred.promise;
82 getAccountUsers(appId) {
83 let deferred = this.$q.defer();
85 this.$log.debug('UsersService::getAccountUsers for appId: ' + appId);
87 let url = this.conf.api.accountUsers.replace(':appId', appId);
93 'X-ECOMP-RequestID':this.uuid.generate()
96 if (Object.keys(res.data).length == 0) {
97 deferred.reject("UsersService::getAccountUsers for appId Failed");
99 log.info('UsersService::getAccountUsers(appId) Succeeded');
100 deferred.resolve(res.data);
104 log.error('getAccountUsers(appId) $http error = ', status);
105 deferred.reject(status);
107 return deferred.promise;
110 getUserAppRoles(appid, orgUserId){
111 let deferred = this.$q.defer();
112 this.$log.info('UsersService::getUserAppRoles');
116 url: this.conf.api.userAppRoles,
117 params: {orgUserId: orgUserId, app: appid},
120 'X-ECOMP-RequestID':this.uuid.generate()
123 if (Object.keys(res.data).length == 0) {
124 deferred.reject("UsersService::getUserAppRoles: Failed");
126 this.$log.info('UsersService::getUserAppRoles: Succeeded');
127 deferred.resolve(res.data);
131 this.$log.debug("UsersService::getUserAppRoles: status.headers(FEErrorString)");
132 this.$log.debug('UsersService::getUserAppRoles status.headers(FEErrorString)', status.headers('FEErrorString'));
133 deferred.reject(status);
135 return deferred.promise;
138 updateUserAppRoles(newUserAppRoles) {
139 let deferred = this.$q.defer();
140 this.$log.info('UsersService::updateUserAppRoles');
143 url: this.conf.api.userAppRoles,
144 data: newUserAppRoles,
146 'X-ECOMP-RequestID':this.uuid.generate()
149 deferred.resolve(res.data);
152 deferred.reject(status);
155 return deferred.promise;
159 UsersService.$inject = ['$q', '$log', '$http', 'conf','uuid4'];
160 angular.module('ecompApp').service('usersService', UsersService)