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 MicroserviceService {
42 constructor($q, $log, $http, conf,uuid, utilsService) {
48 this.utilsService = utilsService;
51 createService(newService) {
52 let deferred = this.$q.defer();
55 url: this.conf.api.widgetCommon,
59 'X-ECOMP-RequestID':this.uuid.generate()
62 if (res == null || res.data == null) {
63 this.$log.error('MicroserviceService::createService Failed: Result or result.data is null');
64 deferred.reject("MicroserviceService::createService Failed: Result or result.data is null");
65 } else if (!this.utilsService.isValidJSON(res.data)) {
66 this.$log.error('MicroserviceService::createService Failed: Invalid JSON format');
67 deferred.reject("MicroserviceService::createService Failed: Invalid JSON format");
69 deferred.resolve(res.data);
73 deferred.reject(errRes);
75 return deferred.promise;
79 updateService(serviceId, newService) {
80 let deferred = this.$q.defer();
83 url: this.conf.api.widgetCommon + "/" + serviceId,
87 'X-ECOMP-RequestID':this.uuid.generate()
90 if (res == null || res.data == null) {
91 this.$log.error('MicroserviceService::updateService Failed: Result or result.data is null');
92 deferred.reject("MicroserviceService::updateService Failed: Result or result.data is null");
93 } else if (!this.utilsService.isValidJSON(res.data)) {
94 this.$log.error('MicroserviceService::updateService Failed: Invalid JSON format');
95 deferred.reject("MicroserviceService::updateService Failed: Invalid JSON format");
97 deferred.resolve(res.data);
101 deferred.reject(errRes);
103 return deferred.promise;
106 deleteService(serviceId) {
107 let deferred = this.$q.defer();
110 url: this.conf.api.widgetCommon + "/" + serviceId,
113 'X-ECOMP-RequestID':this.uuid.generate()
116 if (res == null || res.data == null) {
117 this.$log.error('MicroserviceService::deleteService Failed: Result or result.data is null');
118 deferred.reject("MicroserviceService::deleteService Failed: Result or result.data is null");
119 } else if (!this.utilsService.isValidJSON(res.data)) {
120 this.$log.error('MicroserviceService::deleteService Failed: Invalid JSON format');
121 deferred.reject("MicroserviceService::deleteService Failed: Invalid JSON format");
123 deferred.resolve(res.data);
127 deferred.reject(errRes);
129 return deferred.promise;
133 let deferred = this.$q.defer();
136 url: this.conf.api.widgetCommon,
139 'X-ECOMP-RequestID':this.uuid.generate()
142 if (res == null || res.data == null) {
143 this.$log.error('MicroserviceService::getServiceList Failed: Result or result.data is null');
144 deferred.reject("MicroserviceService::getServiceList Failed: Result or result.data is null");
145 } else if (!this.utilsService.isValidJSON(res.data)) {
146 this.$log.error('MicroserviceService::getServiceList Failed: Invalid JSON format');
147 deferred.reject("MicroserviceService::getServiceList Failed: Invalid JSON format");
149 deferred.resolve(res.data);
153 deferred.reject(errRes);
155 return deferred.promise;
158 getWidgetListByService(serviceId) {
159 let deferred = this.$q.defer();
162 url: this.conf.api.widgetCommon + '/' + serviceId,
165 'X-ECOMP-RequestID':this.uuid.generate()
168 if (res == null || res.data == null) {
169 this.$log.error('MicroserviceService::getWidgetListByService Failed: Result or result.data is null');
170 deferred.reject("MicroserviceService::getWidgetListByService Failed: Result or result.data is null");
171 } else if (!this.utilsService.isValidJSON(res.data)) {
172 this.$log.error('MicroserviceService::getWidgetListByService Failed: Invalid JSON format');
173 deferred.reject("MicroserviceService::getWidgetListByService Failed: Invalid JSON format");
175 deferred.resolve(res.data);
179 deferred.reject(errRes);
181 return deferred.promise;
184 getUserParameterById(paramId){
185 let deferred = this.$q.defer();
188 url: this.conf.api.widgetCommon + '/services/' + paramId,
191 'X-ECOMP-RequestID':this.uuid.generate()
194 if (res == null || res.data == null) {
195 this.$log.error('MicroserviceService::getUserParameterById Failed: Result or result.data is null');
196 deferred.reject("MicroserviceService::getUserParameterById Failed: Result or result.data is null");
197 } else if (!this.utilsService.isValidJSON(res.data)) {
198 this.$log.error('MicroserviceService::getUserParameterById Failed: Invalid JSON format');
199 deferred.reject("MicroserviceService::getUserParameterById Failed: Invalid JSON format");
201 deferred.resolve(res.data);
205 deferred.reject(errRes);
207 return deferred.promise;
210 deleteUserParameterById(paramId){
211 let deferred = this.$q.defer();
214 url: this.conf.api.widgetCommon + '/services/' + paramId,
217 'X-ECOMP-RequestID':this.uuid.generate()
220 if (res == null || res.data == null) {
221 this.$log.error('MicroserviceService::deleteUserParameterById Failed: Result or result.data is null');
222 deferred.reject("MicroserviceService::deleteUserParameterById Failed: Result or result.data is null");
224 deferred.resolve(res.data);
228 deferred.reject(errRes);
230 return deferred.promise;
234 MicroserviceService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
235 angular.module('ecompApp').service('microserviceService', MicroserviceService)