5c6968874545548b951e5c6e31b725021a1de529
[sdc.git] / catalog-ui / src / app / models / interfaceOperation.ts
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 'use strict';
21
22 export class InputOperationParameter {
23     name: string;
24     type: string;
25     inputId: string;
26     toscaDefaultValue?: string;
27
28     constructor(param?: any) {
29         if (param) {
30             this.name = param.name;
31             this.type = param.type;
32             this.inputId = param.inputId;
33             this.toscaDefaultValue = param.toscaDefaultValue;
34         }
35         console.info("InputOperationParameter Constructor: ", param)
36     }
37 }
38
39 export interface IOperationParamsList {
40     listToscaDataDefinition: Array<InputOperationParameter>;
41 }
42
43 export class BEInterfaceOperationModel {
44     name: string;
45     description: string;
46     uniqueId: string;
47     inputs: IOperationParamsList;
48     implementation?: InterfaceOperationImplementation;
49
50     constructor(operation?: any) {
51         if (operation) {
52             this.name = operation.name;
53             this.description = operation.description;
54             this.uniqueId = operation.uniqueId;
55             this.inputs = operation.inputs;
56             this.implementation = operation.implementation;
57         }
58     }
59 }
60
61 export class InterfaceOperationModel extends BEInterfaceOperationModel {
62     interfaceType: string;
63     interfaceId: string;
64     operationType: string;
65     description: string;
66     uniqueId: string;
67     implementation?: InterfaceOperationImplementation;
68     inputParams: IOperationParamsList;
69
70     constructor(operation?: any) {
71         super(operation);
72         if (operation) {
73             this.interfaceId = operation.interfaceId;
74             this.interfaceType = operation.interfaceType;
75             this.description = operation.description;
76             this.operationType = operation.operationType;
77             this.uniqueId = operation.uniqueId;
78             this.inputParams = operation.inputParams;
79         }
80     }
81
82     public displayType(): string {
83         return displayType(this.interfaceType);
84     }
85 }
86
87 export class InterfaceOperationImplementation {
88     artifactName: string;
89 }
90
91 export class ComponentInstanceInterfaceModel {
92     type: string;
93     uniqueId: string;
94     operations: Array<InterfaceOperationModel>;
95
96     constructor(interfaceOperation?: any) {
97         if (interfaceOperation) {
98             this.type = interfaceOperation.type;
99             this.uniqueId = interfaceOperation.uniqueId;
100             this.operations = interfaceOperation.operations;
101         }
102     }
103
104     public displayType(): string {
105         return displayType(this.type);
106     }
107 }
108
109 const displayType = (type:string) => type && type.substr(type.lastIndexOf('.') + 1);