Catalog alignment
[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
46     implementation?: {
47         artifactName: string;
48         artifactUUID: string;
49     };
50
51     constructor(operation?: any) {
52         if (operation) {
53             this.name = operation.name;
54             this.description = operation.description;
55             this.uniqueId = operation.uniqueId;
56
57             this.inputs = operation.inputs;
58             this.outputs = operation.outputs;
59
60             this.workflowAssociationType = operation.workflowAssociationType;
61             this.workflowId = operation.workflowId;
62             this.workflowVersionId = operation.workflowVersionId;
63             this.implementation = operation.implementation || {};
64         }
65     }
66
67     public createInputsList(inputs: Array<OperationParameter>): void {
68         this.inputs = {
69             listToscaDataDefinition: inputs
70         };
71     }
72
73     public createOutputsList(outputs: Array<OperationParameter>): void {
74         this.outputs = {
75             listToscaDataDefinition: _.map(outputs, output => {
76                 delete output.inputId;
77                 return output;
78             })
79         };
80     }
81 }
82
83 export class OperationModel extends BEOperationModel{
84     interfaceType: string;
85     interfaceId: string;
86     operationType: string;
87     description: string;
88     uniqueId: string;
89     artifactFileName?: string;
90     artifactData?: any;
91
92     inputParams: IOperationParamsList;
93     outputParams: IOperationParamsList;
94
95     workflowId: string;
96     workflowVersionId: string;
97
98     protected OperationTypeEnum: Array<String> = [
99         'Create',
100         'Delete',
101         'Instantiate',
102         'Start',
103         'Stop'
104     ];
105
106     constructor(operation?: any) {
107         super(operation);
108         if (operation) {
109             this.interfaceId = operation.interfaceId;
110             this.interfaceType = operation.interfaceType;
111             this.description = operation.description;
112             this.inputParams = operation.inputParams;
113             this.operationType = operation.operationType;
114             this.outputParams = operation.outputParams;
115             this.uniqueId = operation.uniqueId;
116             this.workflowId = operation.workflowId;
117             this.workflowVersionId = operation.workflowVersionId;
118             this.artifactFileName = operation.artifactFileName;
119             this.artifactData = operation.artifactData;
120         }
121     }
122
123     public displayType(): string {
124         return displayType(this.interfaceType);
125     }
126
127     public createInputParamsList(inputParams: Array<OperationParameter>): void {
128         this.inputParams = {
129             listToscaDataDefinition: inputParams
130         };
131     }
132
133     public createOutputParamsList(outputParams: Array<OperationParameter>): void {
134         this.outputParams = {
135             listToscaDataDefinition: outputParams
136         };
137     }
138 }
139
140 export interface CreateOperationResponse extends OperationModel {
141     artifactUUID: string;
142 }
143
144 export class InterfaceModel {
145     type: string;
146     uniqueId: string;
147     operations: Array<OperationModel>;
148
149     constructor(interf?: any) {
150         if (interf) {
151             this.type = interf.type;
152             this.uniqueId = interf.uniqueId;
153             this.operations = interf.operations;
154         }
155     }
156
157     public displayType(): string {
158         return displayType(this.type);
159     }
160 }
161
162 const displayType = (type:string) => type && type.substr(type.lastIndexOf('.') + 1);