blob: 30095b92ef532ae9b3a0ddedf1f67e1c36a42a06 [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;
45
Arielk3d5b80b2019-05-13 15:30:27 +030046 implementation?: {
47 artifactName: string;
48 artifactUUID: string;
49 };
Arielke0c98682019-02-28 16:37:57 +020050
Arielk802bd2a2018-04-16 15:37:39 +030051 constructor(operation?: any) {
52 if (operation) {
Arielk86a37522019-01-13 18:31:13 +020053 this.name = operation.name;
Arielkaefe3912018-10-14 16:50:17 +030054 this.description = operation.description;
Arielk802bd2a2018-04-16 15:37:39 +030055 this.uniqueId = operation.uniqueId;
Arielkaefe3912018-10-14 16:50:17 +030056
Arielk86a37522019-01-13 18:31:13 +020057 this.inputs = operation.inputs;
58 this.outputs = operation.outputs;
Arielkaefe3912018-10-14 16:50:17 +030059
60 this.workflowAssociationType = operation.workflowAssociationType;
Arielkeaaf8012018-07-31 12:59:36 +030061 this.workflowId = operation.workflowId;
62 this.workflowVersionId = operation.workflowVersionId;
Arielk3d5b80b2019-05-13 15:30:27 +030063 this.implementation = operation.implementation || {};
Arielk802bd2a2018-04-16 15:37:39 +030064 }
65 }
66
Arielk86a37522019-01-13 18:31:13 +020067 public createInputsList(inputs: Array<OperationParameter>): void {
68 this.inputs = {
69 listToscaDataDefinition: inputs
Arielk802bd2a2018-04-16 15:37:39 +030070 };
71 }
72
Arielk86a37522019-01-13 18:31:13 +020073 public createOutputsList(outputs: Array<OperationParameter>): void {
74 this.outputs = {
75 listToscaDataDefinition: _.map(outputs, output => {
76 delete output.inputId;
77 return output;
Arielk502b7b72018-10-03 14:06:13 +030078 })
Arielk802bd2a2018-04-16 15:37:39 +030079 };
80 }
81}
82
ys969316a9fce2020-01-19 13:50:02 +020083export class OperationModel extends BEOperationModel{
Arielk86a37522019-01-13 18:31:13 +020084 interfaceType: string;
85 interfaceId: string;
ys969316a9fce2020-01-19 13:50:02 +020086 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 ];
Arielk86a37522019-01-13 18:31:13 +0200105
106 constructor(operation?: any) {
107 super(operation);
108 if (operation) {
109 this.interfaceId = operation.interfaceId;
110 this.interfaceType = operation.interfaceType;
ys969316a9fce2020-01-19 13:50:02 +0200111 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;
Arielk3d5b80b2019-05-13 15:30:27 +0300118 this.artifactFileName = operation.artifactFileName;
119 this.artifactData = operation.artifactData;
Arielk86a37522019-01-13 18:31:13 +0200120 }
121 }
122
Arielkafd5f952019-01-27 16:30:57 +0200123 public displayType(): string {
Arielk3d5b80b2019-05-13 15:30:27 +0300124 return displayType(this.interfaceType);
Arielk86a37522019-01-13 18:31:13 +0200125 }
ys969316a9fce2020-01-19 13:50:02 +0200126
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
140export interface CreateOperationResponse extends OperationModel {
141 artifactUUID: string;
Arielk86a37522019-01-13 18:31:13 +0200142}
143
Arielk86a37522019-01-13 18:31:13 +0200144export 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 {
Arielk3d5b80b2019-05-13 15:30:27 +0300158 return displayType(this.type);
Arielk86a37522019-01-13 18:31:13 +0200159 }
Arielk802bd2a2018-04-16 15:37:39 +0300160}
Arielk3d5b80b2019-05-13 15:30:27 +0300161
ys969316a9fce2020-01-19 13:50:02 +0200162const displayType = (type:string) => type && type.substr(type.lastIndexOf('.') + 1);