aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model
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-model
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-model')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java4
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyConstraint.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/ToscaPropertyData.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/FilterConstraintDto.java58
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java67
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/SubstitutionFilterOperation.java29
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java6
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaPropertyType.java13
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintType.java58
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterOrEqualConstraint.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterThanConstraint.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/InRangeConstraint.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LengthConstraint.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessOrEqualConstraint.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessThanConstraint.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/MaxLengthConstraint.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/MinLengthConstraint.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/PatternConstraint.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraint.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/DataTypeValidatorConverter.java23
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/MapValidator.java9
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/validation/FilterConstraintValidator.java39
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapper.java124
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/dto/FilterConstraintDtoTest.java101
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperationTest.java41
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractPropertyConstraintTest.java1
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractStringPropertyConstraintTest.java1
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapperTest.java142
29 files changed, 572 insertions, 158 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java
index 6af88e1215..326cfca202 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java
@@ -24,7 +24,7 @@ import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition;
@ToString
@Getter
@@ -37,6 +37,6 @@ public class ParsedToscaYamlInfo {
Map<String, GroupDefinition> groups;
Map<String, PolicyDefinition> policies;
Map<String, PropertyDefinition> properties;
- ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> substitutionFilterProperties;
+ ListDataDefinition<SubstitutionFilterPropertyDataDefinition> substitutionFilterProperties;
String substitutionMappingNodeType;
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyConstraint.java
index 6bc8083118..12a79ec90e 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyConstraint.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyConstraint.java
@@ -21,7 +21,7 @@ package org.openecomp.sdc.be.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openecomp.sdc.be.model.tosca.ToscaType;
-import org.openecomp.sdc.be.model.tosca.constraints.ConstraintType;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintViolationException;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ToscaPropertyData.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ToscaPropertyData.java
index 14c95757c7..6626d9aa3d 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ToscaPropertyData.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ToscaPropertyData.java
@@ -26,6 +26,7 @@ package org.openecomp.sdc.be.model;
*/
public interface ToscaPropertyData {
String getUniqueId();
+ String getName();
String getType();
String getSchemaType();
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/FilterConstraintDto.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/FilterConstraintDto.java
new file mode 100644
index 0000000000..b9ceb11276
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/FilterConstraintDto.java
@@ -0,0 +1,58 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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.model.dto;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.Optional;
+import lombok.Data;
+import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
+import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
+
+@Data
+public class FilterConstraintDto {
+
+ private String propertyName;
+ private String capabilityName;
+ private PropertyFilterTargetType targetType;
+ private ConstraintType operator;
+ private FilterValueType valueType;
+ private Object value;
+
+ public boolean isCapabilityPropertyFilter() {
+ return capabilityName != null;
+ }
+
+ public Optional<ToscaGetFunctionDataDefinition> getAsToscaGetFunction() {
+ if (value instanceof ToscaGetFunctionDataDefinition) {
+ return Optional.of((ToscaGetFunctionDataDefinition) value);
+ }
+ try {
+ return Optional.of(new ObjectMapper().convertValue(value, ToscaGetFunctionDataDefinition.class));
+ } catch (final Exception ignored) {
+ return Optional.empty();
+ }
+ }
+
+}
+
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java
index 2d0693af76..3dc2a73466 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java
@@ -19,8 +19,6 @@
*/
package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
import fj.data.Either;
import java.util.ArrayList;
import java.util.List;
@@ -33,8 +31,8 @@ import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterCapabilityDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType;
import org.openecomp.sdc.be.model.Component;
@@ -69,7 +67,7 @@ public class NodeFilterOperation extends BaseOperation {
public Either<String, StorageOperationStatus> deleteNodeFilter(final Component component, final String componentInstanceId) {
final Either<Set<String>, StorageOperationStatus> listStorageOperationStatusEither = deleteNodeFilters(component,
- ImmutableSet.of(componentInstanceId));
+ Set.of(componentInstanceId));
if (listStorageOperationStatusEither.isRight()) {
return Either.right(listStorageOperationStatusEither.right().value());
}
@@ -86,7 +84,7 @@ public class NodeFilterOperation extends BaseOperation {
final int propertyIndex,
final NodeFilterConstraintType nodeFilterConstraintType) {
if (NodeFilterConstraintType.PROPERTIES.equals(nodeFilterConstraintType)) {
- final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> properties = nodeFilterDataDefinition.getProperties();
+ final ListDataDefinition<PropertyFilterDataDefinition> properties = nodeFilterDataDefinition.getProperties();
properties.getListToscaDataDefinition().remove(propertyIndex);
nodeFilterDataDefinition.setProperties(properties);
} else if (NodeFilterConstraintType.CAPABILITIES.equals(nodeFilterConstraintType)) {
@@ -97,22 +95,22 @@ public class NodeFilterOperation extends BaseOperation {
return addOrUpdateNodeFilter(true, serviceId, componentInstanceId, nodeFilterDataDefinition);
}
- public Either<CINodeFilterDataDefinition, StorageOperationStatus> addNewProperty(final String componentId, final String componentInstanceId,
- final CINodeFilterDataDefinition nodeFilterDataDefinition,
- final RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition) {
- ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> properties = nodeFilterDataDefinition.getProperties();
+ public Either<CINodeFilterDataDefinition, StorageOperationStatus> addPropertyFilter(final String componentId, final String componentInstanceId,
+ final CINodeFilterDataDefinition nodeFilterDataDefinition,
+ final PropertyFilterDataDefinition propertyFilterDataDefinition) {
+ ListDataDefinition<PropertyFilterDataDefinition> properties = nodeFilterDataDefinition.getProperties();
if (properties == null) {
properties = new ListDataDefinition<>();
nodeFilterDataDefinition.setProperties(properties);
}
- properties.getListToscaDataDefinition().add(requirementNodeFilterPropertyDataDefinition);
+ properties.getListToscaDataDefinition().add(propertyFilterDataDefinition);
nodeFilterDataDefinition.setProperties(properties);
return addOrUpdateNodeFilter(true, componentId, componentInstanceId, nodeFilterDataDefinition);
}
- public Either<CINodeFilterDataDefinition, StorageOperationStatus> addNewCapabilities(final String componentId, final String componentInstanceId,
- final CINodeFilterDataDefinition nodeFilterDataDefinition,
- final RequirementNodeFilterCapabilityDataDefinition requirementNodeFilterCapabilityDataDefinition) {
+ public Either<CINodeFilterDataDefinition, StorageOperationStatus> addCapabilities(final String componentId, final String componentInstanceId,
+ final CINodeFilterDataDefinition nodeFilterDataDefinition,
+ final RequirementNodeFilterCapabilityDataDefinition requirementNodeFilterCapabilityDataDefinition) {
ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> capabilities = nodeFilterDataDefinition.getCapabilities();
if (capabilities == null) {
capabilities = new ListDataDefinition<>();
@@ -124,9 +122,9 @@ public class NodeFilterOperation extends BaseOperation {
.filter(def -> def.getName().equals(requirementNodeFilterCapabilityDataDefinition.getName())).findAny();
if (existingCap.isPresent()) {
- final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> newProperties = requirementNodeFilterCapabilityDataDefinition.getProperties();
- final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> existingProperties = existingCap.get().getProperties();
- newProperties.getListToscaDataDefinition().stream().forEach((prop -> existingProperties.add(prop))) ;
+ final ListDataDefinition<PropertyFilterDataDefinition> newProperties = requirementNodeFilterCapabilityDataDefinition.getProperties();
+ final ListDataDefinition<PropertyFilterDataDefinition> existingProperties = existingCap.get().getProperties();
+ newProperties.getListToscaDataDefinition().forEach((existingProperties::add)) ;
} else {
capabilities.getListToscaDataDefinition().add(requirementNodeFilterCapabilityDataDefinition);
}
@@ -134,26 +132,6 @@ public class NodeFilterOperation extends BaseOperation {
return addOrUpdateNodeFilter(true, componentId, componentInstanceId, nodeFilterDataDefinition);
}
- public Either<CINodeFilterDataDefinition, StorageOperationStatus> updateProperties(final String componentId, final String componentInstanceId,
- final CINodeFilterDataDefinition nodeFilterDataDefinition,
- final List<RequirementNodeFilterPropertyDataDefinition> requirementNodeFilterPropertyDataDefinition) {
- final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> properties = nodeFilterDataDefinition.getProperties();
- properties.getListToscaDataDefinition().clear();
- properties.getListToscaDataDefinition().addAll(requirementNodeFilterPropertyDataDefinition);
- nodeFilterDataDefinition.setProperties(properties);
- return addOrUpdateNodeFilter(true, componentId, componentInstanceId, nodeFilterDataDefinition);
- }
-
- public Either<CINodeFilterDataDefinition, StorageOperationStatus> updateCapabilities(final String componentId, final String componentInstanceId,
- final CINodeFilterDataDefinition nodeFilterDataDefinition,
- final List<RequirementNodeFilterCapabilityDataDefinition> requirementNodeFilterCapabilityDataDefinitions) {
- final ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> capabilities = nodeFilterDataDefinition.getCapabilities();
- capabilities.getListToscaDataDefinition().clear();
- capabilities.getListToscaDataDefinition().addAll(requirementNodeFilterCapabilityDataDefinitions);
- nodeFilterDataDefinition.setCapabilities(capabilities);
- return addOrUpdateNodeFilter(true, componentId, componentInstanceId, nodeFilterDataDefinition);
- }
-
public Either<CINodeFilterDataDefinition, StorageOperationStatus> updateNodeFilter(final String serviceId, final String componentInstanceId,
final CINodeFilterDataDefinition ciNodeFilterDataDefinition) {
return addOrUpdateNodeFilter(true, serviceId, componentInstanceId, ciNodeFilterDataDefinition);
@@ -169,20 +147,19 @@ public class NodeFilterOperation extends BaseOperation {
private Either<CINodeFilterDataDefinition, StorageOperationStatus> addOrUpdateNodeFilter(final boolean isUpdateAction, final String componentId,
final String componentInstanceId,
final CINodeFilterDataDefinition ciNodeFilterDataDefinition) {
- StorageOperationStatus statusRes;
- Either<GraphVertex, JanusGraphOperationStatus> getToscaElementRes;
- getToscaElementRes = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
- if (getToscaElementRes.isRight()) {
- JanusGraphOperationStatus status = getToscaElementRes.right().value();
+
+ final Either<GraphVertex, JanusGraphOperationStatus> serviceVertexEither =
+ janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (serviceVertexEither.isRight()) {
+ JanusGraphOperationStatus status = serviceVertexEither.right().value();
CommonUtility
.addRecordToLog(logger, CommonUtility.LogLevelEnum.DEBUG, "Failed to get tosca element {} upon adding the properties. Status is {}. ",
componentId, status);
- statusRes = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status);
- return Either.right(statusRes);
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
}
- GraphVertex serviceVertex = getToscaElementRes.left().value();
+ final GraphVertex serviceVertex = serviceVertexEither.left().value();
ciNodeFilterDataDefinition.setID(componentInstanceId);
- statusRes = performUpdateToscaAction(isUpdateAction, serviceVertex, ImmutableList.of(ciNodeFilterDataDefinition));
+ final StorageOperationStatus statusRes = performUpdateToscaAction(isUpdateAction, serviceVertex, List.of(ciNodeFilterDataDefinition));
if (!statusRes.equals(StorageOperationStatus.OK)) {
janusGraphDao.rollback();
logger.error(" Failed to perform tosca update for node filter in service {} , component instance {}. status is {}", componentId,
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/SubstitutionFilterOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/SubstitutionFilterOperation.java
index b4873fa78a..ca50f42453 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/SubstitutionFilterOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/SubstitutionFilterOperation.java
@@ -18,7 +18,6 @@
*/
package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
-import com.google.common.collect.ImmutableList;
import fj.data.Either;
import java.util.List;
import java.util.Objects;
@@ -28,8 +27,8 @@ import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
@@ -50,7 +49,7 @@ public class SubstitutionFilterOperation extends BaseOperation {
public Either<SubstitutionFilterDataDefinition, StorageOperationStatus> deleteConstraint(final String serviceId,
final SubstitutionFilterDataDefinition substitutionFilterDataDefinition,
final int propertyIndex) {
- final ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> properties = substitutionFilterDataDefinition.getProperties();
+ final ListDataDefinition<SubstitutionFilterPropertyDataDefinition> properties = substitutionFilterDataDefinition.getProperties();
properties.getListToscaDataDefinition().remove(propertyIndex);
substitutionFilterDataDefinition.setProperties(properties);
return addOrUpdateSubstitutionFilter(true, serviceId, substitutionFilterDataDefinition);
@@ -58,26 +57,34 @@ public class SubstitutionFilterOperation extends BaseOperation {
public Either<SubstitutionFilterDataDefinition, StorageOperationStatus> addPropertyFilter(final String componentId,
final SubstitutionFilterDataDefinition substitutionFilterDataDefinition,
- final RequirementSubstitutionFilterPropertyDataDefinition substitutionFilterPropertyDataDefinition) {
+ final SubstitutionFilterPropertyDataDefinition substitutionFilterPropertyDataDefinition) {
final SubstitutionFilterDataDefinition substitutionFilterDataDefinition1 = Objects
.requireNonNullElseGet(substitutionFilterDataDefinition, SubstitutionFilterDataDefinition::new);
- final ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> properties = Objects
+ final ListDataDefinition<SubstitutionFilterPropertyDataDefinition> properties = Objects
.requireNonNullElseGet(substitutionFilterDataDefinition1.getProperties(), ListDataDefinition::new);
properties.getListToscaDataDefinition().add(substitutionFilterPropertyDataDefinition);
substitutionFilterDataDefinition1.setProperties(properties);
return addOrUpdateSubstitutionFilter(true, componentId, substitutionFilterDataDefinition1);
}
- public Either<SubstitutionFilterDataDefinition, StorageOperationStatus> updateProperties(final String componentId,
- final SubstitutionFilterDataDefinition substitutionFilterDataDefinition,
- final List<RequirementSubstitutionFilterPropertyDataDefinition> requirementSubstitutionFilterPropertyDataDefinition) {
- final ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> properties = substitutionFilterDataDefinition.getProperties();
+ public Either<SubstitutionFilterDataDefinition, StorageOperationStatus> updatePropertyFilters(final String componentId,
+ final SubstitutionFilterDataDefinition substitutionFilterDataDefinition,
+ final List<SubstitutionFilterPropertyDataDefinition> substitutionFilterPropertyDataDefinition) {
+ final ListDataDefinition<SubstitutionFilterPropertyDataDefinition> properties = substitutionFilterDataDefinition.getProperties();
properties.getListToscaDataDefinition().clear();
- properties.getListToscaDataDefinition().addAll(requirementSubstitutionFilterPropertyDataDefinition);
+ properties.getListToscaDataDefinition().addAll(substitutionFilterPropertyDataDefinition);
substitutionFilterDataDefinition.setProperties(properties);
return addOrUpdateSubstitutionFilter(true, componentId, substitutionFilterDataDefinition);
}
+ public Either<SubstitutionFilterDataDefinition, StorageOperationStatus> updatePropertyFilter(final String componentId,
+ final SubstitutionFilterDataDefinition substitutionFilter,
+ final SubstitutionFilterPropertyDataDefinition substitutionFilterProperty,
+ final int index) {
+ substitutionFilter.getProperties().getListToscaDataDefinition().set(index, substitutionFilterProperty);
+ return addOrUpdateSubstitutionFilter(true, componentId, substitutionFilter);
+ }
+
private Either<SubstitutionFilterDataDefinition, StorageOperationStatus> addOrUpdateSubstitutionFilter(final boolean isUpdateAction,
final String componentId,
final SubstitutionFilterDataDefinition substitutionFilterDataDefinition) {
@@ -92,7 +99,7 @@ public class SubstitutionFilterOperation extends BaseOperation {
final GraphVertex serviceVertex = toscaElementEither.left().value();
substitutionFilterDataDefinition.setID(componentId);
final StorageOperationStatus operationStatus = performUpdateToscaAction(isUpdateAction, serviceVertex,
- ImmutableList.of(substitutionFilterDataDefinition));
+ List.of(substitutionFilterDataDefinition));
if (!StorageOperationStatus.OK.equals(operationStatus)) {
janusGraphDao.rollback();
LOGGER.error(EcompErrorSeverity.ERROR, EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR,
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
index b5215dc848..6b580527c4 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
@@ -82,12 +82,11 @@ import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.IComplexDefaultValue;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.validation.ToscaFunctionValidator;
import org.openecomp.sdc.be.model.operations.api.DerivedFromOperation;
import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
-import org.openecomp.sdc.be.model.tosca.constraints.ConstraintType;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
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;
@@ -96,6 +95,7 @@ import org.openecomp.sdc.be.model.tosca.constraints.LessThanConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.MinLengthConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.ValidValuesConstraint;
import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
+import org.openecomp.sdc.be.model.validation.ToscaFunctionValidator;
import org.openecomp.sdc.be.resources.data.ComponentInstanceData;
import org.openecomp.sdc.be.resources.data.DataTypeData;
import org.openecomp.sdc.be.resources.data.ModelData;
@@ -2145,7 +2145,7 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
Entry<String, JsonElement> element = set.iterator().next();
String key = element.getKey();
JsonElement value = element.getValue();
- ConstraintType constraintType = ConstraintType.getByType(key);
+ ConstraintType constraintType = ConstraintType.findByType(key).orElse(null);
if (constraintType == null) {
log.warn("ConstraintType was not found for constraint name:{}", key);
} else {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaPropertyType.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaPropertyType.java
index ec7ca43155..364dfd33fb 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaPropertyType.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaPropertyType.java
@@ -71,10 +71,10 @@ public enum ToscaPropertyType {
JSON("json", JsonValidator.getInstance(), JsonConverter.getInstance(), ToscaJsonValueConverter.getInstance());
// @formatter:on
- private String type;
- private PropertyTypeValidator validator;
- private PropertyValueConverter converter;
- private ToscaValueConverter valueConverter;
+ private final String type;
+ private final PropertyTypeValidator validator;
+ private final PropertyValueConverter converter;
+ private final ToscaValueConverter valueConverter;
private boolean isAbstract = false;
ToscaPropertyType(String type, PropertyTypeValidator validator, PropertyValueConverter converter, ToscaValueConverter valueConverter) {
@@ -111,10 +111,7 @@ public enum ToscaPropertyType {
if (ToscaPropertyType.MAP.getType().equals(dataTypeName) || ToscaPropertyType.LIST.getType().equals(dataTypeName)) {
return false;
}
- if (isScalarType(dataTypeName)) {
- return true;
- }
- return false;
+ return isScalarType(dataTypeName);
}
public static ToscaPropertyType getTypeIfScalar(String dataTypeName) {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintType.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintType.java
deleted file mode 100644
index 3647bd67d0..0000000000
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintType.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-package org.openecomp.sdc.be.model.tosca.constraints;
-
-import java.util.Arrays;
-import java.util.List;
-
-public enum ConstraintType {
- // @formatter:off
- EQUAL("equal", "equal"),
- IN_RANGE("inRange", "in_range"),
- GREATER_THAN("greaterThan", "greater_than"),
- GREATER_OR_EQUAL("greaterOrEqual", "greater_or_equal"),
- LESS_OR_EQUAL("lessOrEqual", "less_or_equal"),
- LENGTH("length", "length"),
- MIN_LENGTH("minLength", "min_length"),
- MAX_LENGTH("maxLength", "max_length"),
- VALID_VALUES("validValues", "valid_values"),
- LESS_THAN("lessThan", "less_than"),
- SCHEMA("schema", "schema");
- // @formatter:on
-
- List<String> types;
-
- private ConstraintType(String... types) {
- this.types = Arrays.asList(types);
- }
-
- public static ConstraintType getByType(String type) {
- for (ConstraintType inst : ConstraintType.values()) {
- if (inst.getTypes().contains(type)) {
- return inst;
- }
- }
- return null;
- }
-
- public List<String> getTypes() {
- return types;
- }
-}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java
index 4b62b12897..c4b26f3077 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java
@@ -21,6 +21,7 @@ package org.openecomp.sdc.be.model.tosca.constraints;
import java.io.Serializable;
import javax.validation.constraints.NotNull;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterOrEqualConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterOrEqualConstraint.java
index dc50d7d549..d32ab721fc 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterOrEqualConstraint.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterOrEqualConstraint.java
@@ -23,6 +23,7 @@ import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterThanConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterThanConstraint.java
index 0b76e97967..e50c8fe3d0 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterThanConstraint.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterThanConstraint.java
@@ -20,6 +20,7 @@
package org.openecomp.sdc.be.model.tosca.constraints;
import javax.validation.constraints.NotNull;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/InRangeConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/InRangeConstraint.java
index bfb1b75a5c..d574816c5f 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/InRangeConstraint.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/InRangeConstraint.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.be.model.tosca.constraints;
import com.google.common.collect.Lists;
import java.util.List;
import javax.validation.constraints.NotNull;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LengthConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LengthConstraint.java
index 3c89ed1b07..457c824ac6 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LengthConstraint.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LengthConstraint.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.be.model.tosca.constraints;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotNull;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessOrEqualConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessOrEqualConstraint.java
index 653c93bf29..62cec05a73 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessOrEqualConstraint.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessOrEqualConstraint.java
@@ -20,6 +20,7 @@
package org.openecomp.sdc.be.model.tosca.constraints;
import javax.validation.constraints.NotNull;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessThanConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessThanConstraint.java
index 59c091f224..c721c5cd63 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessThanConstraint.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessThanConstraint.java
@@ -21,6 +21,7 @@ package org.openecomp.sdc.be.model.tosca.constraints;
import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/MaxLengthConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/MaxLengthConstraint.java
index 2535d972ca..004e431485 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/MaxLengthConstraint.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/MaxLengthConstraint.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.be.model.tosca.constraints;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotNull;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/MinLengthConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/MinLengthConstraint.java
index 98fda80604..a2ff95512a 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/MinLengthConstraint.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/MinLengthConstraint.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.be.model.tosca.constraints;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotNull;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/PatternConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/PatternConstraint.java
index e3f4d3e7e3..e519f1b7e4 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/PatternConstraint.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/PatternConstraint.java
@@ -21,6 +21,7 @@ package org.openecomp.sdc.be.model.tosca.constraints;
import java.util.regex.Pattern;
import javax.validation.constraints.NotNull;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraint.java
index fb4685d716..1cafc213bb 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraint.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraint.java
@@ -26,6 +26,7 @@ import java.util.List;
import java.util.Set;
import javax.validation.constraints.NotNull;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/DataTypeValidatorConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/DataTypeValidatorConverter.java
index 0a537a5445..4a5cda2fdd 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/DataTypeValidatorConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/DataTypeValidatorConverter.java
@@ -29,6 +29,8 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
@@ -36,18 +38,13 @@ import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
import org.openecomp.sdc.common.log.wrappers.Logger;
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class DataTypeValidatorConverter {
private static final Logger log = Logger.getLogger(DataTypeValidatorConverter.class.getName());
- private static DataTypeValidatorConverter dataTypeValidatorConverter = new DataTypeValidatorConverter();
- JsonParser jsonParser = new JsonParser();
- ImmutablePair<JsonElement, Boolean> falseResult = new ImmutablePair<>(null, false);
- ImmutablePair<JsonElement, Boolean> trueEmptyResult = new ImmutablePair<>(null, true);
- ImmutablePair<String, Boolean> trueStringEmptyResult = new ImmutablePair<>(null, true);
- ImmutablePair<String, Boolean> falseStringEmptyResult = new ImmutablePair<>(null, true);
-
- private DataTypeValidatorConverter() {
- }
+ private static final DataTypeValidatorConverter dataTypeValidatorConverter = new DataTypeValidatorConverter();
+ private static final ImmutablePair<JsonElement, Boolean> falseResult = new ImmutablePair<>(null, false);
+ private static final ImmutablePair<JsonElement, Boolean> trueEmptyResult = new ImmutablePair<>(null, true);
public static DataTypeValidatorConverter getInstance() {
return dataTypeValidatorConverter;
@@ -101,7 +98,7 @@ public class DataTypeValidatorConverter {
String convertedValue = converter.convert(value, null, allDataTypes);
JsonElement element = null;
try {
- element = jsonParser.parse(convertedValue);
+ element = JsonParser.parseString(convertedValue);
} catch (JsonSyntaxException e) {
log.debug("Failed to parse value {} of property {} {}", convertedValue, dataTypeDefinition.getName(), e);
return falseResult;
@@ -174,7 +171,7 @@ public class DataTypeValidatorConverter {
element = new JsonPrimitive("");
} else {
try {
- element = jsonParser.parse(convertedValue);
+ element = JsonParser.parseString(convertedValue);
} catch (JsonSyntaxException e) {
log.debug("Failed to parse value {} of type {}", convertedValue, propertyType, e);
return falseResult;
@@ -237,9 +234,9 @@ public class DataTypeValidatorConverter {
if (value == null || value.isEmpty()) {
return true;
}
- JsonElement jsonElement = null;
+ JsonElement jsonElement;
try {
- jsonElement = jsonParser.parse(value);
+ jsonElement = JsonParser.parseString(value);
} catch (JsonSyntaxException e) {
log.debug("Failed to parse the value {} from type {}", value, dataTypeDefinition, e);
return false;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/MapValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/MapValidator.java
index 2635647467..d3424b8612 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/MapValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/MapValidator.java
@@ -52,9 +52,8 @@ Keys always need " " around them.
public class MapValidator implements PropertyTypeValidator {
private static final Logger log = Logger.getLogger(MapValidator.class.getName());
- private static MapValidator mapValidator = new MapValidator();
- private static DataTypeValidatorConverter dataTypeValidatorConverter = DataTypeValidatorConverter.getInstance();
- private static JsonParser jsonParser = new JsonParser();
+ private static final MapValidator mapValidator = new MapValidator();
+ private static final DataTypeValidatorConverter dataTypeValidatorConverter = DataTypeValidatorConverter.getInstance();
public static MapValidator getInstance() {
return mapValidator;
@@ -99,7 +98,7 @@ public class MapValidator implements PropertyTypeValidator {
return isValid;
}
try {
- JsonElement jsonObject = jsonParser.parse(value);
+ JsonElement jsonObject = JsonParser.parseString(value);
if (!jsonObject.isJsonObject()) {
return false;
}
@@ -134,7 +133,7 @@ public class MapValidator implements PropertyTypeValidator {
return false;
}
try {
- JsonElement jsonObject = jsonParser.parse(value);
+ JsonElement jsonObject = JsonParser.parseString(value);
JsonObject asJsonObject = jsonObject.getAsJsonObject();
Set<Entry<String, JsonElement>> entrySet = asJsonObject.entrySet();
for (Entry<String, JsonElement> entry : entrySet) {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/validation/FilterConstraintValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/validation/FilterConstraintValidator.java
new file mode 100644
index 0000000000..634b1efe85
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/validation/FilterConstraintValidator.java
@@ -0,0 +1,39 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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.model.validation;
+
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
+
+/**
+ * Handle validation for a node/substitution filter constraint
+ */
+public interface FilterConstraintValidator {
+
+ /**
+ * Validates a node/substitution filter constraint
+ *
+ * @param filterConstraint the filter constraint
+ * @throws RuntimeException when the filter constraint is invalid
+ */
+ void validate(final FilterConstraintDto filterConstraint);
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapper.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapper.java
new file mode 100644
index 0000000000..da486e47f5
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapper.java
@@ -0,0 +1,124 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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.ui.mapper;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
+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.datatypes.enums.FilterValueType;
+import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
+import org.openecomp.sdc.be.ui.model.UIConstraint;
+
+public class FilterConstraintMapper {
+
+ public FilterConstraintDto mapFrom(final UIConstraint uiConstraint) {
+ final var filterConstraint = new FilterConstraintDto();
+ ConstraintType.findByType(uiConstraint.getConstraintOperator()).ifPresent(filterConstraint::setOperator);
+ filterConstraint.setCapabilityName(uiConstraint.getCapabilityName());
+ filterConstraint.setPropertyName(uiConstraint.getServicePropertyName());
+ filterConstraint.setTargetType(StringUtils.isEmpty(uiConstraint.getCapabilityName()) ? PropertyFilterTargetType.PROPERTY : PropertyFilterTargetType.CAPABILITY);
+ FilterValueType.findByName(uiConstraint.getSourceType()).ifPresent(filterConstraint::setValueType);
+ filterConstraint.setValue(parseValueFromUiConstraint(uiConstraint.getValue()));
+ return filterConstraint;
+ }
+
+ public FilterConstraintDto mapFrom(final PropertyFilterConstraintDataDefinition propertyFilterConstraint) {
+ var filterConstraintDto = new FilterConstraintDto();
+ filterConstraintDto.setTargetType(propertyFilterConstraint.getTargetType());
+ filterConstraintDto.setPropertyName(propertyFilterConstraint.getPropertyName());
+ filterConstraintDto.setCapabilityName(propertyFilterConstraint.getCapabilityName());
+ filterConstraintDto.setOperator(propertyFilterConstraint.getOperator());
+ filterConstraintDto.setValueType(propertyFilterConstraint.getValueType());
+ filterConstraintDto.setValue(propertyFilterConstraint.getValue());
+ return filterConstraintDto;
+ }
+
+ public PropertyFilterConstraintDataDefinition mapTo(final FilterConstraintDto filterConstraintDto) {
+ var propertyFilterConstraint = new PropertyFilterConstraintDataDefinition();
+ propertyFilterConstraint.setTargetType(filterConstraintDto.getTargetType());
+ propertyFilterConstraint.setPropertyName(filterConstraintDto.getPropertyName());
+ propertyFilterConstraint.setCapabilityName(filterConstraintDto.getCapabilityName());
+ propertyFilterConstraint.setOperator(filterConstraintDto.getOperator());
+ propertyFilterConstraint.setValueType(filterConstraintDto.getValueType());
+ propertyFilterConstraint.setValue(filterConstraintDto.getValue());
+ return propertyFilterConstraint;
+ }
+
+ public UIConstraint mapToUiConstraint(final FilterConstraintDto filterConstraintDto) {
+ final var uiConstraint = new UIConstraint();
+ uiConstraint.setConstraintOperator(filterConstraintDto.getOperator().getType());
+ uiConstraint.setValue(filterConstraintDto.getValue());
+ uiConstraint.setCapabilityName(filterConstraintDto.getCapabilityName());
+ uiConstraint.setServicePropertyName(filterConstraintDto.getPropertyName());
+ uiConstraint.setSourceType(filterConstraintDto.getValueType().getName());
+ return uiConstraint;
+ }
+
+ private Object parseValueFromUiConstraint(final Object value) {
+ if (!(value instanceof Map || value instanceof String)) {
+ return value;
+ }
+ final Map<?, ?> valueAsMap;
+ if (value instanceof String) {
+ try {
+ valueAsMap = new Gson().fromJson((String) value, Map.class);
+ } catch (final Exception ignored) {
+ return value;
+ }
+ } else {
+ valueAsMap = (Map<?, ?>) value;
+ }
+
+ final Optional<ToscaFunction> toscaFunction = parseValueToToscaFunction(valueAsMap);
+ if (toscaFunction.isPresent()) {
+ return toscaFunction.get();
+ }
+
+ return valueAsMap;
+ }
+
+ public Optional<ToscaFunction> parseValueToToscaFunction(final Object value) {
+ if (value instanceof ToscaFunction) {
+ return Optional.of((ToscaFunction) value);
+ }
+ return readToscaFunctionType(value).map(toscaFunctionType -> new ObjectMapper().convertValue(value, ToscaFunction.class));
+ }
+
+ private Optional<ToscaFunctionType> readToscaFunctionType(final Object toscaFunction) {
+ if (!(toscaFunction instanceof Map)) {
+ return Optional.empty();
+ }
+ final Object type = ((Map<?, ?>) toscaFunction).get("type");
+ if (type instanceof String) {
+ return ToscaFunctionType.findType((String) type);
+ }
+ return Optional.empty();
+ }
+
+}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/dto/FilterConstraintDtoTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/dto/FilterConstraintDtoTest.java
new file mode 100644
index 0000000000..e67fdc0f33
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/dto/FilterConstraintDtoTest.java
@@ -0,0 +1,101 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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.model.dto;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.PropertySource;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
+
+class FilterConstraintDtoTest {
+
+ @Test
+ void isCapabilityPropertyFilter() {
+ var filterConstraintDto = new FilterConstraintDto();
+ assertFalse(filterConstraintDto.isCapabilityPropertyFilter());
+ filterConstraintDto.setCapabilityName("aCapability");
+ assertTrue(filterConstraintDto.isCapabilityPropertyFilter());
+ }
+
+ @Test
+ void readGetFunctionWithToscaGetFunctionInstanceAsValue() {
+ final var filterConstraintDto = new FilterConstraintDto();
+ final var toscaGetFunction = new ToscaGetFunctionDataDefinition();
+ toscaGetFunction.setFunctionType(ToscaGetFunctionType.GET_PROPERTY);
+ filterConstraintDto.setValue(toscaGetFunction);
+ final Optional<ToscaGetFunctionDataDefinition> readGetFunctionOpt = filterConstraintDto.getAsToscaGetFunction();
+ assertTrue(readGetFunctionOpt.isPresent());
+ assertEquals(toscaGetFunction, readGetFunctionOpt.get());
+ }
+
+ @Test
+ void readGetFunctionWithInvalidGetFunctionValue() {
+ final var filterConstraintDto = new FilterConstraintDto();
+ filterConstraintDto.setValue("not a ToscaGetFunctionDataDefinition");
+ final Optional<ToscaGetFunctionDataDefinition> readGetFunctionOpt = filterConstraintDto.getAsToscaGetFunction();
+ assertTrue(readGetFunctionOpt.isEmpty());
+ }
+
+ @Test
+ void readGetFunctionWithGetFunctionValueAsMap() {
+ //given
+ final List<String> propertyPathFromSource = List.of("input", "path");
+ final String propertyUniqueId = "propertyUniqueIdValue";
+ final String propertyName = "propertyNameValue";
+ final String sourceUniqueId = "sourceUniqueIdValue";
+ final String sourceName = "sourceNameValue";
+ final Map<String, Object> toscaGetFunctionAsMap = Map.of(
+ "propertyUniqueId", propertyUniqueId,
+ "propertyName", propertyName,
+ "propertySource", PropertySource.SELF.getName(),
+ "sourceUniqueId", sourceUniqueId,
+ "sourceName", sourceName,
+ "functionType", ToscaGetFunctionType.GET_INPUT.getFunctionName(),
+ "propertyPathFromSource", propertyPathFromSource
+ );
+
+ final var filterConstraintDto = new FilterConstraintDto();
+ filterConstraintDto.setValue(toscaGetFunctionAsMap);
+ //when
+ final Optional<ToscaGetFunctionDataDefinition> readGetFunctionOpt = filterConstraintDto.getAsToscaGetFunction();
+ //then
+ assertTrue(readGetFunctionOpt.isPresent());
+ final ToscaGetFunctionDataDefinition toscaGetFunctionDataDefinition = readGetFunctionOpt.get();
+ assertEquals(toscaGetFunctionDataDefinition.getPropertyUniqueId(), propertyUniqueId);
+ assertEquals(toscaGetFunctionDataDefinition.getPropertyName(), propertyName);
+ assertEquals(toscaGetFunctionDataDefinition.getPropertySource(), PropertySource.SELF);
+ assertEquals(toscaGetFunctionDataDefinition.getSourceUniqueId(), sourceUniqueId);
+ assertEquals(toscaGetFunctionDataDefinition.getSourceName(), sourceName);
+ assertEquals(toscaGetFunctionDataDefinition.getFunctionType(), ToscaGetFunctionType.GET_INPUT);
+ assertEquals(toscaGetFunctionDataDefinition.getPropertyPathFromSource().size(), 2);
+ assertEquals(toscaGetFunctionDataDefinition.getPropertyPathFromSource().get(0), propertyPathFromSource.get(0));
+ assertEquals(toscaGetFunctionDataDefinition.getPropertyPathFromSource().get(1), propertyPathFromSource.get(1));
+ }
+
+} \ No newline at end of file
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperationTest.java
index 0cbba25e04..bd16016ad9 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperationTest.java
@@ -21,6 +21,8 @@
package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
import fj.data.Either;
+import java.util.List;
+import java.util.Map;
import org.janusgraph.core.JanusGraphVertex;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -33,7 +35,11 @@ import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
+import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import java.util.Arrays;
@@ -66,19 +72,30 @@ class NodeFilterOperationTest {
nodeFilterDataDefinition.setName("new node filter name");
String prop1 = "property1";
String prop2 = "property2";
- RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition();
- requirementNodeFilterPropertyDataDefinition.setName("Name1");
- requirementNodeFilterPropertyDataDefinition
- .setConstraints(Arrays.asList("mem_size:\n" + " equal: { get_property : [" + prop1 + ", size]}\n"));
- RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition2 = new RequirementNodeFilterPropertyDataDefinition();
- requirementNodeFilterPropertyDataDefinition2.setName("Name2");
- requirementNodeFilterPropertyDataDefinition2
- .setConstraints(Arrays.asList("mem_size:\n {equal: { get_property : [SELF, " + prop2 + "]}}\n"));
+ final var propertyFilterDataDefinition = new PropertyFilterDataDefinition();
+ propertyFilterDataDefinition.setName("Name1");
+ final var propertyFilterConstraint1 = new PropertyFilterConstraintDataDefinition();
+ propertyFilterConstraint1.setPropertyName("mem_size");
+ propertyFilterConstraint1.setOperator(ConstraintType.EQUAL);
+ propertyFilterConstraint1.setValue(Map.of("get_property", List.of(prop1, "size")));
+ propertyFilterConstraint1.setValueType(FilterValueType.GET_PROPERTY);
+ propertyFilterConstraint1.setTargetType(PropertyFilterTargetType.PROPERTY);
+ propertyFilterDataDefinition.setConstraints(List.of(propertyFilterConstraint1));
- ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> listDataDefinition =
+ final var propertyFilterDataDefinition2 = new PropertyFilterDataDefinition();
+ propertyFilterDataDefinition2.setName("Name2");
+ final var propertyFilterConstraint2 = new PropertyFilterConstraintDataDefinition();
+ propertyFilterConstraint2.setPropertyName("mem_size");
+ propertyFilterConstraint2.setOperator(ConstraintType.EQUAL);
+ propertyFilterConstraint2.setValue(Map.of("get_property", List.of("SELF", prop2)));
+ propertyFilterConstraint2.setValueType(FilterValueType.GET_PROPERTY);
+ propertyFilterConstraint2.setTargetType(PropertyFilterTargetType.PROPERTY);
+ propertyFilterDataDefinition2.setConstraints(List.of(propertyFilterConstraint2));
+
+ ListDataDefinition<PropertyFilterDataDefinition> listDataDefinition =
new ListDataDefinition<>(Arrays.asList(
- requirementNodeFilterPropertyDataDefinition,
- requirementNodeFilterPropertyDataDefinition2));
+ propertyFilterDataDefinition,
+ propertyFilterDataDefinition2));
nodeFilterDataDefinition.setProperties(listDataDefinition);
String componentId = "componentId";
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractPropertyConstraintTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractPropertyConstraintTest.java
index 6fd578856d..621c95109e 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractPropertyConstraintTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractPropertyConstraintTest.java
@@ -24,6 +24,7 @@ package org.openecomp.sdc.be.model.tosca.constraints;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractStringPropertyConstraintTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractStringPropertyConstraintTest.java
index 376bac8ca9..595437fab6 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractStringPropertyConstraintTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractStringPropertyConstraintTest.java
@@ -24,6 +24,7 @@ package org.openecomp.sdc.be.model.tosca.constraints;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapperTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapperTest.java
new file mode 100644
index 0000000000..1ea72937b9
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapperTest.java
@@ -0,0 +1,142 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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.ui.mapper;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Map;
+import java.util.Optional;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ToscaConcatFunction;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunction;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType;
+import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
+import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
+import org.openecomp.sdc.be.ui.model.UIConstraint;
+
+class FilterConstraintMapperTest {
+
+ private final FilterConstraintMapper filterConstraintMapper = new FilterConstraintMapper();
+
+ @Test
+ void mapFromUIConstraintTest() {
+ //given
+ final var uIConstraint = new UIConstraint();
+ final FilterValueType filterValueType = FilterValueType.STATIC;
+ uIConstraint.setSourceType(filterValueType.getName());
+ final String capabilityName = "aCapability";
+ uIConstraint.setCapabilityName(capabilityName);
+ final String propertyName = "aProperty";
+ uIConstraint.setServicePropertyName(propertyName);
+ final ConstraintType operator = ConstraintType.GREATER_OR_EQUAL;
+ uIConstraint.setConstraintOperator(operator.getType());
+ final ToscaFunctionType expectedValueToscaFunctionType = ToscaFunctionType.GET_INPUT;
+ uIConstraint.setValue(Map.of("type", expectedValueToscaFunctionType.getName()));
+ //when
+ final FilterConstraintDto filterConstraintDto = filterConstraintMapper.mapFrom(uIConstraint);
+ //then
+ assertEquals(PropertyFilterTargetType.CAPABILITY, filterConstraintDto.getTargetType());
+ assertEquals(propertyName, filterConstraintDto.getPropertyName());
+ assertEquals(capabilityName, filterConstraintDto.getCapabilityName());
+ assertEquals(filterValueType, filterConstraintDto.getValueType());
+ assertTrue(filterConstraintDto.getValue() instanceof ToscaGetFunctionDataDefinition);
+ assertEquals(expectedValueToscaFunctionType, ((ToscaGetFunctionDataDefinition) filterConstraintDto.getValue()).getType());
+ assertEquals(operator, filterConstraintDto.getOperator());
+ //when
+ final UIConstraint actualUiConstraint = filterConstraintMapper.mapToUiConstraint(filterConstraintDto);
+ //then
+ assertEquals(propertyName, actualUiConstraint.getServicePropertyName());
+ assertEquals(capabilityName, actualUiConstraint.getCapabilityName());
+ assertEquals(filterValueType.getName(), actualUiConstraint.getSourceType());
+ assertTrue(actualUiConstraint.getValue() instanceof ToscaGetFunctionDataDefinition);
+ assertEquals(expectedValueToscaFunctionType, ((ToscaGetFunctionDataDefinition) actualUiConstraint.getValue()).getType());
+ assertEquals(operator.getType(), actualUiConstraint.getConstraintOperator());
+ assertNull(actualUiConstraint.getSourceName());
+ }
+
+ @Test
+ void mapFromPropertyFilterConstraintDataDefinitionTest() {
+ //given
+ final var propertyFilterConstraintDataDefinition = new PropertyFilterConstraintDataDefinition();
+ propertyFilterConstraintDataDefinition.setTargetType(PropertyFilterTargetType.CAPABILITY);
+ final String capabilityName = "aCapability";
+ propertyFilterConstraintDataDefinition.setCapabilityName(capabilityName);
+ final String propertyName = "aProperty";
+ propertyFilterConstraintDataDefinition.setPropertyName(propertyName);
+ final ConstraintType operator = ConstraintType.GREATER_OR_EQUAL;
+ propertyFilterConstraintDataDefinition.setOperator(operator);
+ final FilterValueType filterValueType = FilterValueType.STATIC;
+ propertyFilterConstraintDataDefinition.setValueType(filterValueType);
+ final String value = "aStaticValue";
+ propertyFilterConstraintDataDefinition.setValue(value);
+ //when
+ final FilterConstraintDto filterConstraintDto = filterConstraintMapper.mapFrom(propertyFilterConstraintDataDefinition);
+ //then
+ assertEquals(PropertyFilterTargetType.CAPABILITY, filterConstraintDto.getTargetType());
+ assertEquals(propertyName, filterConstraintDto.getPropertyName());
+ assertEquals(capabilityName, filterConstraintDto.getCapabilityName());
+ assertEquals(filterValueType, filterConstraintDto.getValueType());
+ assertEquals(value, filterConstraintDto.getValue());
+ assertEquals(operator, filterConstraintDto.getOperator());
+ //when
+ final PropertyFilterConstraintDataDefinition actualPropertyFilterConstraint =
+ filterConstraintMapper.mapTo(filterConstraintDto);
+ assertEquals(PropertyFilterTargetType.CAPABILITY, actualPropertyFilterConstraint.getTargetType());
+ assertEquals(propertyName, actualPropertyFilterConstraint.getPropertyName());
+ assertEquals(capabilityName, actualPropertyFilterConstraint.getCapabilityName());
+ assertEquals(filterValueType, actualPropertyFilterConstraint.getValueType());
+ assertEquals(value, actualPropertyFilterConstraint.getValue());
+ assertEquals(operator, actualPropertyFilterConstraint.getOperator());
+ }
+
+ @Test
+ void parseValueToToscaFunctionTest() {
+ //given
+ final ToscaConcatFunction expectedValue = new ToscaConcatFunction();
+ //when
+ Optional<ToscaFunction> actualToscaFunction = filterConstraintMapper.parseValueToToscaFunction(expectedValue);
+ //then
+ assertTrue(actualToscaFunction.isPresent());
+ assertEquals(expectedValue, actualToscaFunction.get());
+ //when
+ actualToscaFunction = filterConstraintMapper.parseValueToToscaFunction("not a tosca function");
+ //then
+ assertTrue(actualToscaFunction.isEmpty());
+ //given
+ final Map<String, Object> value = Map.of("type", ToscaFunctionType.CONCAT.getName());
+ //when
+ actualToscaFunction = filterConstraintMapper.parseValueToToscaFunction(value);
+ //then
+ assertTrue(actualToscaFunction.isPresent());
+ assertTrue(actualToscaFunction.get() instanceof ToscaConcatFunction);
+ //when
+ actualToscaFunction = filterConstraintMapper.parseValueToToscaFunction(Map.of("type", 1));
+ //then
+ assertTrue(actualToscaFunction.isEmpty());
+ }
+} \ No newline at end of file