bug fixes to operation screen and External workflowartifact completion
[sdc.git] / catalog-ui / src / app / models / operation.ts
1 'use strict';
2
3 export class OperationParameter {
4     name: string;
5     type: String;
6     inputId: string;
7     required: boolean;
8
9     constructor(param?: any) {
10         if (param) {
11             this.name = param.name;
12             this.type = param.type;
13             this.inputId = param.inputId;
14             this.required = param.required;
15         }
16     }
17 }
18
19 export interface IOperationParamsList {
20     listToscaDataDefinition: Array<OperationParameter>;
21 }
22
23 export class WORKFLOW_ASSOCIATION_OPTIONS {
24     static NONE = 'NONE';
25     static NEW = 'NEW';
26     static EXISTING = 'EXISTING';
27     static EXTERNAL = 'EXTERNAL';
28 }
29
30 export class BEOperationModel {
31     name: string;
32     description: string;
33     uniqueId: string;
34
35     inputs: IOperationParamsList;
36     outputs: IOperationParamsList;
37
38     workflowAssociationType: string;
39     workflowId: string;
40     workflowVersionId: string;
41
42     implementation?: { artifactUUID: string; };
43
44     constructor(operation?: any) {
45         if (operation) {
46             this.name = operation.name;
47             this.description = operation.description;
48             this.uniqueId = operation.uniqueId;
49
50             this.inputs = operation.inputs;
51             this.outputs = operation.outputs;
52
53             this.workflowAssociationType = operation.workflowAssociationType;
54             this.workflowId = operation.workflowId;
55             this.workflowVersionId = operation.workflowVersionId;
56             this.implementation = operation.implementation;
57         }
58     }
59
60     public createInputsList(inputs: Array<OperationParameter>): void {
61         this.inputs = {
62             listToscaDataDefinition: inputs
63         };
64     }
65
66     public createOutputsList(outputs: Array<OperationParameter>): void {
67         this.outputs = {
68             listToscaDataDefinition: _.map(outputs, output => {
69                 delete output.inputId;
70                 return output;
71             })
72         };
73     }
74 }
75
76 export class OperationModel extends BEOperationModel {
77     interfaceType: string;
78     interfaceId: string;
79     artifactFile: any;
80     artifactData: any;
81
82     constructor(operation?: any) {
83         super(operation);
84         if (operation) {
85             this.interfaceId = operation.interfaceId;
86             this.interfaceType = operation.interfaceType;
87         }
88     }
89
90     public displayType(): string {
91         const lastDot = this.interfaceType ? this.interfaceType.lastIndexOf('.') : -1;
92         return lastDot === -1 ? this.interfaceType : this.interfaceType.substr(lastDot + 1);
93     }
94 }
95
96 export class InterfaceModel {
97     type: string;
98     uniqueId: string;
99     operations: Array<OperationModel>;
100
101     constructor(interf?: any) {
102         if (interf) {
103             this.type = interf.type;
104             this.uniqueId = interf.uniqueId;
105             this.operations = interf.operations;
106         }
107     }
108
109     public displayType(): string {
110         const lastDot = this.type ? this.type.lastIndexOf('.') : -1;
111         return lastDot === -1 ? this.type : this.type.substr(lastDot + 1);
112     }
113 }