From 92b18f188105d5ba4b2c469cdfaedc7d2953d593 Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Wed, 10 Aug 2022 14:50:08 +0100 Subject: Support TOSCA functions in Node Filters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds support to use tosca functions as value in the node property filters and substitution filters Change-Id: Id242691cc9ddd233245b58f052b9f0e2c7bbd66b Issue-ID: SDC-4128 Signed-off-by: André Schmid --- .../src/app/utils/filter-constraint-helper.ts | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 catalog-ui/src/app/utils/filter-constraint-helper.ts (limited to 'catalog-ui/src/app/utils') diff --git a/catalog-ui/src/app/utils/filter-constraint-helper.ts b/catalog-ui/src/app/utils/filter-constraint-helper.ts new file mode 100644 index 0000000000..bdb3f9ec7a --- /dev/null +++ b/catalog-ui/src/app/utils/filter-constraint-helper.ts @@ -0,0 +1,64 @@ +import {FilterConstraint} from "../models/filter-constraint"; +import {ToscaFunctionType} from "../models/tosca-function-type.enum"; +import {ToscaConcatFunction} from "../models/tosca-concat-function"; +import {ToscaGetFunction} from "../models/tosca-get-function"; +import {YamlFunction} from "../models/yaml-function"; +import {CapabilityFilterConstraint} from "../models/capability-filter-constraint"; + +export class FilterConstraintHelper { + + public static buildFilterConstraintLabel(constraint: FilterConstraint | CapabilityFilterConstraint): string { + let value; + if (this.isValueToscaFunction(constraint.value)) { + switch (constraint.value.type) { + case ToscaFunctionType.CONCAT: + value = new ToscaConcatFunction(constraint.value).buildValueString(); + break; + case ToscaFunctionType.GET_PROPERTY: + case ToscaFunctionType.GET_INPUT: + case ToscaFunctionType.GET_ATTRIBUTE: + value = new ToscaGetFunction(constraint.value).buildValueString(); + break; + case ToscaFunctionType.YAML: + value = new YamlFunction(constraint.value).buildValueString(); + break; + case ToscaFunctionType.STRING: + value = constraint.value.value; + break; + default: + value = JSON.stringify(constraint.value, null, 4); + } + } else { + value = JSON.stringify(constraint.value, null, 4); + } + if (constraint instanceof CapabilityFilterConstraint) { + return `${constraint.capabilityName}: ${constraint.servicePropertyName} ${this.convertToSymbol(constraint.constraintOperator)} ${value}`; + } + + return `${constraint.servicePropertyName} ${this.convertToSymbol(constraint.constraintOperator)} ${value}`; + } + + public static convertToSymbol(constraintOperator: string) { + switch (constraintOperator) { + case OPERATOR_TYPES.LESS_THAN: return '<'; + case OPERATOR_TYPES.EQUAL: return '='; + case OPERATOR_TYPES.GREATER_THAN: return '>'; + case OPERATOR_TYPES.GREATER_OR_EQUAL: return '>='; + case OPERATOR_TYPES.LESS_OR_EQUAL: return '<='; + } + } + + private static isValueToscaFunction(value: any): boolean { + return value instanceof Object && 'type' in value && (Object).values(ToscaFunctionType).includes(value.type); + } + +} + +export const OPERATOR_TYPES = { + EQUAL: 'equal', + GREATER_THAN: 'greater_than', + LESS_THAN: 'less_than', + GREATER_OR_EQUAL: 'greater_or_equal', + LESS_OR_EQUAL: 'less_or_equal' +}; + -- cgit 1.2.3-korg