1 import {FilterConstraint} from "../models/filter-constraint";
2 import {ToscaFunctionType} from "../models/tosca-function-type.enum";
3 import {ToscaConcatFunction} from "../models/tosca-concat-function";
4 import {ToscaGetFunction} from "../models/tosca-get-function";
5 import {YamlFunction} from "../models/yaml-function";
6 import {CapabilityFilterConstraint} from "../models/capability-filter-constraint";
8 export class FilterConstraintHelper {
10 public static buildFilterConstraintLabel(constraint: FilterConstraint | CapabilityFilterConstraint): string {
12 if (this.isValueToscaFunction(constraint.value)) {
13 switch (constraint.value.type) {
14 case ToscaFunctionType.CONCAT:
15 value = new ToscaConcatFunction(constraint.value).buildValueString();
17 case ToscaFunctionType.GET_PROPERTY:
18 case ToscaFunctionType.GET_INPUT:
19 case ToscaFunctionType.GET_ATTRIBUTE:
20 value = new ToscaGetFunction(constraint.value).buildValueString();
22 case ToscaFunctionType.YAML:
23 value = new YamlFunction(constraint.value).buildValueString();
25 case ToscaFunctionType.STRING:
26 value = constraint.value.value;
29 value = JSON.stringify(constraint.value, null, 4);
32 value = JSON.stringify(constraint.value, null, 4);
34 if (constraint instanceof CapabilityFilterConstraint) {
35 return `${constraint.capabilityName}: ${constraint.servicePropertyName} ${this.convertToSymbol(constraint.constraintOperator)} ${value}`;
38 return `${constraint.servicePropertyName} ${this.convertToSymbol(constraint.constraintOperator)} ${value}`;
41 public static convertToSymbol(constraintOperator: string) {
42 switch (constraintOperator) {
43 case OPERATOR_TYPES.LESS_THAN: return '<';
44 case OPERATOR_TYPES.EQUAL: return '=';
45 case OPERATOR_TYPES.GREATER_THAN: return '>';
46 case OPERATOR_TYPES.GREATER_OR_EQUAL: return '>=';
47 case OPERATOR_TYPES.LESS_OR_EQUAL: return '<=';
51 private static isValueToscaFunction(value: any): boolean {
52 return value instanceof Object && 'type' in value && (<any>Object).values(ToscaFunctionType).includes(value.type);
57 export const OPERATOR_TYPES = {
59 GREATER_THAN: 'greater_than',
60 LESS_THAN: 'less_than',
61 GREATER_OR_EQUAL: 'greater_or_equal',
62 LESS_OR_EQUAL: 'less_or_equal'