2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2019 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============================================
38 import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
39 import { IMircroservies } from 'src/app/shared/model/microservice-onboarding/microservices';
40 import { MicroserviceService, WidgetOnboardingService } from '../../../shared/services/index';
41 import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap';
42 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
45 selector: 'app-microservice-add-details',
46 templateUrl: './microservice-add-details.component.html',
47 styleUrls: ['./microservice-add-details.component.scss']
49 export class MicroserviceAddDetailsComponent implements OnInit {
51 @Input() public ms: IMircroservies;
52 @Output() passEntry: EventEmitter<any> = new EventEmitter();
58 emptyServiceName = false;
59 emptyServiceDesc = false;
60 emptyServiceURL = false;
61 emptyServiceApp = false;
62 availableSecurityTypes = [];
63 availableWidgets = [];
64 applicationList: Array<Object> = [];
66 constructor(public microservice: MicroserviceService, public widgetOnboardingService: WidgetOnboardingService,
67 public activeModal: NgbActiveModal, public ngbModal: NgbModal) { }
71 this.isEditMode = true;
73 this.isEditMode = false;
75 this.ms.parameterList = [];
76 this.ms.active = true;
77 this.populateAvailableApps();
78 this.getAvailableSecurityTypes();
81 getAvailableWidgets(serviceId){
82 console.log("getAvailableWidgets called");
83 this.microservice.getWidgetListByService(serviceId)
86 if (this.result == null || this.result) {
87 console.log('MicroserviceService::getServiceList Failed: Result or result.data is null');
89 this.availableWidgets = [];
90 for(var i = 0; i < data.length; i++){
91 this.availableWidgets.push({
101 getAvailableSecurityTypes(): Array<String> {
102 this.availableSecurityTypes = [];
103 this.availableSecurityTypes.push({
105 name: 'No Authentication'
107 this.availableSecurityTypes.push({
109 name: 'Basic Authentication'
111 this.availableSecurityTypes.push({
113 name: 'Cookie based Authentication'
116 return this.availableSecurityTypes;
119 populateAvailableApps(){
120 this.widgetOnboardingService.populateAvailableApps()
121 .subscribe( _data => {
122 let allPortalsFilterObject = {index: 0, title: 'Select Application', value: ''};
123 this.applicationList = [allPortalsFilterObject];
124 var realAppIndex = 1;
125 for (let i = 1; i <= _data.length; i++) {
126 if (!_data[i-1].restrictedApp) {
127 this.applicationList.push({
129 title: _data[i - 1].name,
130 value: _data[i - 1].id
132 realAppIndex = realAppIndex + 1;
141 this.ms.parameterList.push({});
145 console.log("testServiceURL called id is :: ",this.ms.id)
146 this.microservice.getServiceJSON(this.ms.id)
147 .subscribe( _data => {
149 console.log("testServiceURL response :: ",this.result);
150 document.getElementById("microservice-details-input-json").innerHTML = (JSON.stringify(this.result));
152 document.getElementById("microservice-details-input-json").innerHTML = "Something went wrong. Please go back to the previous page or try again later.";
157 removeParamItem(parameter: any){
158 console.log("removeParamItem called", parameter);
159 this.ms.parameterList.splice(parameter.para_key, 1);
160 this.microservice.getUserParameterById(parameter)
163 if (this.result == null || this.result) {
164 console.log('MicroserviceService::removeParamItem Failed: Result or result.data is null');
165 }else if(this.result && this.result.length > 0) {
166 this.microservice.deleteUserParameterById(parameter.id)
167 .subscribe(__data => {
168 for(var i = 0; i < this.ms.parameterList.length; i++){
169 if(this.ms.parameterList[i].para_key == parameter.para_key
170 && this.ms.parameterList[i].para_value == parameter.para_value){
171 this.ms.parameterList.splice(i, 1);
180 for(var i = 0; i < this.ms.parameterList.length; i++){
181 if(this.ms.parameterList[i].para_key == parameter.para_key
182 && this.ms.parameterList[i].para_value == parameter.para_value){
183 this.ms.parameterList.splice(i, 1);
193 //Add Or Update Microservices.
195 console.log("saveChanges..",this.ms);
196 if(this.ms && this.ms.id && this.ms.id !='undefined'){
197 this.isEditMode = true;
201 if(this.ms.name == ''
202 || this.ms.name == undefined){
203 this.emptyServiceName = true;
206 console.log("a >",isValid);
207 if(this.dupliateName == true){
210 console.log("b> ",isValid);
211 if(this.ms.desc == ''
212 || this.ms.desc == undefined){
213 this.emptyServiceDesc = true;
216 console.log("c> ",isValid);
219 || this.ms.url == undefined){
220 this.emptyServiceURL = true;
223 console.log("d> ",isValid);
225 if(this.ms.appId == undefined
226 || this.ms.appId == null){
227 this.emptyServiceApp = true;
231 console.log("IsValid flag add/update microservices ",isValid )
236 * Check the parameter list, delete those parameters that don't
239 if(this.ms && this.ms.parameterList){
240 for(var i = 0; i < this.ms.parameterList.length; i++){
241 if(this.ms.parameterList[i].para_key == undefined
242 || this.ms.parameterList[i].para_key == null
243 || this.ms.parameterList[i].para_key == ""){
244 this.ms.parameterList.splice(i, 1);
249 if(this.ms.securityType == undefined ||
250 this.ms.securityType == null)
251 this.ms.securityType = "No Authentication";
253 this.ms.securityType = this.ms.securityType;
254 this.ms.username = this.ms.username;
255 this.ms.password = this.ms.password;
259 if(this.ms.active == true)
263 if(this.ms.parameterList && this.ms.parameterList.length >0){
264 paramList = this.ms.parameterList;
269 appId: this.ms.appId,
271 securityType: this.ms.securityType,
272 username: this.ms.username,
273 password: this.ms.password,
275 parameterList: paramList
279 console.log("Edit microservice mode called");
280 this.microservice.updateService(this.ms.id , newService)
281 .subscribe( data => {
283 console.log("update microservice response :: ",this.result);
284 this.passEntry.emit(this.result);
285 this.ngbModal.dismissAll();
288 this.ngbModal.dismissAll();
291 console.log("Add microservice mode called")
292 this.microservice.createService(newService)
293 .subscribe( data => {
295 if(this.result.status === 'OK'){
296 console.log("add microservice response :: ",this.result);
297 this.passEntry.emit(this.result);
298 this.ngbModal.dismissAll();
301 const modalErrorRef = this.ngbModal.open(ConfirmationModalComponent);
302 modalErrorRef.componentInstance.title = 'Error';
303 modalErrorRef.componentInstance.message = this.result.response;