blob: 3d4917fd4517d79e7ad0f0f77fa40c39fbea5985 [file] [log] [blame]
Arielk802bd2a2018-04-16 15:37:39 +03001'use strict';
2
Arielkeaaf8012018-07-31 12:59:36 +03003export class OperationParameter {
4 name: string;
ys969316a9fce2020-01-19 13:50:02 +02005 type: string;
6 inputId?: string;
7 required?: boolean;
8 property?: string;
9 mandatory?: boolean;
Arielk802bd2a2018-04-16 15:37:39 +030010
Arielkc21ba952019-04-21 16:07:44 +030011 constructor(param?: any) {
Arielk802bd2a2018-04-16 15:37:39 +030012 if (param) {
Arielkeaaf8012018-07-31 12:59:36 +030013 this.name = param.name;
14 this.type = param.type;
ys969316a9fce2020-01-19 13:50:02 +020015 this.inputId = param.inputId ;
Arielk86a37522019-01-13 18:31:13 +020016 this.required = param.required;
ys969316a9fce2020-01-19 13:50:02 +020017 this.property = param.property;
18 this.mandatory = param.mandatory;
Arielk802bd2a2018-04-16 15:37:39 +030019 }
20 }
21}
22
23export interface IOperationParamsList {
Arielkeaaf8012018-07-31 12:59:36 +030024 listToscaDataDefinition: Array<OperationParameter>;
Arielk802bd2a2018-04-16 15:37:39 +030025}
26
Arielkaefe3912018-10-14 16:50:17 +030027export class WORKFLOW_ASSOCIATION_OPTIONS {
28 static NONE = 'NONE';
29 static NEW = 'NEW';
30 static EXISTING = 'EXISTING';
Arielkc21ba952019-04-21 16:07:44 +030031 static EXTERNAL = 'EXTERNAL';
Arielkaefe3912018-10-14 16:50:17 +030032}
33
Arielk86a37522019-01-13 18:31:13 +020034export class BEOperationModel {
35 name: string;
Arielkeaaf8012018-07-31 12:59:36 +030036 description: string;
Arielk802bd2a2018-04-16 15:37:39 +030037 uniqueId: string;
38
Arielk86a37522019-01-13 18:31:13 +020039 inputs: IOperationParamsList;
40 outputs: IOperationParamsList;
Arielkeaaf8012018-07-31 12:59:36 +030041
Arielkaefe3912018-10-14 16:50:17 +030042 workflowAssociationType: string;
Arielkeaaf8012018-07-31 12:59:36 +030043 workflowId: string;
44 workflowVersionId: string;
xuegao84a51512020-09-04 15:29:15 +020045 workflowName: string;
46 workflowVersion: string;
Arielkeaaf8012018-07-31 12:59:36 +030047
Arielk3d5b80b2019-05-13 15:30:27 +030048 implementation?: {
49 artifactName: string;
50 artifactUUID: string;
51 };
Arielke0c98682019-02-28 16:37:57 +020052
Arielk802bd2a2018-04-16 15:37:39 +030053 constructor(operation?: any) {
54 if (operation) {
Arielk86a37522019-01-13 18:31:13 +020055 this.name = operation.name;
Arielkaefe3912018-10-14 16:50:17 +030056 this.description = operation.description;
Arielk802bd2a2018-04-16 15:37:39 +030057 this.uniqueId = operation.uniqueId;
Arielkaefe3912018-10-14 16:50:17 +030058
Arielk86a37522019-01-13 18:31:13 +020059 this.inputs = operation.inputs;
60 this.outputs = operation.outputs;
Arielkaefe3912018-10-14 16:50:17 +030061
62 this.workflowAssociationType = operation.workflowAssociationType;
Arielkeaaf8012018-07-31 12:59:36 +030063 this.workflowId = operation.workflowId;
64 this.workflowVersionId = operation.workflowVersionId;
xuegao84a51512020-09-04 15:29:15 +020065 this.workflowName = operation.workflowName;
66 this.workflowVersion = operation.workflowVersion;
Arielk3d5b80b2019-05-13 15:30:27 +030067 this.implementation = operation.implementation || {};
Arielk802bd2a2018-04-16 15:37:39 +030068 }
69 }
70
Arielk86a37522019-01-13 18:31:13 +020071 public createInputsList(inputs: Array<OperationParameter>): void {
72 this.inputs = {
73 listToscaDataDefinition: inputs
Arielk802bd2a2018-04-16 15:37:39 +030074 };
75 }
76
Arielk86a37522019-01-13 18:31:13 +020077 public createOutputsList(outputs: Array<OperationParameter>): void {
78 this.outputs = {
79 listToscaDataDefinition: _.map(outputs, output => {
80 delete output.inputId;
81 return output;
Arielk502b7b72018-10-03 14:06:13 +030082 })
Arielk802bd2a2018-04-16 15:37:39 +030083 };
84 }
85}
86
ys969316a9fce2020-01-19 13:50:02 +020087export class OperationModel extends BEOperationModel{
Arielk86a37522019-01-13 18:31:13 +020088 interfaceType: string;
89 interfaceId: string;
ys969316a9fce2020-01-19 13:50:02 +020090 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;
xuegao84a51512020-09-04 15:29:15 +0200101 workflowName: string;
102 workflowVersion: string;
ys969316a9fce2020-01-19 13:50:02 +0200103
104 protected OperationTypeEnum: Array<String> = [
105 'Create',
106 'Delete',
107 'Instantiate',
108 'Start',
109 'Stop'
110 ];
Arielk86a37522019-01-13 18:31:13 +0200111
112 constructor(operation?: any) {
113 super(operation);
114 if (operation) {
115 this.interfaceId = operation.interfaceId;
116 this.interfaceType = operation.interfaceType;
ys969316a9fce2020-01-19 13:50:02 +0200117 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;
Arielk3d5b80b2019-05-13 15:30:27 +0300124 this.artifactFileName = operation.artifactFileName;
125 this.artifactData = operation.artifactData;
xuegao84a51512020-09-04 15:29:15 +0200126 this.workflowName = operation.workflowName;
127 this.workflowVersion = operation.workflowVersion;
Arielk86a37522019-01-13 18:31:13 +0200128 }
129 }
130
Arielkafd5f952019-01-27 16:30:57 +0200131 public displayType(): string {
Arielk3d5b80b2019-05-13 15:30:27 +0300132 return displayType(this.interfaceType);
Arielk86a37522019-01-13 18:31:13 +0200133 }
ys969316a9fce2020-01-19 13:50:02 +0200134
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
148export interface CreateOperationResponse extends OperationModel {
149 artifactUUID: string;
Arielk86a37522019-01-13 18:31:13 +0200150}
151
Arielk86a37522019-01-13 18:31:13 +0200152export 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 {
Arielk3d5b80b2019-05-13 15:30:27 +0300166 return displayType(this.type);
Arielk86a37522019-01-13 18:31:13 +0200167 }
Arielk802bd2a2018-04-16 15:37:39 +0300168}
Arielk3d5b80b2019-05-13 15:30:27 +0300169
ys969316a9fce2020-01-19 13:50:02 +0200170const displayType = (type:string) => type && type.substr(type.lastIndexOf('.') + 1);