support set body parameter by json
[sdc/sdc-workflow-designer.git] / sdc-workflow-designer-ui / src / app / services / workflow-config.service.ts
1 /**\r
2  * Copyright (c) 2017 ZTE Corporation.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the terms of the Eclipse Public License v1.0\r
5  * and the Apache License 2.0 which both accompany this distribution,\r
6  * and are available at http://www.eclipse.org/legal/epl-v10.html\r
7  * and http://www.apache.org/licenses/LICENSE-2.0\r
8  *\r
9  * Contributors:\r
10  *     ZTE - initial API and implementation and/or initial documentation\r
11  */\r
12 \r
13 import { Injectable } from '@angular/core';\r
14 import { WorkflowService } from "./workflow.service";\r
15 import { Microservice } from "../model/workflow/microservice";\r
16 import { Observable } from "rxjs/Rx";\r
17 import { HttpService } from "../util/http.service";\r
18 import { Swagger, SwaggerSchemaObject } from "../model/swagger";\r
19 \r
20 /**\r
21  * WorkflowConfigService\r
22  * provides all of the operations about workflow configs.\r
23  */\r
24 @Injectable()\r
25 export class WorkflowConfigService {\r
26     constructor(private httpService: HttpService, private workflowService: WorkflowService) {}\r
27 \r
28     public getMicroservices(): Microservice[] {\r
29         return this.workflowService.workflow.configs.microservices;\r
30     }\r
31 \r
32     public loadDynamicInfo(url: string): Observable<any> {\r
33         const options: any = {\r
34             headers: {\r
35                 Accept: 'application/json',\r
36             },\r
37         };\r
38         return this.httpService.get(url).map(response => response.data);\r
39     }\r
40 \r
41     public getSwaggerInfo(serviceName: string, version: string): Swagger {\r
42         const microservice = this.getMicroservices().find(service => (service.name === serviceName && service.version === version));\r
43         if(microservice) {\r
44             return microservice.swagger;\r
45         } else {\r
46             return undefined;\r
47         }\r
48     }\r
49 \r
50     public getDefinition(swagger: Swagger, position: string): SwaggerSchemaObject {\r
51         const definitionName = position.substring('#/definitions/'.length);\r
52 \r
53         return swagger.definitions[definitionName];\r
54     }\r
55 \r
56 }\r