3d4917fd4517d79e7ad0f0f77fa40c39fbea5985
[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     protected OperationTypeEnum: Array<String> = [
105         'Create',
106         'Delete',
107         'Instantiate',
108         'Start',
109         'Stop'
110     ];
111
112     constructor(operation?: any) {
113         super(operation);
114         if (operation) {
115             this.interfaceId = operation.interfaceId;
116             this.interfaceType = operation.interfaceType;
117             this.description = operation.description;
118             this.inputParams = operation.inputParams;
119             this.operationType = operation.operationType;
120             this.outputParams = operation.outputParams;
121             this.uniqueId = operation.uniqueId;
122             this.workflowId = operation.workflowId;
123             this.workflowVersionId = operation.workflowVersionId;
124             this.artifactFileName = operation.artifactFileName;
125             this.artifactData = operation.artifactData;
126             this.workflowName = operation.workflowName;
127             this.workflowVersion = operation.workflowVersion;
128         }
129     }
130
131     public displayType(): string {
132         return displayType(this.interfaceType);
133     }
134
135     public createInputParamsList(inputParams: Array<OperationParameter>): void {
136         this.inputParams = {
137             listToscaDataDefinition: inputParams
138         };
139     }
140
141     public createOutputParamsList(outputParams: Array<OperationParameter>): void {
142         this.outputParams = {
143             listToscaDataDefinition: outputParams
144         };
145     }
146 }
147
148 export interface CreateOperationResponse extends OperationModel {
149     artifactUUID: string;
150 }
151
152 export class InterfaceModel {
153     type: string;
154     uniqueId: string;
155     operations: Array<OperationModel>;
156
157     constructor(interf?: any) {
158         if (interf) {
159             this.type = interf.type;
160             this.uniqueId = interf.uniqueId;
161             this.operations = interf.operations;
162         }
163     }
164
165     public displayType(): string {
166         return displayType(this.type);
167     }
168 }
169
170 const displayType = (type:string) => type && type.substr(type.lastIndexOf('.') + 1);