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';
44 selector: 'app-microservice-add-details',
45 templateUrl: './microservice-add-details.component.html',
46 styleUrls: ['./microservice-add-details.component.scss']
48 export class MicroserviceAddDetailsComponent implements OnInit {
50 @Input() public ms: IMircroservies;
51 @Output() passEntry: EventEmitter<any> = new EventEmitter();
57 emptyServiceName = false;
58 emptyServiceDesc = false;
59 emptyServiceURL = false;
60 emptyServiceApp = false;
61 availableSecurityTypes = [];
62 availableWidgets = [];
63 applicationList: Array<Object> = [];
65 constructor(public microservice: MicroserviceService, public widgetOnboardingService: WidgetOnboardingService,
66 public activeModal: NgbActiveModal, public ngbModal: NgbModal) { }
70 this.isEditMode = true;
72 this.isEditMode = false;
74 this.ms.parameterList = [];
75 this.ms.active = true;
76 this.populateAvailableApps();
77 this.getAvailableSecurityTypes();
80 getAvailableWidgets(serviceId){
81 console.log("getAvailableWidgets called");
82 this.microservice.getWidgetListByService(serviceId)
85 if (this.result == null || this.result) {
86 console.log('MicroserviceService::getServiceList Failed: Result or result.data is null');
88 this.availableWidgets = [];
89 for(var i = 0; i < data.length; i++){
90 this.availableWidgets.push({
100 getAvailableSecurityTypes(): Array<String> {
101 this.availableSecurityTypes = [];
102 this.availableSecurityTypes.push({
104 name: 'No Authentication'
106 this.availableSecurityTypes.push({
108 name: 'Basic Authentication'
110 this.availableSecurityTypes.push({
112 name: 'Cookie based Authentication'
115 return this.availableSecurityTypes;
118 populateAvailableApps(){
119 this.widgetOnboardingService.populateAvailableApps()
120 .subscribe( _data => {
121 let allPortalsFilterObject = {index: 0, title: 'Select Application', value: ''};
122 this.applicationList = [allPortalsFilterObject];
123 var realAppIndex = 1;
124 for (let i = 1; i <= _data.length; i++) {
125 if (!_data[i-1].restrictedApp) {
126 this.applicationList.push({
128 title: _data[i - 1].name,
129 value: _data[i - 1].id
131 realAppIndex = realAppIndex + 1;
140 this.ms.parameterList.push({});
144 console.log("testServiceURL called id is :: ",this.ms.id)
145 this.microservice.getServiceJSON(this.ms.id)
146 .subscribe( _data => {
148 console.log("testServiceURL response :: ",this.result);
149 document.getElementById("microservice-details-input-json").innerHTML = (JSON.stringify(this.result));
151 document.getElementById("microservice-details-input-json").innerHTML = "Something went wrong. Please go back to the previous page or try again later.";
156 removeParamItem(parameter: any){
157 console.log("removeParamItem called", parameter);
158 this.ms.parameterList.splice(parameter.para_key, 1);
159 this.microservice.getUserParameterById(parameter)
162 if (this.result == null || this.result) {
163 console.log('MicroserviceService::removeParamItem Failed: Result or result.data is null');
164 }else if(this.result && this.result.length > 0) {
165 this.microservice.deleteUserParameterById(parameter.id)
166 .subscribe(__data => {
167 for(var i = 0; i < this.ms.parameterList.length; i++){
168 if(this.ms.parameterList[i].para_key == parameter.para_key
169 && this.ms.parameterList[i].para_value == parameter.para_value){
170 this.ms.parameterList.splice(i, 1);
179 for(var i = 0; i < this.ms.parameterList.length; i++){
180 if(this.ms.parameterList[i].para_key == parameter.para_key
181 && this.ms.parameterList[i].para_value == parameter.para_value){
182 this.ms.parameterList.splice(i, 1);
192 //Add Or Update Microservices.
194 console.log("saveChanges..",this.ms);
195 if(this.ms && this.ms.id && this.ms.id !='undefined'){
196 this.isEditMode = true;
200 if(this.ms.name == ''
201 || this.ms.name == undefined){
202 this.emptyServiceName = true;
205 console.log("a >",isValid);
206 if(this.dupliateName == true){
209 console.log("b> ",isValid);
210 if(this.ms.desc == ''
211 || this.ms.desc == undefined){
212 this.emptyServiceDesc = true;
215 console.log("c> ",isValid);
218 || this.ms.url == undefined){
219 this.emptyServiceURL = true;
222 console.log("d> ",isValid);
224 if(this.ms.appId == undefined
225 || this.ms.appId == null){
226 this.emptyServiceApp = true;
230 console.log("IsValid flag add/update microservices ",isValid )
235 * Check the parameter list, delete those parameters that don't
238 if(this.ms && this.ms.parameterList){
239 for(var i = 0; i < this.ms.parameterList.length; i++){
240 if(this.ms.parameterList[i].para_key == undefined
241 || this.ms.parameterList[i].para_key == null
242 || this.ms.parameterList[i].para_key == ""){
243 this.ms.parameterList.splice(i, 1);
248 if(this.ms.securityType == undefined ||
249 this.ms.securityType == null)
250 this.ms.securityType = "No Authentication";
252 this.ms.securityType = this.ms.securityType;
253 this.ms.username = this.ms.username;
254 this.ms.password = this.ms.password;
258 if(this.ms.active == true)
262 if(this.ms.parameterList && this.ms.parameterList.length >0){
263 paramList = this.ms.parameterList;
268 appId: this.ms.appId,
270 securityType: this.ms.securityType,
271 username: this.ms.username,
272 password: this.ms.password,
274 parameterList: paramList
278 console.log("Edit microservice mode called");
279 this.microservice.updateService(this.ms.id , newService)
280 .subscribe( data => {
282 console.log("update microservice response :: ",this.result);
283 this.passEntry.emit(this.result);
284 this.ngbModal.dismissAll();
287 this.ngbModal.dismissAll();
290 console.log("Add microservice mode called")
291 this.microservice.createService(newService)
292 .subscribe( data => {
294 console.log("add microservice response :: ",this.result);
295 this.passEntry.emit(this.result);
296 this.ngbModal.dismissAll();
298 this.ngbModal.dismissAll();