UI Support for operation milestones
[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     property?: string;
9     mandatory?: boolean;
10
11     constructor(param?: any) {
12         if (param) {
13             this.name = param.name;
14             this.type = param.type;
15             this.inputId = param.inputId ;
16             this.required = param.required;
17             this.property = param.property;
18             this.mandatory = param.mandatory;
19         }
20     }
21 }
22
23 export interface IOperationParamsList {
24     listToscaDataDefinition: Array<OperationParameter>;
25 }
26
27 export class WORKFLOW_ASSOCIATION_OPTIONS {
28     static NONE = 'NONE';
29     static NEW = 'NEW';
30     static EXISTING = 'EXISTING';
31     static EXTERNAL = 'EXTERNAL';
32 }
33
34 export class BEOperationModel {
35     name: string;
36     description: string;
37     uniqueId: string;
38
39     inputs: IOperationParamsList;
40     outputs: IOperationParamsList;
41
42     workflowAssociationType: string;
43     workflowId: string;
44     workflowVersionId: string;
45     workflowName: string;
46     workflowVersion: string;
47
48     implementation?: {
49         artifactName: string;
50         artifactUUID: string;
51     };
52
53     constructor(operation?: any) {
54         if (operation) {
55             this.name = operation.name;
56             this.description = operation.description;
57             this.uniqueId = operation.uniqueId;
58
59             this.inputs = operation.inputs;
60             this.outputs = operation.outputs;
61
62             this.workflowAssociationType = operation.workflowAssociationType;
63             this.workflowId = operation.workflowId;
64             this.workflowVersionId = operation.workflowVersionId;
65             this.workflowName = operation.workflowName;
66             this.workflowVersion = operation.workflowVersion;
67             this.implementation = operation.implementation || {};
68         }
69     }
70
71     public createInputsList(inputs: Array<OperationParameter>): void {
72         this.inputs = {
73             listToscaDataDefinition: inputs
74         };
75     }
76
77     public createOutputsList(outputs: Array<OperationParameter>): void {
78         this.outputs = {
79             listToscaDataDefinition: _.map(outputs, output => {
80                 delete output.inputId;
81                 return output;
82             })
83         };
84     }
85 }
86
87 export class OperationModel extends BEOperationModel{
88     interfaceType: string;
89     interfaceId: string;
90     operationType: string;
91     description: string;
92     uniqueId: string;
93     artifactFileName?: string;
94     artifactData?: any;
95
96     inputParams: IOperationParamsList;
97     outputParams: IOperationParamsList;
98
99     workflowId: string;
100     workflowVersionId: string;
101     workflowName: string;
102     workflowVersion: string;
103
104     milestones: Object;
105
106     protected OperationTypeEnum: Array<String> = [
107         'Create',
108         'Delete',
109         'Instantiate',
110         'Start',
111         'Stop'
112     ];
113
114     constructor(operation?: any) {
115         super(operation);
116         if (operation) {
117             this.interfaceId = operation.interfaceId;
118             this.interfaceType = operation.interfaceType;
119             this.description = operation.description;
120             this.inputParams = operation.inputParams;
121             this.operationType = operation.operationType;
122             this.outputParams = operation.outputParams;
123             this.uniqueId = operation.uniqueId;
124             this.workflowId = operation.workflowId;
125             this.workflowVersionId = operation.workflowVersionId;
126             this.artifactFileName = operation.artifactFileName;
127             this.artifactData = operation.artifactData;
128             this.workflowName = operation.workflowName;
129             this.workflowVersion = operation.workflowVersion;
130             this.milestones = operation.milestones;
131         }
132     }
133
134     public displayType(): string {
135         return displayType(this.interfaceType);
136     }
137
138     public createInputParamsList(inputParams: Array<OperationParameter>): void {
139         this.inputParams = {
140             listToscaDataDefinition: inputParams
141         };
142     }
143
144     public createOutputParamsList(outputParams: Array<OperationParameter>): void {
145         this.outputParams = {
146             listToscaDataDefinition: outputParams
147         };
148     }
149 }
150
151 export interface CreateOperationResponse extends OperationModel {
152     artifactUUID: string;
153 }
154
155 export class InterfaceModel {
156     type: string;
157     uniqueId: string;
158     operations: Array<OperationModel>;
159
160     constructor(interf?: any) {
161         if (interf) {
162             this.type = interf.type;
163             this.uniqueId = interf.uniqueId;
164             this.operations = interf.operations;
165         }
166     }
167
168     public displayType(): string {
169         return displayType(this.type);
170     }
171 }
172
173 const displayType = (type:string) => type && type.substr(type.lastIndexOf('.') + 1);