summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/utils
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-08-10 14:50:08 +0100
committerVasyl Razinkov <vasyl.razinkov@est.tech>2022-09-08 18:24:44 +0000
commit92b18f188105d5ba4b2c469cdfaedc7d2953d593 (patch)
treedf7c7562faa99a76b0e6b5bc079de8d514b35006 /catalog-ui/src/app/utils
parentc0c2637f201f488a74cb1916f05eece0cc207e9d (diff)
Support TOSCA functions in Node Filters
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 <andre.schmid@est.tech>
Diffstat (limited to 'catalog-ui/src/app/utils')
-rw-r--r--catalog-ui/src/app/utils/filter-constraint-helper.ts64
1 files changed, 64 insertions, 0 deletions
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 && (<any>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'
+};
+