3 * ============LICENSE_START=======================================================
4 * Copyright (C) 2022 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 import {ToscaFunctionType} from "../models/tosca-function-type.enum";
23 import {ToscaConcatFunction} from "../models/tosca-concat-function";
24 import {ToscaGetFunction} from "../models/tosca-get-function";
25 import {YamlFunction} from "../models/yaml-function";
26 import {ToscaFunction} from "../models/tosca-function";
27 import {ToscaCustomFunction} from "../models/tosca-custom-function";
29 export class ToscaFunctionHelper {
31 public static convertObjectToToscaFunction(value: any): ToscaFunction {
32 if (!value || !this.isValueToscaFunction(value)) {
37 case ToscaFunctionType.CONCAT:
38 return new ToscaConcatFunction(value);
39 case ToscaFunctionType.GET_PROPERTY:
40 case ToscaFunctionType.GET_INPUT:
41 case ToscaFunctionType.GET_ATTRIBUTE:
42 return new ToscaGetFunction(value);
43 case ToscaFunctionType.YAML:
44 return new YamlFunction(value);
45 case ToscaFunctionType.CUSTOM:
46 return new ToscaCustomFunction(value);
47 case ToscaFunctionType.STRING:
48 return <ToscaFunction> {
49 type: ToscaFunctionType.STRING,
51 buildValueString(): string {
54 buildValueObject(): Object {
63 public static isValueToscaFunction(value: any): boolean {
64 return value instanceof Object && 'type' in value && (<any>Object).values(ToscaFunctionType).includes(value.type);