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
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.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
22 import {ArtifactModel} from "./artifacts";
23 import {SchemaPropertyGroupModel} from "./schema-property";
24 import {PROPERTY_DATA, PROPERTY_TYPES} from "../utils/constants";
25 import {ToscaFunction} from "./tosca-function";
27 export class InputOperationParameter {
30 schema: SchemaPropertyGroupModel;
32 toscaDefaultValue?: string;
34 toscaFunction?: ToscaFunction;
36 subPropertyToscaFunctions: any;
38 constructor(param?: any) {
40 this.name = param.name;
41 this.type = param.type;
42 this.schema = param.schema;
43 this.inputId = param.inputId;
44 this.toscaDefaultValue = param.toscaDefaultValue;
45 this.value = param.value;
46 this.toscaFunction = param.toscaFunction;
47 this.valid = param.valid;
48 this.subPropertyToscaFunctions = param.subPropertyToscaFunctions;
52 public getDefaultValue(): any {
53 if (this.isTypeNotSimple()) {
54 if (this.toscaDefaultValue) {
55 this.toscaDefaultValue = JSON.parse(this.toscaDefaultValue);
56 return JSON.parse(this.toscaDefaultValue);
59 case PROPERTY_TYPES.LIST:
66 return this.toscaDefaultValue;
69 private isTypeNotSimple() {
70 return PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) == -1;
73 public isToscaFunction(): boolean {
74 return this.toscaFunction != null;
78 export class PropertyOperationParameter {
84 constructor(param?: any) {
86 this.name = param.name;
87 this.type = param.type;
88 this.value = param.value;
89 this.propertyId = param.propertyId;
94 export interface IOperationParamsList {
95 listToscaDataDefinition: Array<InputOperationParameter>;
98 export class BEInterfaceOperationModel {
102 inputs: IOperationParamsList;
103 implementation: ArtifactModel;
105 constructor(operation?: any) {
107 this.name = operation.name;
108 this.description = operation.description;
109 this.uniqueId = operation.uniqueId;
110 this.inputs = operation.inputs;
111 this.implementation = operation.implementation;
116 export class InterfaceOperationModel extends BEInterfaceOperationModel {
117 isCollapsed: boolean = true;
121 interfaceType: string;
123 operationType: string;
126 inputParams: IOperationParamsList;
127 implementation: ArtifactModel;
129 constructor(operation?: any) {
132 this.interfaceId = operation.interfaceId;
133 this.interfaceType = operation.interfaceType;
134 this.description = operation.description;
135 this.operationType = operation.operationType;
136 this.uniqueId = operation.uniqueId;
137 if (operation.inputParams && operation.inputParams.listToscaDataDefinition) {
138 const listToscaDataDefinition: InputOperationParameter[] = [];
139 operation.inputParams.listToscaDataDefinition.forEach(inputOperation => {
140 listToscaDataDefinition.push(new InputOperationParameter(inputOperation));
142 this.inputParams = <IOperationParamsList> {
143 'listToscaDataDefinition': listToscaDataDefinition
146 if (operation.implementation) {
147 this.implementation = new ArtifactModel(operation.implementation);
152 public displayType(): string {
153 return displayType(this.interfaceType);
156 getDescriptionEllipsis(): string {
157 if (this.isCollapsed && this.description.length > this.MAX_LENGTH) {
158 return this.description.substr(0, this.MAX_LENGTH - 3) + '...';
160 return this.description;
165 this.isCollapsed = !this.isCollapsed;
170 export class ComponentInterfaceDefinitionModel {
173 operations: Array<InterfaceOperationModel>;
175 constructor(interfaceOperation?: any) {
176 if (interfaceOperation) {
177 this.type = interfaceOperation.type;
178 this.uniqueId = interfaceOperation.uniqueId;
179 this.operations = interfaceOperation.operations;
183 public displayType(): string {
184 return displayType(this.type);
188 const displayType = (type:string) => type && type.substr(type.lastIndexOf('.') + 1);