summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/models
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-07-18 17:25:41 +0100
committerMichael Morris <michael.morris@est.tech>2022-07-29 20:08:14 +0000
commit3f9669fdae5f7c6cb1bfe34742df35dfe3a14aa7 (patch)
tree307686e72403ee837fd342efb9865b0b6a83da7c /catalog-ui/src/app/models
parent22d13840722a4020b1aaf75eeff3622e83c4b6d4 (diff)
Support a custom yaml value in tosca function
Allows to add a custom YAML value to properties in the TOSCA function feature. Change-Id: I15e65088a18537d9832428717be826ac0ef6049a Issue-ID: SDC-4099 Signed-off-by: André Schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-ui/src/app/models')
-rw-r--r--catalog-ui/src/app/models/properties-inputs/input-fe-model.ts2
-rw-r--r--catalog-ui/src/app/models/properties-inputs/property-be-model.ts4
-rw-r--r--catalog-ui/src/app/models/properties-inputs/property-fe-model.ts30
-rw-r--r--catalog-ui/src/app/models/yaml-function.ts37
4 files changed, 57 insertions, 16 deletions
diff --git a/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts b/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts
index 347b8a1665..bcdc95c18e 100644
--- a/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts
+++ b/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts
@@ -83,7 +83,7 @@ export class InputFEModel extends InputBEModel {
}
public getDefaultValueObj(): any {
- return PropertyFEModel.parseValueObj(this.defaultValue, this.type, this.derivedDataType);
+ return PropertyFEModel.parseValueObj(this.defaultValue, this.type, this.derivedDataType, this.isToscaFunction());
}
public resetDefaultValueObjValidation() {
diff --git a/catalog-ui/src/app/models/properties-inputs/property-be-model.ts b/catalog-ui/src/app/models/properties-inputs/property-be-model.ts
index ae7141353b..9429036f6e 100644
--- a/catalog-ui/src/app/models/properties-inputs/property-be-model.ts
+++ b/catalog-ui/src/app/models/properties-inputs/property-be-model.ts
@@ -189,9 +189,9 @@ export class PropertyBEModel {
}
/**
- * Checks whether the property value is a tosca get function (e.g. get_input, get_property, get_attribute)
+ * Checks whether the property value is a TOSCA function (e.g. get_input, get_property, get_attribute, concat, etc.)
*/
- public isToscaGetFunction(): boolean {
+ public isToscaFunction(): boolean {
return this.toscaFunction != null;
}
}
diff --git a/catalog-ui/src/app/models/properties-inputs/property-fe-model.ts b/catalog-ui/src/app/models/properties-inputs/property-fe-model.ts
index f231ec8aa8..eb18c4e4f9 100644
--- a/catalog-ui/src/app/models/properties-inputs/property-fe-model.ts
+++ b/catalog-ui/src/app/models/properties-inputs/property-fe-model.ts
@@ -21,9 +21,9 @@
*/
import * as _ from "lodash";
-import {SchemaPropertyGroupModel, SchemaProperty} from '../schema-property';
-import { PROPERTY_DATA, PROPERTY_TYPES } from 'app/utils';
-import { FilterPropertiesAssignmentData, PropertyBEModel, DerivedPropertyType, DerivedFEPropertyMap, DerivedFEProperty } from 'app/models';
+import {PROPERTY_DATA, PROPERTY_TYPES} from 'app/utils';
+import {DerivedFEProperty, DerivedPropertyType, PropertyBEModel} from 'app/models';
+import * as jsYaml from 'js-yaml';
export class PropertyFEModel extends PropertyBEModel {
@@ -96,7 +96,7 @@ export class PropertyFEModel extends PropertyBEModel {
}
public getValueObj = (): any => {
- return PropertyFEModel.parseValueObj(this.value, this.type, this.derivedDataType, this.defaultValue);
+ return PropertyFEModel.parseValueObj(this.value, this.type, this.derivedDataType, this.isToscaFunction(), this.defaultValue);
}
public setNonDeclared = (childPath?: string): void => {
@@ -278,23 +278,27 @@ export class PropertyFEModel extends PropertyBEModel {
return valueObj.trim();
}
- static parseValueObj(value: string, propertyType: PROPERTY_TYPES, propertyDerivedType: DerivedPropertyType, defaultValue?: string): any {
- let valueObj;
+ static parseValueObj(value: string, propertyType: PROPERTY_TYPES, propertyDerivedType: DerivedPropertyType, isToscaFunction: boolean,
+ defaultValue?: string): any {
+ if (isToscaFunction) {
+ return jsYaml.load(value);
+ }
if (propertyDerivedType === DerivedPropertyType.SIMPLE) {
- valueObj = value || defaultValue || null; // use null for empty value object
+ const valueObj = value || defaultValue || null; // use null for empty value object
if (valueObj &&
propertyType !== PROPERTY_TYPES.STRING &&
propertyType !== PROPERTY_TYPES.TIMESTAMP &&
propertyType !== PROPERTY_TYPES.JSON &&
PROPERTY_DATA.SCALAR_TYPES.indexOf(<string>propertyType) == -1) {
- valueObj = JSON.parse(value); // the value object contains the real value ans not the value as string
+ return JSON.parse(value); // the value object contains the real value ans not the value as string
}
- } else if (propertyDerivedType == DerivedPropertyType.LIST) {
- valueObj = _.merge([], JSON.parse(defaultValue || '[]'), JSON.parse(value || '[]')); // value object should be merged value and default value. Value takes higher precedence. Set value object to empty obj if undefined.
- } else {
- valueObj = _.merge({}, JSON.parse(defaultValue || '{}'), JSON.parse(value || '{}')); // value object should be merged value and default value. Value takes higher precedence. Set value object to empty obj if undefined.
+ return valueObj;
}
- return valueObj;
+ if (propertyDerivedType == DerivedPropertyType.LIST) {
+ return _.merge([], JSON.parse(defaultValue || '[]'), JSON.parse(value || '[]')); // value object should be merged value and default value. Value takes higher precedence. Set value object to empty obj if undefined.
+ }
+
+ return _.merge({}, JSON.parse(defaultValue || '{}'), JSON.parse(value || '{}')); // value object should be merged value and default value. Value takes higher precedence. Set value object to empty obj if undefined.
};
static cleanValueObj(valueObj: any, unsetEmpty?: boolean): any {
diff --git a/catalog-ui/src/app/models/yaml-function.ts b/catalog-ui/src/app/models/yaml-function.ts
new file mode 100644
index 0000000000..e80d783424
--- /dev/null
+++ b/catalog-ui/src/app/models/yaml-function.ts
@@ -0,0 +1,37 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+import {ToscaFunction} from "./tosca-function";
+import {ToscaFunctionType} from "./tosca-function-type.enum";
+import {ToscaFunctionParameter} from "./tosca-function-parameter";
+
+export class YamlFunction implements ToscaFunction, ToscaFunctionParameter {
+ type = ToscaFunctionType.YAML;
+ value: any;
+
+ constructor(yamlFunction?: YamlFunction) {
+ if (!yamlFunction) {
+ return;
+ }
+ this.value = yamlFunction.value;
+ }
+
+} \ No newline at end of file