aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/services/workflow.service.ts
blob: ae06a397134c18e392dcd62b1b237187ea360551 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Injectable, Inject } from "@angular/core";
import { Response } from "@angular/http";
import { Observable } from "rxjs/Observable";
import { HttpService } from "./http.service";
import { SdcConfigToken, ISdcConfig } from "../config/sdc-config.config";

@Injectable()
export class WorkflowServiceNg2 {

    protected baseUrl;
    protected catalogBaseUrl;

    VERSION_STATE_CERTIFIED = 'CERTIFIED';

    constructor(private http: HttpService, @Inject(SdcConfigToken) sdcConfig:ISdcConfig) {
        this.baseUrl = sdcConfig.api.workflow_root;
        this.catalogBaseUrl = sdcConfig.api.POST_workflow_artifact;
    }

    public getWorkflows(filterCertified: boolean = true): Observable<any> {
        return this.http.get(this.baseUrl + '/workflows' + (filterCertified ? '?versionState=' + this.VERSION_STATE_CERTIFIED : ''))
            .map((res:Response) => {
                return res.json().items;
            });
    }

    public getWorkflowVersions(workflowId: string, filterCertified: boolean = true): Observable<any> {
        return this.http.get(this.baseUrl + '/workflows/' + workflowId + '/versions' + (filterCertified ? '?state=' + this.VERSION_STATE_CERTIFIED : ''))
            .map((res:Response) => {
                return res.json().items;
            });
    }

    public updateWorkflowVersion(workflowId: string, versionId: string, payload: any): Observable<any> {
        return this.http.put(this.baseUrl + '/workflows/' + workflowId + '/versions/' + versionId, payload)
            .map((res:Response) => {
                return res.json();
            });
    }

    public associateWorkflowArtifact(resourceUuid, operationId, workflowId, workflowVersionId, artifactUuid): Observable<any> {
        return this.http.post(this.baseUrl + '/workflows/' + workflowId + '/versions/' + workflowVersionId + '/artifact-deliveries', {
                endpoint: this.catalogBaseUrl + '/resources/' + resourceUuid + '/interfaces/' + operationId + '/artifacts/' + artifactUuid,
                method: 'POST'
            })
            .map((res:Response) => {
                return res.json();
            });
    }

}