2 * ================================================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ================================================================================
\r
21 * Created by doritrieur on 12/8/15.
\r
26 class UsersService {
\r
27 constructor($q, $log, $http, conf, uuid, utilsService) {
\r
33 this.utilsService = utilsService;
\r
37 searchUsers(queryString) {
\r
38 let canceller = this.$q.defer();
\r
39 let isActive = false;
\r
41 let cancel = () => {
\r
43 this.$log.debug('UsersService::searchUsers: canceling the request');
\r
44 canceller.resolve();
\r
48 let promise = () => {
\r
49 let deferred = this.$q.defer();
\r
51 return deferred.reject(new Error('query string is mandatory'));
\r
56 url: this.conf.api.queryUsers,
\r
57 params: {search: queryString},
\r
59 timeout: canceller.promise,
\r
61 'X-ECOMP-RequestID':this.uuid.generate()
\r
64 // If response comes back as a redirected HTML page which IS NOT a success
\r
65 if (this.utilsService.isValidJSON(res)== false) {
\r
66 deferred.reject('UsersService::queryUsers Failed');
\r
68 //this.$log.info('UsersService::queryUsers Succeeded');
\r
70 deferred.resolve(res.data);
\r
72 }).catch( status => {
\r
74 deferred.reject('UsersService::searchUsers:: API Failed with status: ' + status);
\r
76 return deferred.promise;
\r
86 getAccountUsers(appId) {
\r
87 let deferred = this.$q.defer();
\r
88 let log = this.$log;
\r
89 // this.$log.debug('UsersService::getAccountUsers for appId: ' + appId);
\r
91 let url = this.conf.api.accountUsers.replace(':appId', appId);
\r
97 'X-ECOMP-RequestID':this.uuid.generate()
\r
100 // If response comes back as a redirected HTML page which IS NOT a success
\r
101 if (this.utilsService.isValidJSON(res)== false) {
\r
102 deferred.reject('UsersService::getAccountUsers for appId Failed');
\r
104 // log.info('UsersService::getAccountUsers(appId) Succeeded');
\r
105 deferred.resolve(res.data);
\r
108 .catch( status => {
\r
109 log.error('getAccountUsers(appId) $http error = ', status);
\r
110 deferred.reject(status);
\r
113 return deferred.promise;
\r
116 getUserAppRoles(appid, orgUserId){
\r
117 // let deferred = this.$q.defer();
\r
118 let canceller = this.$q.defer();
\r
119 let isActive = false;
\r
121 let cancel = () => {
\r
123 this.$log.debug('UsersService::getUserAppRoles: canceling the request');
\r
124 canceller.resolve();
\r
128 // this.$log.info('UsersService::getUserAppRoles');
\r
130 let promise = () => {
\r
131 let deferred = this.$q.defer();
\r
135 url: this.conf.api.userAppRoles,
\r
136 params: {user: orgUserId, app: appid},
\r
139 'X-ECOMP-RequestID':this.uuid.generate()
\r
142 //this.$log.debug('getUserAppRoles response: ', JSON.stringify(res))
\r
143 // If response comes back as a redirected HTML page which IS NOT a success
\r
144 if (this.utilsService.isValidJSON(res)== false) {
\r
145 deferred.reject('UsersService::getUserAppRoles: Failed');
\r
148 //this.$log.info('UsersService::getUserAppRoles: Succeeded');
\r
149 deferred.resolve(res.data);
\r
152 .catch( status => {
\r
154 deferred.reject(status);
\r
157 return deferred.promise;
\r
166 updateUserAppRoles(newUserAppRoles) {
\r
167 // let deferred = this.$q.defer();
\r
168 let canceller = this.$q.defer();
\r
169 let isActive = false;
\r
171 let cancel = () => {
\r
173 this.$log.debug('UsersService::updateUserAppRoles: canceling the request');
\r
174 canceller.resolve();
\r
178 // this.$log.info('UsersService::updateUserAppRoles');
\r
179 let promise = () => {
\r
180 let deferred = this.$q.defer();
\r
183 url: this.conf.api.userAppRoles,
\r
184 data: newUserAppRoles,
\r
186 'X-ECOMP-RequestID':this.uuid.generate()
\r
189 // this.$log.debug('getUserAppRoles response: ', JSON.stringify(res))
\r
190 // If response comes back as a redirected HTML page which IS NOT a success
\r
191 if (this.utilsService.isValidJSON(res)== false) {
\r
192 deferred.reject('UsersService::updateUserAppRoles: Failed');
\r
194 // this.$log.info('UsersService::updateUserAppRoles: Succeeded');
\r
195 deferred.resolve(res.data);
\r
198 .catch( status => {
\r
199 deferred.reject(status);
\r
202 return deferred.promise;
\r
213 UsersService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
\r
214 angular.module('ecompApp').service('usersService', UsersService)
\r