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";
26 import {SubPropertyToscaFunction} from "./sub-property-tosca-function";
28 export class InputOperationParameter {
31 schema: SchemaPropertyGroupModel;
33 toscaDefaultValue?: string;
35 toscaFunction?: ToscaFunction;
36 subPropertyToscaFunctions: SubPropertyToscaFunction[];
39 constructor(param?: any) {
41 this.name = param.name;
42 this.type = param.type;
43 this.schema = param.schema;
44 this.inputId = param.inputId;
45 this.toscaDefaultValue = param.toscaDefaultValue;
46 this.value = param.value;
47 this.toscaFunction = param.toscaFunction;
48 this.valid = param.valid;
49 this.subPropertyToscaFunctions = param.subPropertyToscaFunctions;
53 public getDefaultValue(): any {
54 if (this.isTypeNotSimple()) {
55 if (this.toscaDefaultValue) {
56 this.toscaDefaultValue = JSON.parse(this.toscaDefaultValue);
57 return JSON.parse(this.toscaDefaultValue);
60 case PROPERTY_TYPES.LIST:
67 return this.toscaDefaultValue;
70 private isTypeNotSimple() {
71 return PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) == -1;
74 public isToscaFunction(): boolean {
75 return this.toscaFunction != null;
79 export class PropertyOperationParameter {
85 constructor(param?: any) {
87 this.name = param.name;
88 this.type = param.type;
89 this.value = param.value;
90 this.propertyId = param.propertyId;
95 export interface IOperationParamsList {
96 listToscaDataDefinition: Array<InputOperationParameter>;
99 export class BEInterfaceOperationModel {
103 inputs: IOperationParamsList;
104 implementation: ArtifactModel;
106 constructor(operation?: any) {
108 this.name = operation.name;
109 this.description = operation.description;
110 this.uniqueId = operation.uniqueId;
111 this.inputs = operation.inputs;
112 this.implementation = operation.implementation;
117 export class InterfaceOperationModel extends BEInterfaceOperationModel {
118 isCollapsed: boolean = true;
122 interfaceType: string;
124 operationType: string;
127 inputParams: IOperationParamsList;
128 implementation: ArtifactModel;
130 constructor(operation?: any) {
133 this.interfaceId = operation.interfaceId;
134 this.interfaceType = operation.interfaceType;
135 this.description = operation.description;
136 this.operationType = operation.operationType;
137 this.uniqueId = operation.uniqueId;
138 if (operation.inputParams && operation.inputParams.listToscaDataDefinition) {
139 const listToscaDataDefinition: InputOperationParameter[] = [];
140 operation.inputParams.listToscaDataDefinition.forEach(inputOperation => {
141 listToscaDataDefinition.push(new InputOperationParameter(inputOperation));
143 this.inputParams = <IOperationParamsList> {
144 'listToscaDataDefinition': listToscaDataDefinition
147 if (operation.implementation) {
148 this.implementation = new ArtifactModel(operation.implementation);
153 public displayType(): string {
154 return displayType(this.interfaceType);
157 getDescriptionEllipsis(): string {
158 if (this.isCollapsed && this.description.length > this.MAX_LENGTH) {
159 return this.description.substr(0, this.MAX_LENGTH - 3) + '...';
161 return this.description;
166 this.isCollapsed = !this.isCollapsed;
171 export class ComponentInterfaceDefinitionModel {
174 operations: Array<InterfaceOperationModel>;
176 constructor(interfaceOperation?: any) {
177 if (interfaceOperation) {
178 this.type = interfaceOperation.type;
179 this.uniqueId = interfaceOperation.uniqueId;
180 this.operations = interfaceOperation.operations;
184 public displayType(): string {
185 return displayType(this.type);
189 const displayType = (type:string) => type && type.substr(type.lastIndexOf('.') + 1);