+ private List<Map<String, ToscaPropertyConstraint>> getToscaFilters(ListDataDefinition<FilterDataDefinition> filters) {
+ if (filters != null && !filters.isEmpty()) {
+ List<Map<String, ToscaPropertyConstraint>> toscaFilters = new ArrayList<>();
+ for (FilterDataDefinition filter : filters.getListToscaDataDefinition()) {
+ Optional<ConstraintType> typeOptional = ConstraintType.findByType(filter.getConstraint());
+ if (typeOptional.isEmpty()) {
+ continue;
+ }
+ ConstraintType type = typeOptional.get();
+ Object value = filter.isToscaFunction() ? filter.getToscaFunction().getJsonObjectValue() : filter.getFilterValue();
+ if (ConstraintType.EQUAL.equals(type)) {
+ EqualConstraint equalConstraint = new EqualConstraint(value);
+ ToscaPropertyConstraint prop = new ToscaPropertyConstraintEqual(equalConstraint.getEqual());
+ toscaFilters.add(Map.of(filter.getName(), prop));
+ }
+ if (ConstraintType.GREATER_THAN.equals(type)) {
+ GreaterThanConstraint greaterThanConstraint = new GreaterThanConstraint(value);
+ ToscaPropertyConstraintGreaterThan prop = new ToscaPropertyConstraintGreaterThan(greaterThanConstraint.getGreaterThan());
+ toscaFilters.add(Map.of(filter.getName(), prop));
+ }
+ if (ConstraintType.GREATER_OR_EQUAL.equals(type)) {
+ GreaterOrEqualConstraint greaterOrEqualConstraint = new GreaterOrEqualConstraint<>(value);
+ ToscaPropertyConstraintGreaterOrEqual prop =
+ new ToscaPropertyConstraintGreaterOrEqual(greaterOrEqualConstraint.getGreaterOrEqual());
+ toscaFilters.add(Map.of(filter.getName(), prop));
+ }
+ if (ConstraintType.LESS_THAN.equals(type)) {
+ LessThanConstraint lessThanConstraint = new LessThanConstraint(value);
+ ToscaPropertyConstraintLessThan prop = new ToscaPropertyConstraintLessThan(lessThanConstraint.getLessThan());
+ toscaFilters.add(Map.of(filter.getName(), prop));
+ }
+ if (ConstraintType.LESS_OR_EQUAL.equals(type)) {
+ LessOrEqualConstraint lessOrEqualConstraint = new LessOrEqualConstraint<>(value);
+ ToscaPropertyConstraintLessOrEqual prop = new ToscaPropertyConstraintLessOrEqual(lessOrEqualConstraint.getLessOrEqual());
+ toscaFilters.add(Map.of(filter.getName(), prop));
+ }
+ if (ConstraintType.IN_RANGE.equals(type)) {
+ InRangeConstraint inRangeConstraint = new InRangeConstraint((List<Object>) value);
+ toscaFilters.add(Map.of(filter.getName(), new ToscaPropertyConstraintInRange(inRangeConstraint.getInRange())));
+ }
+ if (ConstraintType.VALID_VALUES.equals(type)) {
+ ValidValuesConstraint validValues = new ValidValuesConstraint((List<Object>) value);
+ List prop = validValues.getValidValues();
+ toscaFilters.add(Map.of(filter.getName(), (new ToscaPropertyConstraintValidValues(prop))));
+ }
+ if (ConstraintType.LENGTH.equals(type)) {
+ LengthConstraint lengthConstraint = new LengthConstraint((Integer) value);
+ toscaFilters.add(Map.of(filter.getName(), (new ToscaPropertyConstraintLength(lengthConstraint.getLength()))));
+ }
+ if (ConstraintType.MIN_LENGTH.equals(type)) {
+ MinLengthConstraint minLengthConstraint = new MinLengthConstraint((Integer) value);
+ toscaFilters.add(Map.of(filter.getName(), new ToscaPropertyConstraintMinLength(minLengthConstraint.getMinLength())));
+ }
+ if (ConstraintType.MAX_LENGTH.equals(type)) {
+ MaxLengthConstraint maxLengthConstraint = new MaxLengthConstraint((Integer) value);
+ toscaFilters.add(Map.of(filter.getName(), new ToscaPropertyConstraintMaxLength(maxLengthConstraint.getMaxLength())));
+ }
+ }
+ return toscaFilters;
+ }
+ return null;
+ }
+