diff options
author | JvD_Ericsson <jeff.van.dam@est.tech> | 2023-08-01 09:28:12 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2023-09-22 07:43:25 +0000 |
commit | 035d670c792c9408493b3d729a3ac91124c2d4df (patch) | |
tree | 0437db7e9b647546799236c39b026d538e5e1c60 /catalog-be/src | |
parent | 27633293d6d45521ea985019ea7b99c2009b62c7 (diff) |
Backend support for operation milestone filters
Issue-ID: SDC-4590
Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
Change-Id: If291bd79871eee590c8826800127f543a6ba4b0c
Diffstat (limited to 'catalog-be/src')
16 files changed, 271 insertions, 0 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java index c8d7862306..46ec9aa244 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java @@ -20,9 +20,11 @@ package org.openecomp.sdc.be.components.impl; import static org.openecomp.sdc.be.components.impl.ImportUtils.Constants.QUOTE; +import static org.openecomp.sdc.be.utils.PropertyFilterConstraintDataDefinitionHelper.createToscaFunctionFromLegacyConstraintValue; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ACTIVITIES; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DEFAULT; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DESCRIPTION; +import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.FILTERS; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.IMPLEMENTATION; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.INPUTS; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.MILESTONES; @@ -53,6 +55,7 @@ import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentEx import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.elements.ActivityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.FilterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MilestoneDataDefinition; @@ -60,6 +63,9 @@ import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; +import org.openecomp.sdc.be.datatypes.elements.ToscaFunction; +import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType; +import org.openecomp.sdc.be.datatypes.enums.ConstraintType; import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; @@ -197,12 +203,70 @@ public class InterfaceDefinitionHandler { if (activities.isEmpty()) { throw new ByActionStatusComponentException(ActionStatus.INVALID_OPERATION_MILESTONE, interfaceInput.getKey()); } + ListDataDefinition<FilterDataDefinition> filters = handleMilestoneFilters(interfaceInput.getValue()); + if (!filters.isEmpty()) { + operationMilestone.setFilters(filters); + } operationMilestone.setActivities(activities); milestones.put(interfaceInput.getKey(), operationMilestone); } return milestones; } + private ListDataDefinition<FilterDataDefinition> handleMilestoneFilters(Object milestone) { + ListDataDefinition<FilterDataDefinition> filters = new ListDataDefinition<>(); + if (milestone instanceof Map) { + final LinkedHashMap<String, Object> milestoneValue = (LinkedHashMap<String, Object>) milestone; + if (milestoneValue.containsKey(FILTERS.getElementName())) { + final List<Object> milestoneFilters = (List<Object>) milestoneValue.get(FILTERS.getElementName()); + for (Object filtersValues : milestoneFilters) { + if (filtersValues instanceof Map) { + FilterDataDefinition filter = new FilterDataDefinition(); + Map<String, Object> filterMap = (Map<String, Object>) filtersValues; + + Optional<Entry<String, Object>> filterOptional = + filterMap.entrySet().stream().filter(entrySet -> entrySet.getValue() instanceof Map).findAny(); + if (filterOptional.isEmpty()) { + continue; + } + Entry<String, Object> filterValue = filterOptional.get(); + if (!(filterValue.getValue() instanceof Map)) { + continue; + } + Map<String, Object> valueMap = (Map<String, Object>) filterValue.getValue(); + Optional<String> constraintTypeOptional = + valueMap.keySet().stream().filter(key -> ConstraintType.findByType(key).isPresent()).findAny(); + if (constraintTypeOptional.isEmpty()) { + continue; + } + String constraintType = constraintTypeOptional.get(); + filter.setName(filterValue.getKey()); + filter.setConstraint(constraintType); + Object value = valueMap.get(constraintType); + if (value instanceof Map) { + Map<String, Object> valueAsMap = (Map<String, Object>) value; + Optional<String> toscaFunctionTypeOptional = + valueAsMap.keySet().stream().filter(key -> ToscaFunctionType.findType(key).isPresent()).findAny(); + if (toscaFunctionTypeOptional.isPresent()) { + Optional<ToscaFunction> toscaValue = createToscaFunctionFromLegacyConstraintValue(valueAsMap); + if (toscaValue.isPresent()) { + filter.setToscaFunction(toscaValue.get()); + } + } + } + filter.setFilterValue(value); + filters.add(filter); + } else { + return new ListDataDefinition<>(); + } + } + } else { + return new ListDataDefinition<>(); + } + } + return filters; + } + private ListDataDefinition<ActivityDataDefinition> handleMilestoneActivities(final Object value) { ListDataDefinition<ActivityDataDefinition> activities = new ListDataDefinition<>(); if (value instanceof Map) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java index 52fdfcc4e5..fa5261806c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import org.apache.commons.collections.MapUtils; @@ -41,6 +42,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.openecomp.sdc.be.datatypes.elements.ActivityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.FilterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MilestoneDataDefinition; @@ -48,6 +50,7 @@ import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ActivityTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.ConstraintType; import org.openecomp.sdc.be.datatypes.enums.MilestoneTypeEnum; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstance; @@ -55,6 +58,17 @@ import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Product; import org.openecomp.sdc.be.model.PropertyDefinition; +import org.openecomp.sdc.be.model.tosca.constraints.EqualConstraint; +import org.openecomp.sdc.be.model.tosca.constraints.GreaterOrEqualConstraint; +import org.openecomp.sdc.be.model.tosca.constraints.GreaterThanConstraint; +import org.openecomp.sdc.be.model.tosca.constraints.InRangeConstraint; +import org.openecomp.sdc.be.model.tosca.constraints.LengthConstraint; +import org.openecomp.sdc.be.model.tosca.constraints.LessOrEqualConstraint; +import org.openecomp.sdc.be.model.tosca.constraints.LessThanConstraint; +import org.openecomp.sdc.be.model.tosca.constraints.MaxLengthConstraint; +import org.openecomp.sdc.be.model.tosca.constraints.MinLengthConstraint; +import org.openecomp.sdc.be.model.tosca.constraints.PatternConstraint; +import org.openecomp.sdc.be.model.tosca.constraints.ValidValuesConstraint; import org.openecomp.sdc.be.tosca.PropertyConvertor.PropertyType; import org.openecomp.sdc.be.tosca.model.ToscaActivity; import org.openecomp.sdc.be.tosca.model.ToscaArtifactDefinition; @@ -68,6 +82,18 @@ import org.openecomp.sdc.be.tosca.model.ToscaNodeType; import org.openecomp.sdc.be.tosca.model.ToscaProperty; import org.openecomp.sdc.be.tosca.model.ToscaPropertyAssignment; import org.openecomp.sdc.be.tosca.model.ToscaPropertyAssignmentJsonSerializer; +import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraint; +import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintEqual; +import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintGreaterOrEqual; +import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintGreaterThan; +import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintInRange; +import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintLength; +import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintLessOrEqual; +import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintLessThan; +import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintMaxLength; +import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintMinLength; +import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintPattern; +import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintValidValues; import org.openecomp.sdc.be.tosca.utils.OperationArtifactUtil; import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum; import org.openecomp.sdc.tosca.datatypes.ToscaFunctions; @@ -342,11 +368,75 @@ public class InterfacesOperationsConverter { } ToscaMilestone toscaMilestone = new ToscaMilestone(); toscaMilestone.setActivities(toscaActivities); + toscaMilestone.setFilters(getToscaFilters(milestone.getValue().getFilters())); toscaMilestones.put(milestone.getKey(), toscaMilestone); } toscaOperation.setMilestones(toscaMilestones); } + 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; + } + private Map<String, Object> getToscaActivityInputs(ListDataDefinition<OperationInputDefinition> inputs, Map<String, DataTypeDefinition> dataTypes) { if (Objects.isNull(inputs) || inputs.isEmpty()) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaFilter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaFilter.java new file mode 100644 index 0000000000..3ff29e8df9 --- /dev/null +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaFilter.java @@ -0,0 +1,32 @@ +/* + * + * ============LICENSE_START======================================================= + * Copyright (C) 2023 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========================================================= + */ + +package org.openecomp.sdc.be.tosca.model; + +import lombok.Data; + +@Data +public class ToscaFilter { + + private String name; + private String constraint; + private Object value; //ToscaFunction or String or float, etc I guess +} diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMilestone.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMilestone.java index d04bdd7357..5b737f55a3 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMilestone.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMilestone.java @@ -29,5 +29,6 @@ import lombok.Data; public class ToscaMilestone { private List<Map<String, ToscaActivity>> activities; + private List<Map<String, ToscaPropertyConstraint>> filters; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintEqual.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintEqual.java index e52f8dfa87..75d6855420 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintEqual.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintEqual.java @@ -18,6 +18,7 @@ */ package org.openecomp.sdc.be.tosca.model; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; @@ -43,6 +44,7 @@ public class ToscaPropertyConstraintEqual implements ToscaPropertyConstraint { } @Override + @JsonIgnore public ConstraintType getConstraintType() { return CONSTRAINT_TYPE; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterOrEqual.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterOrEqual.java index 89c563bdbc..a4da4a30f0 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterOrEqual.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterOrEqual.java @@ -18,6 +18,7 @@ */ package org.openecomp.sdc.be.tosca.model; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; @@ -43,6 +44,7 @@ public class ToscaPropertyConstraintGreaterOrEqual implements ToscaPropertyConst } @Override + @JsonIgnore public ConstraintType getConstraintType() { return CONSTRAINT_TYPE; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterThan.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterThan.java index 2168cf4b67..5e3b2248f8 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterThan.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterThan.java @@ -18,6 +18,7 @@ */ package org.openecomp.sdc.be.tosca.model; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; @@ -43,6 +44,7 @@ public class ToscaPropertyConstraintGreaterThan implements ToscaPropertyConstrai } @Override + @JsonIgnore public ConstraintType getConstraintType() { return CONSTRAINT_TYPE; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java index 43cc0e3a55..76d6abadfd 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java @@ -18,6 +18,7 @@ */ package org.openecomp.sdc.be.tosca.model; +import com.fasterxml.jackson.annotation.JsonIgnore; import java.util.LinkedList; import java.util.List; import lombok.AllArgsConstructor; @@ -45,6 +46,7 @@ public class ToscaPropertyConstraintInRange implements ToscaPropertyConstraint { } @Override + @JsonIgnore public ConstraintType getConstraintType() { return CONSTRAINT_TYPE; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLength.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLength.java index 998a7283bb..89a985be8a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLength.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLength.java @@ -18,6 +18,7 @@ */ package org.openecomp.sdc.be.tosca.model; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; @@ -43,6 +44,7 @@ public class ToscaPropertyConstraintLength implements ToscaPropertyConstraint { } @Override + @JsonIgnore public ConstraintType getConstraintType() { return CONSTRAINT_TYPE; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessOrEqual.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessOrEqual.java index 75e661d15c..a2dba2cd90 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessOrEqual.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessOrEqual.java @@ -18,6 +18,7 @@ */ package org.openecomp.sdc.be.tosca.model; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; @@ -43,6 +44,7 @@ public class ToscaPropertyConstraintLessOrEqual implements ToscaPropertyConstrai } @Override + @JsonIgnore public ConstraintType getConstraintType() { return CONSTRAINT_TYPE; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessThan.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessThan.java index a64382d8a8..c9eafe7458 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessThan.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessThan.java @@ -18,6 +18,7 @@ */ package org.openecomp.sdc.be.tosca.model; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; @@ -43,6 +44,7 @@ public class ToscaPropertyConstraintLessThan implements ToscaPropertyConstraint } @Override + @JsonIgnore public ConstraintType getConstraintType() { return CONSTRAINT_TYPE; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintMaxLength.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintMaxLength.java index 29d1464714..66fa5d95b1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintMaxLength.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintMaxLength.java @@ -18,6 +18,7 @@ */ package org.openecomp.sdc.be.tosca.model; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; @@ -43,6 +44,7 @@ public class ToscaPropertyConstraintMaxLength implements ToscaPropertyConstraint } @Override + @JsonIgnore public ConstraintType getConstraintType() { return CONSTRAINT_TYPE; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintMinLength.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintMinLength.java index 3613df9928..91ade64a83 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintMinLength.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintMinLength.java @@ -18,6 +18,7 @@ */ package org.openecomp.sdc.be.tosca.model; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; @@ -42,6 +43,7 @@ public class ToscaPropertyConstraintMinLength implements ToscaPropertyConstraint } @Override + @JsonIgnore public ConstraintType getConstraintType() { return ConstraintType.MIN_LENGTH; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintValidValues.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintValidValues.java index 4f9a65cfc1..5d2cf78bcd 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintValidValues.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintValidValues.java @@ -18,6 +18,7 @@ */ package org.openecomp.sdc.be.tosca.model; +import com.fasterxml.jackson.annotation.JsonIgnore; import java.util.List; import lombok.AllArgsConstructor; import lombok.Getter; @@ -43,6 +44,7 @@ public class ToscaPropertyConstraintValidValues implements ToscaPropertyConstrai } @Override + @JsonIgnore public ConstraintType getConstraintType() { return ConstraintType.VALID_VALUES; } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java index 974d321c62..7e4b4c28e2 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java @@ -44,6 +44,7 @@ import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.DummyConfigurationManager; import org.openecomp.sdc.be.datatypes.elements.ActivityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.FilterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MilestoneDataDefinition; @@ -53,9 +54,13 @@ import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType; +import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ActivityTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.ConstraintType; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; import org.openecomp.sdc.be.datatypes.enums.MilestoneTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.PropertySource; +import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.InputDefinition; @@ -443,6 +448,25 @@ class InterfacesOperationsConverterTest { activities.add(activity); MilestoneDataDefinition milestone = new MilestoneDataDefinition(); milestone.setActivities(activities); + FilterDataDefinition filter1 = new FilterDataDefinition(); + filter1.setName("my_attribute"); + filter1.setConstraint("equal"); + filter1.setFilterValue("my_value"); + FilterDataDefinition filter2 = new FilterDataDefinition(); + ToscaGetFunctionDataDefinition toscaFunction = new ToscaGetFunctionDataDefinition(); + toscaFunction.setFunctionType(ToscaGetFunctionType.GET_ATTRIBUTE); + toscaFunction.setPropertyName("role"); + toscaFunction.setPropertySource(PropertySource.SELF); + toscaFunction.setSourceName("myVfc"); + toscaFunction.setPropertyPathFromSource(Arrays.asList("role")); + filter2.setToscaFunction(toscaFunction); + filter2.setName("my_other_attribute"); + filter2.setConstraint("equal"); + filter2.setFilterValue("{'get_attribute':['SELF','role']}"); + ListDataDefinition<FilterDataDefinition> filters = new ListDataDefinition<>(); + filters.add(filter1); + filters.add(filter2); + milestone.setFilters(filters); toscaMilestones.put(MilestoneTypeEnum.ON_ENTRY.getValue(), milestone); return toscaMilestones; } @@ -672,6 +696,25 @@ class InterfacesOperationsConverterTest { assertTrue(complexInputStringProp.containsKey("propertySource")); assertEquals("SELF", complexInputStringProp.get("propertySource")); + assertTrue(milestone.containsKey("filters")); + List<Map<String, Object>> filters = (List<Map<String, Object>>) milestone.get("filters"); + assertEquals(2, filters.size()); + Map<String, Object> filter1 = filters.get(0); + assertTrue(filter1.containsKey("my_attribute")); + Map<String, Object> filter1Constraint = (Map<String, Object>) filter1.get("my_attribute"); + assertTrue(filter1Constraint.containsKey(ConstraintType.EQUAL.getType())); + String filter1Value = (String) filter1Constraint.get(ConstraintType.EQUAL.getType()); + assertEquals("my_value", filter1Value); + Map<String, Object> filter2 = filters.get(1); + assertTrue(filter2.containsKey("my_other_attribute")); + Map<String, Object> filter2Constraint = (Map<String, Object>) filter2.get("my_other_attribute"); + assertTrue(filter2Constraint.containsKey(ConstraintType.EQUAL.getType())); + Map<String, Object> filter2Value = (Map<String, Object>) filter2Constraint.get(ConstraintType.EQUAL.getType()); + assertTrue(filter2Value.containsKey(ToscaGetFunctionType.GET_ATTRIBUTE.getFunctionName())); + List<String> filter2ValueToscaFunction = (List<String>) filter2Value.get(ToscaGetFunctionType.GET_ATTRIBUTE.getFunctionName()); + assertEquals(2, filter2ValueToscaFunction.size()); + assertEquals("SELF", filter2ValueToscaFunction.get(0)); + assertEquals("role", filter2ValueToscaFunction.get(1)); } private void addComplexTypeToDataTypes() { diff --git a/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml index 7daba75d5e..b94b5ab11b 100644 --- a/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml +++ b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml @@ -77,6 +77,27 @@ start: virtual_cpu_pinning_rule: - 1 - 2 + filters: + - my_attribute: + equal: + get_attribute: + - SELF + - role + - my_attribute1: + greaterThan: my_other_value + - my_attribute2: + inRange: + - test1 + - test99 + - my_attribute3: + validValues: + - test1 + - test2 + - test3 + - my_attribute4: + length: 12 + - my_attribute5: + minLength: 4 on_timeout: activities: - type: delegate |