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 * ================================================================================
23 class MicroserviceService {
24 constructor($q, $log, $http, conf,uuid, utilsService) {
30 this.utilsService = utilsService;
33 createService(newService) {
34 let deferred = this.$q.defer();
37 url: this.conf.api.widgetCommon,
41 'X-ECOMP-RequestID':this.uuid.generate()
44 if (res == null || res.data == null) {
45 this.$log.error('MicroserviceService::createService Failed: Result or result.data is null');
46 deferred.reject("MicroserviceService::createService Failed: Result or result.data is null");
47 } else if (!this.utilsService.isValidJSON(res.data)) {
48 this.$log.error('MicroserviceService::createService Failed: Invalid JSON format');
49 deferred.reject("MicroserviceService::createService Failed: Invalid JSON format");
51 deferred.resolve(res.data);
55 deferred.reject(errRes);
57 return deferred.promise;
61 updateService(serviceId, newService) {
62 let deferred = this.$q.defer();
65 url: this.conf.api.widgetCommon + "/" + serviceId,
69 'X-ECOMP-RequestID':this.uuid.generate()
72 if (res == null || res.data == null) {
73 this.$log.error('MicroserviceService::updateService Failed: Result or result.data is null');
74 deferred.reject("MicroserviceService::updateService Failed: Result or result.data is null");
75 } else if (!this.utilsService.isValidJSON(res.data)) {
76 this.$log.error('MicroserviceService::updateService Failed: Invalid JSON format');
77 deferred.reject("MicroserviceService::updateService Failed: Invalid JSON format");
79 deferred.resolve(res.data);
83 deferred.reject(errRes);
85 return deferred.promise;
88 deleteService(serviceId) {
89 let deferred = this.$q.defer();
92 url: this.conf.api.widgetCommon + "/" + serviceId,
95 'X-ECOMP-RequestID':this.uuid.generate()
98 if (res == null || res.data == null) {
99 this.$log.error('MicroserviceService::deleteService Failed: Result or result.data is null');
100 deferred.reject("MicroserviceService::deleteService Failed: Result or result.data is null");
101 } else if (!this.utilsService.isValidJSON(res.data)) {
102 this.$log.error('MicroserviceService::deleteService Failed: Invalid JSON format');
103 deferred.reject("MicroserviceService::deleteService Failed: Invalid JSON format");
105 deferred.resolve(res.data);
109 deferred.reject(errRes);
111 return deferred.promise;
115 let deferred = this.$q.defer();
118 url: this.conf.api.widgetCommon,
121 'X-ECOMP-RequestID':this.uuid.generate()
124 if (res == null || res.data == null) {
125 this.$log.error('MicroserviceService::getServiceList Failed: Result or result.data is null');
126 deferred.reject("MicroserviceService::getServiceList Failed: Result or result.data is null");
127 } else if (!this.utilsService.isValidJSON(res.data)) {
128 this.$log.error('MicroserviceService::getServiceList Failed: Invalid JSON format');
129 deferred.reject("MicroserviceService::getServiceList Failed: Invalid JSON format");
131 deferred.resolve(res.data);
135 deferred.reject(errRes);
137 return deferred.promise;
140 getWidgetListByService(serviceId) {
141 let deferred = this.$q.defer();
144 url: this.conf.api.widgetCommon + '/' + serviceId,
147 'X-ECOMP-RequestID':this.uuid.generate()
150 if (res == null || res.data == null) {
151 this.$log.error('MicroserviceService::getWidgetListByService Failed: Result or result.data is null');
152 deferred.reject("MicroserviceService::getWidgetListByService Failed: Result or result.data is null");
153 } else if (!this.utilsService.isValidJSON(res.data)) {
154 this.$log.error('MicroserviceService::getWidgetListByService Failed: Invalid JSON format');
155 deferred.reject("MicroserviceService::getWidgetListByService Failed: Invalid JSON format");
157 deferred.resolve(res.data);
161 deferred.reject(errRes);
163 return deferred.promise;
166 getUserParameterById(paramId){
167 let deferred = this.$q.defer();
170 url: this.conf.api.widgetCommon + '/services/' + paramId,
173 'X-ECOMP-RequestID':this.uuid.generate()
176 if (res == null || res.data == null) {
177 this.$log.error('MicroserviceService::getUserParameterById Failed: Result or result.data is null');
178 deferred.reject("MicroserviceService::getUserParameterById Failed: Result or result.data is null");
179 } else if (!this.utilsService.isValidJSON(res.data)) {
180 this.$log.error('MicroserviceService::getUserParameterById Failed: Invalid JSON format');
181 deferred.reject("MicroserviceService::getUserParameterById Failed: Invalid JSON format");
183 deferred.resolve(res.data);
187 deferred.reject(errRes);
189 return deferred.promise;
192 deleteUserParameterById(paramId){
193 let deferred = this.$q.defer();
196 url: this.conf.api.widgetCommon + '/services/' + paramId,
199 'X-ECOMP-RequestID':this.uuid.generate()
202 if (res == null || res.data == null) {
203 this.$log.error('MicroserviceService::deleteUserParameterById Failed: Result or result.data is null');
204 deferred.reject("MicroserviceService::deleteUserParameterById Failed: Result or result.data is null");
206 deferred.resolve(res.data);
210 deferred.reject(errRes);
212 return deferred.promise;
216 MicroserviceService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
217 angular.module('ecompApp').service('microserviceService', MicroserviceService)