From 08a13945e82270e6bf27c2d6b26a5dde127ad198 Mon Sep 17 00:00:00 2001 From: Lvbo163 Date: Mon, 4 Sep 2017 19:57:31 +0800 Subject: support rest task node support rest task node to call rest api definited by swagger Issue-ID: SDC-271 Change-Id: Ifb4acdd393609da4ce1e9e2cd8d20a2848365b9b Signed-off-by: Lvbo163 --- .../components/property/properties.component.html | 1 + .../property/rest-task/rest-task.component.html | 44 ++++++++ .../property/rest-task/rest-task.component.ts | 113 +++++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 sdc-workflow-designer-ui/src/app/components/property/rest-task/rest-task.component.html create mode 100644 sdc-workflow-designer-ui/src/app/components/property/rest-task/rest-task.component.ts (limited to 'sdc-workflow-designer-ui/src/app/components') diff --git a/sdc-workflow-designer-ui/src/app/components/property/properties.component.html b/sdc-workflow-designer-ui/src/app/components/property/properties.component.html index d7a8500d..2ca5c690 100644 --- a/sdc-workflow-designer-ui/src/app/components/property/properties.component.html +++ b/sdc-workflow-designer-ui/src/app/components/property/properties.component.html @@ -40,4 +40,5 @@ + diff --git a/sdc-workflow-designer-ui/src/app/components/property/rest-task/rest-task.component.html b/sdc-workflow-designer-ui/src/app/components/property/rest-task/rest-task.component.html new file mode 100644 index 00000000..75422581 --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/components/property/rest-task/rest-task.component.html @@ -0,0 +1,44 @@ + + +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+
diff --git a/sdc-workflow-designer-ui/src/app/components/property/rest-task/rest-task.component.ts b/sdc-workflow-designer-ui/src/app/components/property/rest-task/rest-task.component.ts new file mode 100644 index 00000000..654d19b9 --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/components/property/rest-task/rest-task.component.ts @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2017 ZTE Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * ZTE - initial API and implementation and/or initial documentation + *******************************************************************************/ +import { AfterViewInit, Component, Input, OnInit } from '@angular/core'; +import { Subscription } from 'rxjs/Subscription'; + +import { Swagger, SwaggerMethod, SwaggerParameter, SwaggerResponse } from '../../../model/swagger'; +import { ValueSource } from '../../../model/value-source.enum'; +import { ValueType } from '../../../model/value-type.enum'; +import { RestTask } from '../../../model/workflow/rest-task'; +import { BroadcastService } from '../../../services/broadcast.service'; +import { WorkflowConfigService } from '../../../services/workflow-config.service'; +import { Microservice } from "../../../model/workflow/microservice"; + +@Component({ + selector: 'b4t-rest-task', + templateUrl: 'rest-task.component.html', +}) +export class RestTaskComponent implements AfterViewInit, OnInit { + @Input() public node: RestTask; + public swaggerJson: any = {}; + public restInterfaces: any[]; + public restOperations: any = []; + public microservices: Microservice[]; + public selectedMicroservice: Microservice; + private swagger: Swagger; + + constructor(private broadcastService: BroadcastService, + private configService: WorkflowConfigService) { } + + ngOnInit(): void { + this.microservices = this.configService.getMicroservices(); + this.selectedMicroservice = this.microservices.find(service => + (this.node.serviceName === service.name && this.node.serviceVersion === service.version)); + } + public ngAfterViewInit() { + setTimeout(() => { + this.loadInterfaces(); + }, 0); + } + + public getText4Microservice(microservice: Microservice): string { + return `${microservice.name} [${microservice.version}] `; + } + + public serviceChanged(service: Microservice) { + this.selectedMicroservice = service; + this.node.serviceName = service.name; + this.node.serviceVersion = service.version; + this.urlChanged(''); + this.loadInterfaces(); + } + + public urlChanged(url: string) { + this.node.url = url; + + this.node.consumes = []; + this.node.produces = []; + this.methodChanged(''); + + this.loadOperations(); + } + + public methodChanged(method: string) { + this.node.method = method; + + this.node.parameters = []; + this.node.responses = []; + + this.updateMethodInfo(); + } + + + private loadInterfaces() { + if (this.node.serviceName && this.node.serviceVersion) { + this.swagger = this.configService.getSwaggerInfo(this.node.serviceName, this.node.serviceVersion); + + if (this.swagger) { + this.restInterfaces = []; + for (const key of Object.keys(this.swagger.paths)) { + this.restInterfaces.push(key); + } + this.loadOperations(); + } else { + // TODO error handler + } + } + } + + private loadOperations() { + if (this.node.url) { + const swaggerPath: any = this.swagger.paths[this.node.url]; + + this.restOperations = []; + for (const key of Object.keys(swaggerPath)) { + this.restOperations.push(key); + } + } + } + + private updateMethodInfo() { + // TODO update parameters + console.log('rest task updated'); + } +} -- cgit 1.2.3-korg