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 enum MilestoneEnum {
29 on_entry = 'on_entry',
30 on_success = 'on_success',
31 on_failure = 'on_failure',
32 on_timeout = 'on_timeout'
35 export enum ActivityTypesEnum {
39 export class InputOperationParameter {
42 schema: SchemaPropertyGroupModel;
44 toscaDefaultValue?: string;
46 toscaFunction?: ToscaFunction;
47 subPropertyToscaFunctions: SubPropertyToscaFunction[];
50 constructor(param?: any) {
52 this.name = param.name;
53 this.type = param.type;
54 this.schema = param.schema;
55 this.inputId = param.inputId;
56 this.toscaDefaultValue = param.toscaDefaultValue;
57 this.value = param.value;
58 this.toscaFunction = param.toscaFunction;
59 this.valid = param.valid;
60 this.subPropertyToscaFunctions = param.subPropertyToscaFunctions;
64 public getDefaultValue(): any {
65 if (this.isTypeNotSimple()) {
66 if (this.toscaDefaultValue) {
67 this.toscaDefaultValue = JSON.parse(this.toscaDefaultValue);
68 return JSON.parse(this.toscaDefaultValue);
71 case PROPERTY_TYPES.LIST:
78 return this.toscaDefaultValue;
81 private isTypeNotSimple() {
82 return PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) == -1;
85 public isToscaFunction(): boolean {
86 return this.toscaFunction != null;
90 export class PropertyOperationParameter {
96 constructor(param?: any) {
98 this.name = param.name;
99 this.type = param.type;
100 this.value = param.value;
101 this.propertyId = param.propertyId;
106 export interface IOperationParamsList {
107 listToscaDataDefinition: Array<InputOperationParameter>;
110 export class Milestone {
111 activities: IActivityParameterList;
112 filterParams: IActivityParameterList;
114 constructor(param?: any) {
116 this.activities = param.activityParams;
117 this.filterParams = param.filterParams;
122 export class ActivityParameter {
125 inputs: IOperationParamsList;
127 constructor(param?: any) {
129 this.type = param.type;
130 this.workflow = param.workflow;
131 this.inputs = param.inputs;
136 export interface IActivityParameterList {
137 listToscaDataDefinition: Array<ActivityParameter>;
140 export class FilterParameter {
144 toscaFunction?: ToscaFunction;
146 constructor(param?: any) {
148 this.name = param.name;
149 this.constraint = param.constraint;
150 this.filterValue = param.filterValue;
151 this.toscaFunction = param.toscaFunction;
156 export interface IFilterParameterList {
157 listToscaDataDefinition: Array<FilterParameter>;
160 export class BEInterfaceOperationModel {
164 inputs: IOperationParamsList;
165 implementation: ArtifactModel;
168 constructor(operation?: any) {
170 this.name = operation.name;
171 this.description = operation.description;
172 this.uniqueId = operation.uniqueId;
173 this.inputs = operation.inputs;
174 this.implementation = operation.implementation;
175 this.milestones = operation.milestones;
180 export class InterfaceOperationModel extends BEInterfaceOperationModel {
181 isCollapsed: boolean = true;
185 interfaceType: string;
187 operationType: string;
190 inputParams: IOperationParamsList;
191 implementation: ArtifactModel;
194 constructor(operation?: any) {
197 this.interfaceId = operation.interfaceId;
198 this.interfaceType = operation.interfaceType;
199 this.description = operation.description;
200 this.operationType = operation.operationType;
201 this.uniqueId = operation.uniqueId;
202 if (operation.inputParams && operation.inputParams.listToscaDataDefinition) {
203 const listToscaDataDefinition: InputOperationParameter[] = [];
204 operation.inputParams.listToscaDataDefinition.forEach(inputOperation => {
205 listToscaDataDefinition.push(new InputOperationParameter(inputOperation));
207 this.inputParams = <IOperationParamsList> {
208 'listToscaDataDefinition': listToscaDataDefinition
211 if (operation.implementation) {
212 this.implementation = new ArtifactModel(operation.implementation);
214 this.milestones = operation.milestones;
218 public displayType(): string {
219 return displayType(this.interfaceType);
222 getDescriptionEllipsis(): string {
223 if (this.isCollapsed && this.description.length > this.MAX_LENGTH) {
224 return this.description.substr(0, this.MAX_LENGTH - 3) + '...';
226 return this.description;
231 this.isCollapsed = !this.isCollapsed;
236 export class ComponentInterfaceDefinitionModel {
239 operations: Array<InterfaceOperationModel>;
241 constructor(interfaceOperation?: any) {
242 if (interfaceOperation) {
243 this.type = interfaceOperation.type;
244 this.uniqueId = interfaceOperation.uniqueId;
245 this.operations = interfaceOperation.operations;
249 public displayType(): string {
250 return displayType(this.type);
254 const displayType = (type:string) => type && type.substr(type.lastIndexOf('.') + 1);