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 BasicAuthAccountService {
42 constructor($q, $log, $http, conf,uuid, utilsService) {
48 this.utilsService = utilsService;
51 createAccount(newAccount) {
52 let deferred = this.$q.defer();
55 url: this.conf.api.basicAuthAccount,
59 'X-ECOMP-RequestID':this.uuid.generate()
62 if (res == null || res.data == null) {
63 this.$log.error('BasicAuthAccountService::createAccount Failed: Result or result.data is null');
64 deferred.reject("BasicAuthAccountService::createAccount Failed: Result or result.data is null");
65 } else if (!this.utilsService.isValidJSON(res.data)) {
66 this.$log.error('BasicAuthAccountService::createAccount Failed: Invalid JSON format');
67 deferred.reject("BasicAuthAccountService::createAccount Failed: Invalid JSON format");
69 deferred.resolve(res.data);
73 deferred.reject(errRes);
75 return deferred.promise;
78 updateAccount(accountId, newAccount) {
79 let deferred = this.$q.defer();
82 url: this.conf.api.basicAuthAccount + "/" + accountId,
86 'X-ECOMP-RequestID':this.uuid.generate()
89 if (res == null || res.data == null) {
90 this.$log.error('BasicAuthAccountService::updateAccount Failed: Result or result.data is null');
91 deferred.reject("BasicAuthAccountService::updateAccount Failed: Result or result.data is null");
92 } else if (!this.utilsService.isValidJSON(res.data)) {
93 this.$log.error('BasicAuthAccountService::updateAccount Failed: Invalid JSON format');
94 deferred.reject("BasicAuthAccountService::updateAccount Failed: Invalid JSON format");
96 deferred.resolve(res.data);
100 deferred.reject(errRes);
102 return deferred.promise;
106 let deferred = this.$q.defer();
109 url: this.conf.api.basicAuthAccount,
112 'X-ECOMP-RequestID':this.uuid.generate()
115 if (res == null || res.data == null) {
116 this.$log.error('BasicAuthAccountService::getAccountList Failed: Result or result.data is null');
117 deferred.reject("BasicAuthAccountService::getAccountList Failed: Result or result.data is null");
118 } else if (!this.utilsService.isValidJSON(res.data)) {
119 this.$log.error('BasicAuthAccountService::getAccountList Failed: Invalid JSON format');
120 deferred.reject("BasicAuthAccountService::getAccountList Failed: Invalid JSON format");
122 deferred.resolve(res.data.response);
126 deferred.reject(errRes);
128 return deferred.promise;
131 deleteAccount(accountId) {
132 let deferred = this.$q.defer();
135 url: this.conf.api.basicAuthAccount + "/" + accountId,
138 'X-ECOMP-RequestID':this.uuid.generate()
141 if (res == null || res.data == null) {
142 this.$log.error('BasicAuthAccountService::deleteAccount Failed: Result or result.data is null');
143 deferred.reject("BasicAuthAccountService::deleteAccount Failed: Result or result.data is null");
144 } else if (!this.utilsService.isValidJSON(res.data)) {
145 this.$log.error('BasicAuthAccountService::deleteAccount Failed: Invalid JSON format');
146 deferred.reject("BasicAuthAccountService::deleteAccount Failed: Invalid JSON format");
148 deferred.resolve(res.data);
152 deferred.reject(errRes);
154 return deferred.promise;
159 BasicAuthAccountService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
160 angular.module('ecompApp').service('basicAuthAccountService', BasicAuthAccountService)