summaryrefslogtreecommitdiffstats
path: root/sdc-workflow-designer-ui/src/app/components/property/rest-task/rest-task.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'sdc-workflow-designer-ui/src/app/components/property/rest-task/rest-task.component.ts')
-rw-r--r--sdc-workflow-designer-ui/src/app/components/property/rest-task/rest-task.component.ts180
1 files changed, 168 insertions, 12 deletions
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
index 0dccee1e..3def276f 100644
--- 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
@@ -14,7 +14,6 @@ import { Subscription } from 'rxjs/Subscription';
import { TranslateService } from '@ngx-translate/core';
import { PlanTreeviewItem } from '../../../model/plan-treeview-item';
-import { Swagger, SwaggerMethod, SwaggerParameter, SwaggerResponse } from '../../../model/swagger';
import { ValueSource } from '../../../model/value-source.enum';
import { ValueType } from '../../../model/value-type.enum';
import { RestParameter } from '../../../model/workflow/rest-parameter';
@@ -23,24 +22,49 @@ import { BroadcastService } from '../../../services/broadcast.service';
import { NoticeService } from '../../../services/notice.service';
import { RestService } from '../../../services/rest.service';
import { WorkflowUtil } from '../../../util/workflow-util';
+import { NodeTypeService } from '../../../services/node-type.service';
+import { NodeDataType } from '../../../model/node-data-type/node-data-type';
+import { SwaggerBaseParameter } from "../../../model/workflow/swagger/swagger-base-parameter";
+import { SwaggerResponse } from "../../../model/workflow/swagger/swagger-response";
+import { Swagger, SwaggerMethod } from '../../../model/swagger';
+import { SwaggerBodyParameter } from '../../../model/workflow/swagger/swagger-body-parameter';
+import { SwaggerNormalParameter } from '../../../model/workflow/swagger/swagger-normal-parameter';
+import { SwaggerSchema } from '../../../model/workflow/swagger/swagger-schema';
+import { SwaggerIn } from '../../../model/workflow/swagger/swagger-in.enum';
@Component({
- selector: 'b4t-rest-task',
+ selector: 'wfm-rest-task',
templateUrl: 'rest-task.component.html',
})
export class RestTaskComponent implements OnInit {
@Input() public node: RestTask;
@Input() public planItems: PlanTreeviewItem[];
+
public swaggerJson: any = {};
- public restInterfaces: any[];
- public restOperations: any = [];
+ public restInterfaces = [];
+ public restOperations = [];
+ public loadSwaggerByMSB = true;
+ // public dataTypeInput: SwaggerBaseParameter[] = [];
+ public dataTypeOutput: SwaggerResponse[] = [];
+ public definitions: SwaggerSchema;
private swagger: Swagger;
- constructor(private broadcastService: BroadcastService, public restService: RestService,
+ constructor(private nodeTypeService: NodeTypeService, private broadcastService: BroadcastService, public restService: RestService,
private noticeService: NoticeService, private translate: TranslateService) { }
public ngOnInit() {
- this.loadInterfaces();
+ const nodeDataType = this.nodeTypeService.getNodeDataTypeById(this.node.typeId);
+ // if (nodeDataType.content && nodeDataType.content.baseUrl && nodeDataType.content.serviceName && nodeDataType.content.version
+ // && nodeDataType.content.path && nodeDataType.content.method && nodeDataType.content.consumes) {
+ if (nodeDataType && nodeDataType.content && nodeDataType.content.baseUrl && nodeDataType.content.serviceName
+ && nodeDataType.content.serviceVersion && nodeDataType.content.path && nodeDataType.content.method) {
+ this.loadSwaggerByMSB = false;
+ }
+ if (this.loadSwaggerByMSB) {
+ this.loadInterfaces();
+ } else {
+ this.setParametersByDataType(nodeDataType);
+ }
}
public serviceChanged(configId: string) {
@@ -64,10 +88,15 @@ export class RestTaskComponent implements OnInit {
this.updateMethodInfo();
}
- private loadInterfaces() {
+ private loadInterfaces(): void {
if (this.node.restConfigId) {
- this.swagger = this.restService.getSwaggerInfo(this.node.restConfigId);
+ // this.swagger = this.restService.getSwaggerInfo(this.node.restConfigId);
+ let restConfig = this.restService.getRestConfig(this.node.restConfigId);
+ this.node.baseUrl = restConfig.url;
+ this.node.serviceName = restConfig.name;
+ this.node.serviceVersion = restConfig.version;
+ this.swagger = restConfig.swagger;
if (this.swagger) {
this.restInterfaces = [];
for (const key of Object.keys(this.swagger.paths)) {
@@ -82,7 +111,7 @@ export class RestTaskComponent implements OnInit {
}
}
- private loadOperations() {
+ private loadOperations(): void {
if (this.node.path) {
const swaggerPath: any = this.swagger.paths[this.node.path];
@@ -93,7 +122,7 @@ export class RestTaskComponent implements OnInit {
}
}
- private updateMethodInfo() {
+ private updateMethodInfo(): void {
if (this.node.method) {
const path: any = this.swagger.paths[this.node.path];
const method: SwaggerMethod = path[this.node.method];
@@ -103,8 +132,10 @@ export class RestTaskComponent implements OnInit {
let tempParameters: RestParameter[] = [];
method.parameters.forEach(param => {
- const nodeParam = new RestParameter(param.name, '', ValueSource[ValueSource.String],
- ValueType[ValueType.String], param.position, param.schema, param.required);
+ let defaultType = SwaggerIn[SwaggerIn.body] === param.position ? ValueType[ValueType.object] : ValueType[ValueType.string];
+ const type = param.type ? param.type : defaultType;
+ const nodeParam = new RestParameter(param.name, undefined, ValueSource[ValueSource.string],
+ type, param.position, param.schema, param.required);
tempParameters.push(WorkflowUtil.deepClone(nodeParam));
});
this.node.parameters = tempParameters;
@@ -114,4 +145,129 @@ export class RestTaskComponent implements OnInit {
this.node.responses = responseParams.map(param => WorkflowUtil.deepClone(param));
}
}
+
+ private setParametersByDataType(nodeDataType: NodeDataType): void {
+ this.node.serviceName = nodeDataType.content.serviceName;
+ this.node.serviceVersion = nodeDataType.content.serviceVersion;
+ this.node.restConfigId = this.node.serviceName;
+ if (this.node.serviceVersion) {
+ this.node.restConfigId += ('.' + this.node.serviceVersion);
+ }
+ this.node.baseUrl = nodeDataType.content.baseUrl;
+ this.node.path = nodeDataType.content.path;
+ this.node.method = nodeDataType.content.method;
+ this.node.consumes = nodeDataType.content.consumes;
+ this.node.produces = nodeDataType.content.produces;
+ this.definitions = nodeDataType.definitions;
+ if (nodeDataType.content.inputs) {
+ for (const key in nodeDataType.content.inputs) {
+ if (nodeDataType.content.inputs.hasOwnProperty(key)) {
+ // Set default value of dataType
+ const element = nodeDataType.content.inputs[key];
+ let param: SwaggerBaseParameter = this.getParameterByDataType(element, key);
+ if (param) {
+ // Set exist value
+ let found = false;
+ if (this.node.parameters) {
+ for (let p = 0; p < this.node.parameters.length; p++) {
+ if (param.name === this.node.parameters[p].name) {
+ found = true;
+ let value = this.node.parameters[p].value;
+ let valueSource = this.node.parameters[p].valueSource;
+ param.value = value;
+ param.valueSource = valueSource;
+ this.node.parameters[p] = param;
+ break;
+ }
+ }
+ } else {
+ this.node.parameters = [];
+ }
+ if (!found) {
+ this.node.parameters.push(param);
+ }
+ }
+ }
+ }
+ }
+ if (nodeDataType.content.outputs) {
+ for (const key in nodeDataType.content.outputs) {
+ if (nodeDataType.content.outputs.hasOwnProperty(key)) {
+ // Set default value of dataType
+ const element = nodeDataType.content.outputs[key];
+ this.dataTypeOutput.push(this.getResponseByDataType(element, key));
+ }
+ }
+ }
+ }
+
+ private getParameterByDataType(dataTypeParameter: SwaggerBaseParameter, name: string): SwaggerBaseParameter {
+ if (!dataTypeParameter.name) {
+ dataTypeParameter.name = name;
+ }
+ if (SwaggerIn[SwaggerIn.body] === dataTypeParameter.in) {
+ return this.initBodyParam(dataTypeParameter as SwaggerBodyParameter);
+ } else {
+ return this.initNormalParam(dataTypeParameter as SwaggerNormalParameter);
+ }
+ }
+
+ private getResponseByDataType(dataTypeResponse: SwaggerResponse, name: string): SwaggerResponse {
+ let responseParam = dataTypeResponse;
+ if (!responseParam.name) {
+ responseParam.name = name;
+ }
+ return this.initResponseParam(responseParam);
+ }
+
+ private initNormalParam(normalParam: SwaggerNormalParameter): SwaggerNormalParameter {
+ let normal = WorkflowUtil.deepClone(normalParam);
+ // Set default value of dataType
+ if (undefined === normalParam.show) {
+ normal.show = true;
+ }
+ if ('path' === normalParam.in) {
+ normal.required = true;
+ } else if (undefined === normalParam.required) {
+ normal.required = false;
+ }
+ if (undefined === normalParam.allowEmptyValue) {
+ normal.allowEmptyValue = false;
+ }
+ if (undefined === normalParam.collectionFormat) {
+ normal.collectionFormat = 'csv';
+ }
+ if (undefined === normalParam.type) {
+ normal.type == ValueType[ValueType.string];
+ }
+ // editable not support
+ return normal;
+ }
+
+ private initBodyParam(bodyParam: SwaggerBodyParameter): SwaggerBodyParameter {
+ let body = WorkflowUtil.deepClone(bodyParam);
+ // Set default value of dataType
+ if (undefined === bodyParam.show) {
+ body.show = true;
+ }
+ if (undefined === bodyParam.required) {
+ body.required = false;
+ }
+ if (undefined === bodyParam.valueSource) {
+ body.valueSource = ValueSource[ValueSource.Definition];
+ }
+ if (undefined === bodyParam.schema.type) {
+ body.schema.type == ValueType[ValueType.string];
+ }
+ // $ref not support
+ if (bodyParam.$ref) {
+ console.warn('Do not support body parameter $ref.');
+ }
+ return body;
+ }
+
+ private initResponseParam(responseParam: SwaggerResponse): SwaggerResponse {
+ let response = responseParam;
+ return response;
+ }
}