fix artifact delivery id implementation
[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
9     constructor(param?: OperationParameter) {
10         if (param) {
11             this.name = param.name;
12             this.type = param.type;
13             this.inputId = param.inputId;
14             this.required = param.required;
15         }
16     }
17 }
18
19 export interface IOperationParamsList {
20     listToscaDataDefinition: Array<OperationParameter>;
21 }
22
23 export class WORKFLOW_ASSOCIATION_OPTIONS {
24     static NONE = 'NONE';
25     static NEW = 'NEW';
26     static EXISTING = 'EXISTING';
27 }
28
29 export class BEOperationModel {
30     name: string;
31     description: string;
32     uniqueId: string;
33
34     inputs: IOperationParamsList;
35     outputs: IOperationParamsList;
36
37     workflowAssociationType: string;
38     workflowId: string;
39     workflowVersionId: string;
40
41     implementation?: { artifactUUID: string; };
42
43     constructor(operation?: any) {
44         if (operation) {
45             this.name = operation.name;
46             this.description = operation.description;
47             this.uniqueId = operation.uniqueId;
48
49             this.inputs = operation.inputs;
50             this.outputs = operation.outputs;
51
52             this.workflowAssociationType = operation.workflowAssociationType;
53             this.workflowId = operation.workflowId;
54             this.workflowVersionId = operation.workflowVersionId;
55             this.implementation = operation.implementation;
56         }
57     }
58
59     public createInputsList(inputs: Array<OperationParameter>): void {
60         this.inputs = {
61             listToscaDataDefinition: inputs
62         };
63     }
64
65     public createOutputsList(outputs: Array<OperationParameter>): void {
66         this.outputs = {
67             listToscaDataDefinition: _.map(outputs, output => {
68                 delete output.inputId;
69                 return output;
70             })
71         };
72     }
73 }
74
75 export class OperationModel extends BEOperationModel {
76     interfaceType: string;
77     interfaceId: string;
78
79     constructor(operation?: any) {
80         super(operation);
81         if (operation) {
82             this.interfaceId = operation.interfaceId;
83             this.interfaceType = operation.interfaceType;
84         }
85     }
86
87     public displayType(): string {
88         const lastDot = this.interfaceType ? this.interfaceType.lastIndexOf('.') : -1;
89         return lastDot === -1 ? this.interfaceType : this.interfaceType.substr(lastDot + 1);
90     }
91 }
92
93 export class InterfaceModel {
94     type: string;
95     uniqueId: string;
96     operations: Array<OperationModel>;
97
98     constructor(interf?: any) {
99         if (interf) {
100             this.type = interf.type;
101             this.uniqueId = interf.uniqueId;
102             this.operations = interf.operations;
103         }
104     }
105
106     public displayType(): string {
107         const lastDot = this.type ? this.type.lastIndexOf('.') : -1;
108         return lastDot === -1 ? this.type : this.type.substr(lastDot + 1);
109     }
110 }