aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml89
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java52
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java180
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java92
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/NodeFilterUploadCreator.java26
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/FilterConstraintExceptionSupplier.java40
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtils.java64
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtils.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/FilterConstraintValidatorImpl.java64
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java580
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java164
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java28
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java126
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServlet.java32
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServlet.java105
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java114
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraint.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintValidValues.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java43
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/SubstitutionFilterConverter.java32
-rw-r--r--catalog-be/src/main/resources/config/error-configuration.yaml560
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java322
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java97
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtilsTest.java19
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtilsTest.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/FilterConstraintValidatorImplTest.java125
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java391
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidatorTest.java553
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java31
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertorTest.java (renamed from catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ConstraintConvertorTest.java)79
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java98
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterRenameCiTest.java23
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsCIChangeTest.java49
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsPropertyRemovedTest.java15
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsServiceInputTest.java40
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java81
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServletTest.java73
-rw-r--r--catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml494
41 files changed, 3210 insertions, 1689 deletions
diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
index 50a7014f10..7eb5ee47e9 100644
--- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
+++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
@@ -2302,13 +2302,14 @@ errors:
messageId: "SVC4716"
}
- #---------SVC4717----------------------------
- # %1 - Property Name
- MAPPED_PROPERTY_NOT_FOUND: {
- code: 400,
- message: "Error: %1 property does not exist.",
- messageId: "SVC4717"
- }
+ #---------SVC4184----------------------------
+ # %1 - Source type
+ # %2 - Property Type
+ # %3 - Property Name
+ FILTER_PROPERTY_NOT_FOUND:
+ code: 400
+ message: "%1 %2 %3 does not exist."
+ messageId: "SVC4184"
#---------SVC4718----------------------------
# %1 - Property Name
@@ -2326,13 +2327,13 @@ errors:
messageId: "SVC4719"
}
- #---------SVC4720----------------------------
+ #---------SVC4182----------------------------
# %1 - Property Name
# %2 - Operator Type
SOURCE_TARGET_PROPERTY_TYPE_MISMATCH: {
code: 400,
- message: "Error: %1 property and %2 property type is not same.",
- messageId: "SVC4720"
+ message: "Error: Property '%1' type '%2' does not match with property '%3' type '%4'.",
+ messageId: "SVC4182"
}
#---------SVC4721----------------------------
@@ -2420,7 +2421,7 @@ errors:
messageId: "SVC4734"
}
#-----------SVC4735---------------------------
- #%1 - input name
+ #%1 - input name
INPUT_ALREADY_EXIST: {
code: 409,
message: "Error: Input with '%1' name already exists.",
@@ -2746,3 +2747,69 @@ errors:
message: "Relationship_templates definition not found in TOSCA CSAR.",
messageId: "SVC4174"
}
+
+ #-----------SVC4175---------------------------
+ TOSCA_FUNCTION_EXPECTED_ERROR: {
+ code: 400,
+ message: "Expecting a Tosca Function value.",
+ messageId: "SVC4175"
+ }
+
+ #-----------SVC4176---------------------------
+ FILTER_CONSTRAINT_MISSING: {
+ code: 400,
+ message: "The filter constraint was not provided.",
+ messageId: "SVC4176"
+ }
+
+ #-----------SVC4177---------------------------
+ #%1 - The missing field
+ FILTER_CONSTRAINT_MISSING_FIELD: {
+ code: 400,
+ message: "Required field '%1' is missing in the filter constraint.",
+ messageId: "SVC4177"
+ }
+
+ #%1 - the component id
+ SUBSTITUTION_FILTER_NOT_FOUND: {
+ code: 404,
+ message: 'Substitution filter not found in the component "%1"',
+ messageId: "SVC4178"
+ }
+
+ # %1 - Component name
+ COMPONENT_DOES_NOT_HAVE_INPUTS: {
+ code: 400,
+ message: "Component '%1' does not have inputs.",
+ messageId: "SVC4179"
+ }
+
+ # %1 - Input name
+ # %2 - Component name
+ COMPONENT_INPUT_NOT_FOUND: {
+ code: 400,
+ message: "Input '%1' does not exist in '%2'.",
+ messageId: "SVC4180"
+ }
+
+ # %1 - Target property name
+ # %2 - Source property name
+ SOURCE_TARGET_SCHEMA_MISMATCH: {
+ code: 400,
+ message: "Target property '%1' schema '%2' does not match with source property '%3' schema '%4'.",
+ messageId: "SVC4181"
+ }
+
+ # %1 - Property name
+ # %2 - Component name
+ COMPONENT_PROPERTY_NOT_FOUND:
+ code: 400
+ message: "Property '%1' does not exist in '%2'."
+ messageId: "SVC4183"
+
+ # %1 - The component type
+ # %2 - The expected component types
+ INVALID_COMPONENT_TYPE:
+ code: 400
+ message: "Invalid component type '%1'. Expected types are: %2"
+ messageId: "SVC4185"
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
index 25d5c1f43e..82aa1343c1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
@@ -103,7 +103,12 @@ import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunction;
+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.CapabilityDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
@@ -128,6 +133,7 @@ import org.openecomp.sdc.be.tosca.model.ToscaInterfaceDefinition;
import org.openecomp.sdc.be.tosca.utils.OperationArtifactUtil;
import org.openecomp.sdc.be.ui.model.OperationUi;
import org.openecomp.sdc.be.ui.model.PropertyAssignmentUi;
+import org.openecomp.sdc.be.utils.PropertyFilterConstraintDataDefinitionHelper;
import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.yaml.snakeyaml.parser.ParserException;
@@ -236,8 +242,8 @@ public class YamlTemplateParsingHandler {
return ImportUtils.getProperties(toscaJson).left().on(err -> new HashMap<>());
}
- private ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> getSubstitutionFilterProperties(Map<String, Object> toscaJson) {
- ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> propertyList = new ListDataDefinition<>();
+ private ListDataDefinition<SubstitutionFilterPropertyDataDefinition> getSubstitutionFilterProperties(Map<String, Object> toscaJson) {
+ ListDataDefinition<SubstitutionFilterPropertyDataDefinition> propertyList = new ListDataDefinition<>();
Map<String, Object> substitutionFilters = findFirstToscaMapElement(toscaJson, SUBSTITUTION_FILTERS).left().on(err -> new HashMap<>());
if (MapUtils.isEmpty(substitutionFilters)) {
return propertyList;
@@ -248,25 +254,41 @@ public class YamlTemplateParsingHandler {
return propertyList;
}
for (Map<String, List<Map<String, Object>>> filterProps : substitutionFilterProperties) {
- for (Map.Entry<String, List<Map<String, Object>>> filterPropsMap : filterProps.entrySet()) {
- for (Map<String, Object> mapValue : filterPropsMap.getValue()) {
- RequirementSubstitutionFilterPropertyDataDefinition requirementSubstitutionFilterPropertyDataDefinition =
- new RequirementSubstitutionFilterPropertyDataDefinition();
- requirementSubstitutionFilterPropertyDataDefinition.setName(filterPropsMap.getKey());
- requirementSubstitutionFilterPropertyDataDefinition.setConstraints(
- getSubstitutionFilterConstraints(filterPropsMap.getKey(), mapValue));
- propertyList.add(requirementSubstitutionFilterPropertyDataDefinition);
+ for (Map.Entry<String, List<Map<String, Object>>> propertyFilterEntry : filterProps.entrySet()) {
+ final String propertyName = propertyFilterEntry.getKey();
+ for (Map<String, Object> filterValueMap : propertyFilterEntry.getValue()) {
+ final var substitutionFilterPropertyDataDefinition = new SubstitutionFilterPropertyDataDefinition();
+ substitutionFilterPropertyDataDefinition.setName(propertyName);
+ substitutionFilterPropertyDataDefinition.setConstraints(createSubstitutionFilterConstraints(propertyName, filterValueMap));
+ propertyList.add(substitutionFilterPropertyDataDefinition);
}
}
}
return propertyList;
}
- private List<String> getSubstitutionFilterConstraints(String name, Map<String, Object> value) {
- List<String> constraints = new ArrayList<>();
- for (Map.Entry<String, Object> valueMap : value.entrySet()) {
- constraints.add(name + ": {" + valueMap.getKey() + ": " + valueMap.getValue() + "}");
+ private List<PropertyFilterConstraintDataDefinition> createSubstitutionFilterConstraints(final String name, final Map<String, Object> value) {
+ final List<PropertyFilterConstraintDataDefinition> constraints = new ArrayList<>();
+ for (final Map.Entry<String, Object> valueEntry : value.entrySet()) {
+ final var propertyFilterConstraint = new PropertyFilterConstraintDataDefinition();
+ propertyFilterConstraint.setPropertyName(name);
+ propertyFilterConstraint.setOperator(ConstraintType.findByType(valueEntry.getKey()).orElse(null));
+ propertyFilterConstraint.setTargetType(PropertyFilterTargetType.PROPERTY);
+ final Optional<ToscaFunction> toscaFunction = PropertyFilterConstraintDataDefinitionHelper
+ .createToscaFunctionFromLegacyConstraintValue(valueEntry.getValue());
+ if (toscaFunction.isPresent()) {
+ final ToscaFunction toscaFunction1 = toscaFunction.get();
+ propertyFilterConstraint.setValue(toscaFunction1);
+ propertyFilterConstraint.setValueType(
+ PropertyFilterConstraintDataDefinitionHelper.convertFromToscaFunctionType(toscaFunction1.getType()).orElse(null)
+ );
+ } else {
+ propertyFilterConstraint.setValue(valueEntry.getValue());
+ propertyFilterConstraint.setValueType(FilterValueType.STATIC);
+ }
+ constraints.add(propertyFilterConstraint);
}
+
return constraints;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java
index 65b5794687..ff65d84416 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java
@@ -21,9 +21,7 @@ package org.openecomp.sdc.be.components.impl;
import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR;
import fj.data.Either;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -31,21 +29,19 @@ import java.util.Optional;
import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.utils.CINodeFilterUtils;
-import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
import org.openecomp.sdc.be.components.validation.NodeFilterValidator;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
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.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeFilterOperation;
@@ -55,6 +51,7 @@ import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
+import org.openecomp.sdc.be.ui.mapper.FilterConstraintMapper;
import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.common.log.wrappers.Logger;
@@ -85,8 +82,8 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
final boolean shouldLock, final ComponentTypeEnum componentTypeEnum)
throws BusinessLogicException {
final Component component = getComponent(componentId);
- final Optional<ComponentInstance> componentInstance = getComponentInstance(componentInstanceId, component);
- Optional<CINodeFilterDataDefinition> filterDataDefinition = getCiNodeFilterDataDefinition(componentInstance);
+ Optional<CINodeFilterDataDefinition> filterDataDefinition =
+ component.getComponentInstanceById(componentInstanceId).map(ComponentInstance::getNodeFilter);
if (filterDataDefinition.isPresent()) {
return filterDataDefinition;
}
@@ -123,8 +120,8 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
public Optional<String> deleteNodeFilterIfExists(final String componentId, final String componentInstanceId, final boolean shouldLock,
final ComponentTypeEnum componentTypeEnum) throws BusinessLogicException {
final Component component = getComponent(componentId);
- final Optional<CINodeFilterDataDefinition> nodeFilterDataDefinition = getCiNodeFilterDataDefinition(componentInstanceId, component);
- if (!nodeFilterDataDefinition.isPresent()) {
+ final Optional<CINodeFilterDataDefinition> nodeFilterDataDefinition = getComponentInstanceNodeFilter(componentInstanceId, component);
+ if (nodeFilterDataDefinition.isEmpty()) {
return Optional.ofNullable(componentInstanceId);
}
final Either<String, StorageOperationStatus> result;
@@ -156,43 +153,29 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
return Optional.ofNullable(result.left().value());
}
- private String getComponentInstancePropertyType(Component component, String componentInstanceId, String propertyName) {
- List<ComponentInstanceProperty> componentInstanceProperties = component.getComponentInstancesProperties().get(componentInstanceId);
- if (!componentInstanceProperties.isEmpty()) {
- for (ComponentInstanceProperty componentInstanceProperty : componentInstanceProperties) {
- if (componentInstanceProperty.getName().equals(propertyName)) {
- return componentInstanceProperty.getType();
- }
- }
- }
- return null;
- }
-
public Optional<CINodeFilterDataDefinition> addNodeFilter(final String componentId, final String componentInstanceId,
- final NodeFilterConstraintAction action, final String propertyName,
- final String constraint, final boolean shouldLock,
+ final FilterConstraintDto filterConstraint, final boolean shouldLock,
final ComponentTypeEnum componentTypeEnum,
- final NodeFilterConstraintType nodeFilterConstraintType, final String capabilityName)
- throws BusinessLogicException {
+ final NodeFilterConstraintType nodeFilterConstraintType,
+ final String capabilityName) throws BusinessLogicException {
final Component component = getComponent(componentId);
- CINodeFilterDataDefinition nodeFilterDataDefinition = validateAndReturnNodeFilterDefinition(componentInstanceId, action, constraint,
- component, nodeFilterConstraintType, capabilityName);
+ validateNodeFilter(component, componentInstanceId, filterConstraint);
+ CINodeFilterDataDefinition nodeFilterDataDefinition = getComponentInstanceNodeFilterOrThrow(componentInstanceId, component);
boolean wasLocked = false;
try {
if (shouldLock) {
lockComponent(component.getUniqueId(), component, "Add Node Filter on Component");
wasLocked = true;
}
- final RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition();
- requirementNodeFilterPropertyDataDefinition.setName(propertyName);
- requirementNodeFilterPropertyDataDefinition.setConstraints(Collections.singletonList(constraint));
- requirementNodeFilterPropertyDataDefinition.setType(getComponentInstancePropertyType(component, componentInstanceId, propertyName));
- final Either<CINodeFilterDataDefinition, StorageOperationStatus> result = addNewNodeFilter(componentId, componentInstanceId,
- nodeFilterConstraintType, nodeFilterDataDefinition, requirementNodeFilterPropertyDataDefinition, capabilityName);
+ final PropertyFilterDataDefinition filterPropertyDataDefinition = new PropertyFilterDataDefinition();
+ filterPropertyDataDefinition.setName(filterConstraint.getPropertyName());
+ filterPropertyDataDefinition.setConstraints(List.of(new FilterConstraintMapper().mapTo(filterConstraint)));
+ final Either<CINodeFilterDataDefinition, StorageOperationStatus> result = addNodeFilter(componentId, componentInstanceId,
+ nodeFilterConstraintType, nodeFilterDataDefinition, filterPropertyDataDefinition, capabilityName);
if (result.isRight()) {
- janusGraphDao.rollback();
- throw new BusinessLogicException(componentsUtils
- .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(result.right().value()), component.getSystemName()));
+ throw new BusinessLogicException(componentsUtils.getResponseFormatByResource(
+ componentsUtils.convertFromStorageResponse(result.right().value()), component.getSystemName()
+ ));
} else {
nodeFilterDataDefinition = result.left().value();
}
@@ -201,6 +184,9 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
} catch (final Exception e) {
janusGraphDao.rollback();
LOGGER.error(BUSINESS_PROCESS_ERROR, "Exception occurred during add component node filter property values: {}", e.getMessage(), e);
+ if (e instanceof BusinessLogicException) {
+ throw e;
+ }
throw new BusinessLogicException(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
} finally {
if (wasLocked) {
@@ -210,14 +196,13 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
return Optional.ofNullable(nodeFilterDataDefinition);
}
- public Optional<CINodeFilterDataDefinition> deleteNodeFilter(final String componentId, final String componentInstanceId,
- final NodeFilterConstraintAction action, final String constraint, final int position,
+ public Optional<CINodeFilterDataDefinition> deleteNodeFilter(final String componentId, final String componentInstanceId, final int position,
final boolean shouldLock, final ComponentTypeEnum componentTypeEnum,
final NodeFilterConstraintType nodeFilterConstraintType)
throws BusinessLogicException {
+
final Component component = getComponent(componentId);
- CINodeFilterDataDefinition nodeFilterDataDefinition = validateAndReturnNodeFilterDefinition(componentInstanceId, action, constraint,
- component, nodeFilterConstraintType, "");
+ CINodeFilterDataDefinition nodeFilterDataDefinition = getComponentInstanceNodeFilterOrThrow(componentInstanceId, component);
boolean wasLocked = false;
try {
if (shouldLock) {
@@ -247,23 +232,23 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
return Optional.ofNullable(nodeFilterDataDefinition);
}
- private Either<CINodeFilterDataDefinition, StorageOperationStatus> addNewNodeFilter(final String componentId, final String componentInstanceId,
- final NodeFilterConstraintType nodeFilterConstraintType,
- final CINodeFilterDataDefinition nodeFilterDataDefinition,
- final RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition,
- final String capabilityName) {
+ private Either<CINodeFilterDataDefinition, StorageOperationStatus> addNodeFilter(final String componentId, final String componentInstanceId,
+ final NodeFilterConstraintType nodeFilterConstraintType,
+ final CINodeFilterDataDefinition nodeFilterDataDefinition,
+ final PropertyFilterDataDefinition propertyFilterDataDefinition,
+ final String capabilityName) {
if (NodeFilterConstraintType.PROPERTIES.equals(nodeFilterConstraintType)) {
return nodeFilterOperation
- .addNewProperty(componentId, componentInstanceId, nodeFilterDataDefinition, requirementNodeFilterPropertyDataDefinition);
+ .addPropertyFilter(componentId, componentInstanceId, nodeFilterDataDefinition, propertyFilterDataDefinition);
}
final RequirementNodeFilterCapabilityDataDefinition requirementNodeFilterCapabilityDataDefinition = new RequirementNodeFilterCapabilityDataDefinition();
requirementNodeFilterCapabilityDataDefinition.setName(capabilityName);
- final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> propertyDataDefinitionListDataDefinition = new ListDataDefinition<>();
+ final ListDataDefinition<PropertyFilterDataDefinition> propertyDataDefinitionListDataDefinition = new ListDataDefinition<>();
propertyDataDefinitionListDataDefinition.getListToscaDataDefinition()
- .addAll(Collections.singleton(requirementNodeFilterPropertyDataDefinition));
+ .add(propertyFilterDataDefinition);
requirementNodeFilterCapabilityDataDefinition.setProperties(propertyDataDefinitionListDataDefinition);
return nodeFilterOperation
- .addNewCapabilities(componentId, componentInstanceId, nodeFilterDataDefinition, requirementNodeFilterCapabilityDataDefinition);
+ .addCapabilities(componentId, componentInstanceId, nodeFilterDataDefinition, requirementNodeFilterCapabilityDataDefinition);
}
private void unlockComponent(final String componentUniqueId, final ComponentTypeEnum componentType) {
@@ -280,64 +265,42 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
return component.getComponentInstanceById(componentInstanceId);
}
- private Optional<CINodeFilterDataDefinition> getCiNodeFilterDataDefinition(final Optional<ComponentInstance> componentInstance) {
- if (componentInstance.isPresent()) {
- return Optional.ofNullable(componentInstance.get().getNodeFilter());
- }
- return Optional.empty();
- }
-
- private Optional<CINodeFilterDataDefinition> getCiNodeFilterDataDefinition(final String componentInstanceId, final Component component)
+ private Optional<CINodeFilterDataDefinition> getComponentInstanceNodeFilter(final String componentInstanceId, final Component component)
throws BusinessLogicException {
final Either<Boolean, ResponseFormat> response = nodeFilterValidator.validateComponentInstanceExist(component, componentInstanceId);
if (response.isRight()) {
throw new BusinessLogicException(
componentsUtils.getResponseFormat(ActionStatus.NODE_FILTER_NOT_FOUND, response.right().value().getFormattedMessage()));
}
- final Optional<ComponentInstance> componentInstance = getComponentInstance(componentInstanceId, component);
- if (componentInstance.isPresent()) {
- return Optional.ofNullable(componentInstance.get().getNodeFilter());
- }
- return Optional.empty();
+ return getComponentInstance(componentInstanceId, component).map(ComponentInstance::getNodeFilter);
}
- private CINodeFilterDataDefinition validateAndReturnNodeFilterDefinition(final String componentInstanceId,
- final NodeFilterConstraintAction action, final String constraint,
- final Component component,
- final NodeFilterConstraintType nodeFilterConstraintType,
- final String capabilityName)
- throws BusinessLogicException {
- validateNodeFilter(component, componentInstanceId, action, constraint, nodeFilterConstraintType, capabilityName);
- final Optional<CINodeFilterDataDefinition> cINodeFilterDataDefinition = getCiNodeFilterDataDefinition(componentInstanceId, component);
- if (!cINodeFilterDataDefinition.isPresent()) {
- throw new BusinessLogicException(componentsUtils.getResponseFormat(ActionStatus.NODE_FILTER_NOT_FOUND));
- }
- return cINodeFilterDataDefinition.get();
+ private CINodeFilterDataDefinition getComponentInstanceNodeFilterOrThrow(final String componentInstanceId,
+ final Component component) throws BusinessLogicException {
+ return getComponentInstanceNodeFilter(componentInstanceId, component).orElseThrow(
+ () -> new BusinessLogicException(componentsUtils.getResponseFormat(ActionStatus.NODE_FILTER_NOT_FOUND)));
}
- private void validateNodeFilter(final Component component, final String componentInstanceId, final NodeFilterConstraintAction action,
- final String constraint, final NodeFilterConstraintType nodeFilterConstraintType, final String capabilityName) throws BusinessLogicException {
- final Either<Boolean, ResponseFormat> response = nodeFilterValidator
- .validateFilter(component, componentInstanceId, Collections.singletonList(constraint), action, nodeFilterConstraintType, capabilityName);
+ private void validateNodeFilter(final Component component, final String componentInstanceId,
+ final FilterConstraintDto constraint) throws BusinessLogicException {
+ final Either<Boolean, ResponseFormat> response = nodeFilterValidator.validateFilter(component, componentInstanceId, constraint);
if (response.isRight()) {
- throw new BusinessLogicException(
- componentsUtils.getResponseFormat(ActionStatus.NODE_FILTER_NOT_FOUND, response.right().value().getFormattedMessage()));
+ throw new BusinessLogicException(response.right().value());
}
}
public Optional<CINodeFilterDataDefinition> updateNodeFilter(final String componentId, final String componentInstanceId,
final UIConstraint uiConstraint, final ComponentTypeEnum componentTypeEnum,
- final NodeFilterConstraintType nodeFilterConstraintType, final int index)
- throws BusinessLogicException {
- final Optional<CINodeFilterDataDefinition> deleteActionResponse = deleteNodeFilter(componentId, componentInstanceId,
- NodeFilterConstraintAction.DELETE, null, index, true, componentTypeEnum, nodeFilterConstraintType);
- if (!deleteActionResponse.isPresent()) {
+ final NodeFilterConstraintType nodeFilterConstraintType,
+ final int index) throws BusinessLogicException {
+ final Optional<CINodeFilterDataDefinition> deleteActionResponse =
+ deleteNodeFilter(componentId, componentInstanceId, index, true, componentTypeEnum, nodeFilterConstraintType);
+ if (deleteActionResponse.isEmpty()) {
throw new BusinessLogicException(
componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR, "Failed to delete node filter capabilities"));
}
- return addNodeFilter(componentId.toLowerCase(), componentInstanceId, NodeFilterConstraintAction.ADD, uiConstraint.getServicePropertyName(),
- new ConstraintConvertor().convert(uiConstraint), true, componentTypeEnum, nodeFilterConstraintType,
- uiConstraint.getCapabilityName());
+ return addNodeFilter(componentId.toLowerCase(), componentInstanceId, new FilterConstraintMapper().mapFrom(uiConstraint), true,
+ componentTypeEnum, nodeFilterConstraintType, uiConstraint.getCapabilityName());
}
public StorageOperationStatus associateNodeFilterToComponentInstance(final String componentId,
@@ -355,22 +318,12 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
}
//associate node filter properties to component instance
- List<RequirementNodeFilterPropertyDataDefinition> properties = ciNodeFilterDataDefinition.getProperties()
+ List<PropertyFilterDataDefinition> properties = ciNodeFilterDataDefinition.getProperties()
.getListToscaDataDefinition();
if (!properties.isEmpty()) {
- final Component component;
- try {
- component = getComponent(componentId);
- } catch (BusinessLogicException e) {
- throw new ComponentException(e.getResponseFormat());
- }
properties.forEach(property -> {
- String propertyType = getComponentInstancePropertyType(component, componentInstanceId, property.getName());
- RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition =
- getRequirementNodeFilterPropertyDataDefinition(property);
- requirementNodeFilterPropertyDataDefinition.setType(propertyType);
Either<CINodeFilterDataDefinition, StorageOperationStatus> nodeFilterProperty = nodeFilterOperation
- .addNewProperty(componentId, componentInstanceId, nodeFilter.left().value(), requirementNodeFilterPropertyDataDefinition);
+ .addPropertyFilter(componentId, componentInstanceId, nodeFilter.left().value(), property);
if (nodeFilterProperty.isRight()) {
throw new ComponentException(
componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nodeFilterProperty.right().value()),
@@ -389,7 +342,7 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
requirementNodeFilterCapabilityDataDefinition.setName(capability.getName());
requirementNodeFilterCapabilityDataDefinition.setProperties(getProperties(capability.getProperties()));
Either<CINodeFilterDataDefinition, StorageOperationStatus> nodeFilterCapability = nodeFilterOperation
- .addNewCapabilities(componentId, componentInstanceId, nodeFilter.left().value(),
+ .addCapabilities(componentId, componentInstanceId, nodeFilter.left().value(),
requirementNodeFilterCapabilityDataDefinition);
if (nodeFilterCapability.isRight()) {
throw new ComponentException(
@@ -402,27 +355,10 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
return StorageOperationStatus.OK;
}
- private List<String> getNodeFilterConstraints(String name, List<String> value) {
- List<String> constraints = new ArrayList<>();
- constraints.add(name + ":\n " + value.get(0));
- return constraints;
- }
-
- private ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> getProperties(ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> properties) {
- ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> updatedProperties = new ListDataDefinition<>();
- properties.getListToscaDataDefinition().forEach(property -> {
- RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition = getRequirementNodeFilterPropertyDataDefinition(
- property);
- updatedProperties.add(requirementNodeFilterPropertyDataDefinition);
- });
+ private ListDataDefinition<PropertyFilterDataDefinition> getProperties(ListDataDefinition<PropertyFilterDataDefinition> properties) {
+ ListDataDefinition<PropertyFilterDataDefinition> updatedProperties = new ListDataDefinition<>();
+ properties.getListToscaDataDefinition().forEach(updatedProperties::add);
return updatedProperties;
}
- private RequirementNodeFilterPropertyDataDefinition getRequirementNodeFilterPropertyDataDefinition(
- RequirementNodeFilterPropertyDataDefinition property) {
- RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition();
- requirementNodeFilterPropertyDataDefinition.setName(property.getName());
- requirementNodeFilterPropertyDataDefinition.setConstraints(getNodeFilterConstraints(property.getName(), property.getConstraints()));
- return requirementNodeFilterPropertyDataDefinition;
- }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java
index 74b353ec85..2fed0e2483 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java
@@ -23,20 +23,19 @@ import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_P
import fj.data.Either;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
-import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
import org.openecomp.sdc.be.components.validation.NodeFilterValidator;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.SubstitutionFilterOperation;
@@ -46,6 +45,7 @@ import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
+import org.openecomp.sdc.be.ui.mapper.FilterConstraintMapper;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
@@ -111,12 +111,11 @@ public class ComponentSubstitutionFilterBusinessLogic extends BaseBusinessLogic
return substitutionFilterDataDefinition;
}
- public Optional<SubstitutionFilterDataDefinition> addSubstitutionFilter(final String componentId, final String propertyName,
- final String constraint, final boolean shouldLock,
+ public Optional<SubstitutionFilterDataDefinition> addSubstitutionFilter(final String componentId,
+ final FilterConstraintDto filterConstraint, final boolean shouldLock,
final ComponentTypeEnum componentTypeEnum) throws BusinessLogicException {
final Component component = getComponent(componentId);
- final Either<Boolean, ResponseFormat> response = nodeFilterValidator
- .validateComponentFilter(component, Collections.singletonList(constraint), NodeFilterConstraintAction.ADD);
+ final Either<Boolean, ResponseFormat> response = nodeFilterValidator.validateSubstitutionFilter(component, filterConstraint);
if (response.isRight()) {
throw new BusinessLogicException(
componentsUtils.getResponseFormat(ActionStatus.SUBSTITUTION_FILTER_NOT_FOUND, response.right().value().getFormattedMessage()));
@@ -127,9 +126,9 @@ public class ComponentSubstitutionFilterBusinessLogic extends BaseBusinessLogic
lockComponent(component.getUniqueId(), component, "Add Substitution Filter on Component");
wasLocked = true;
}
- final RequirementSubstitutionFilterPropertyDataDefinition newProperty = new RequirementSubstitutionFilterPropertyDataDefinition();
- newProperty.setName(propertyName);
- newProperty.setConstraints(Collections.singletonList(constraint));
+ final SubstitutionFilterPropertyDataDefinition newProperty = new SubstitutionFilterPropertyDataDefinition();
+ newProperty.setName(filterConstraint.getPropertyName());
+ newProperty.setConstraints(List.of(new FilterConstraintMapper().mapTo(filterConstraint)));
final Either<SubstitutionFilterDataDefinition, StorageOperationStatus> resultEither = substitutionFilterOperation
.addPropertyFilter(componentId, component.getSubstitutionFilter(), newProperty);
if (resultEither.isRight()) {
@@ -153,12 +152,11 @@ public class ComponentSubstitutionFilterBusinessLogic extends BaseBusinessLogic
}
}
- public Optional<SubstitutionFilterDataDefinition> updateSubstitutionFilter(final String componentId, final List<String> constraints,
- final boolean shouldLock, final ComponentTypeEnum componentTypeEnum)
- throws BusinessLogicException {
+ public Optional<SubstitutionFilterDataDefinition> updateSubstitutionFilter(final String componentId, final List<FilterConstraintDto> constraints,
+ final boolean shouldLock,
+ final ComponentTypeEnum componentTypeEnum) throws BusinessLogicException {
final Component component = getComponent(componentId);
- final Either<Boolean, ResponseFormat> response = nodeFilterValidator
- .validateComponentFilter(component, constraints, NodeFilterConstraintAction.UPDATE);
+ final Either<Boolean, ResponseFormat> response = nodeFilterValidator.validateSubstitutionFilter(component, constraints);
if (response.isRight()) {
throw new BusinessLogicException(
componentsUtils.getResponseFormat(ActionStatus.SUBSTITUTION_FILTER_NOT_FOUND, response.right().value().getFormattedMessage()));
@@ -173,10 +171,10 @@ public class ComponentSubstitutionFilterBusinessLogic extends BaseBusinessLogic
lockComponent(component.getUniqueId(), component, "Update Substitution Filter on Component");
wasLocked = true;
}
- final List<RequirementSubstitutionFilterPropertyDataDefinition> properties = constraints.stream()
- .map(this::getRequirementSubstitutionFilterPropertyDataDefinition).collect(Collectors.toList());
+ final List<SubstitutionFilterPropertyDataDefinition> properties = constraints.stream()
+ .map(this::buildSubstitutionFilterPropertyDataDefinition).collect(Collectors.toList());
final Either<SubstitutionFilterDataDefinition, StorageOperationStatus> result = substitutionFilterOperation
- .updateProperties(componentId, substitutionFilterDataDefinition, properties);
+ .updatePropertyFilters(componentId, substitutionFilterDataDefinition, properties);
if (result.isRight()) {
janusGraphDao.rollback();
throw new BusinessLogicException(componentsUtils
@@ -199,6 +197,51 @@ public class ComponentSubstitutionFilterBusinessLogic extends BaseBusinessLogic
return Optional.ofNullable(substitutionFilterDataDefinition);
}
+ public Optional<SubstitutionFilterDataDefinition> updateSubstitutionFilter(final String componentId, final FilterConstraintDto filterConstraint,
+ final int index,
+ final boolean shouldLock) throws BusinessLogicException {
+ final Component component = getComponent(componentId);
+ final Either<Boolean, ResponseFormat> validationResponse = nodeFilterValidator.validateSubstitutionFilter(component, filterConstraint);
+ if (validationResponse.isRight()) {
+ throw new BusinessLogicException(validationResponse.right().value());
+ }
+ final SubstitutionFilterDataDefinition substitutionFilterDataDefinition = component.getSubstitutionFilter();
+ if (substitutionFilterDataDefinition == null) {
+ throw new BusinessLogicException(componentsUtils.getResponseFormat(SUBSTITUTION_FILTER_NOT_FOUND, component.getName()));
+ }
+ boolean wasLocked = false;
+ try {
+ if (shouldLock) {
+ lockComponent(component.getUniqueId(), component, "Update Substitution Filter on Component");
+ wasLocked = true;
+ }
+ final SubstitutionFilterPropertyDataDefinition substitutionFilterProperty =
+ buildSubstitutionFilterPropertyDataDefinition(filterConstraint);
+ final Either<SubstitutionFilterDataDefinition, StorageOperationStatus> result =
+ substitutionFilterOperation.updatePropertyFilter(componentId, substitutionFilterDataDefinition, substitutionFilterProperty, index);
+ if (result.isRight()) {
+ janusGraphDao.rollback();
+ throw new BusinessLogicException(
+ componentsUtils.getResponseFormatByResource(
+ componentsUtils.convertFromStorageResponse(result.right().value()), component.getSystemName()
+ )
+ );
+ }
+ janusGraphDao.commit();
+ LOGGER.debug("Substitution filter successfully updated in component {} . ", component.getSystemName());
+ return Optional.ofNullable(result.left().value());
+ } catch (final Exception e) {
+ janusGraphDao.rollback();
+ LOGGER.error(BUSINESS_PROCESS_ERROR, this.getClass().getName(),
+ "Exception occurred during update component substitution filter property values: {}", e);
+ throw e;
+ } finally {
+ if (wasLocked) {
+ unlockComponent(component.getUniqueId(), component.getComponentType());
+ }
+ }
+ }
+
public Optional<SubstitutionFilterDataDefinition> deleteSubstitutionFilter(final String componentId, final int position, final boolean shouldLock,
final ComponentTypeEnum componentTypeEnum)
throws BusinessLogicException {
@@ -244,20 +287,21 @@ public class ComponentSubstitutionFilterBusinessLogic extends BaseBusinessLogic
return user;
}
- private RequirementSubstitutionFilterPropertyDataDefinition getRequirementSubstitutionFilterPropertyDataDefinition(final String constraint) {
- final RequirementSubstitutionFilterPropertyDataDefinition requirementSubstitutionFilterPropertyDataDefinition = new RequirementSubstitutionFilterPropertyDataDefinition();
- requirementSubstitutionFilterPropertyDataDefinition.setConstraints(Arrays.asList(constraint));
- return requirementSubstitutionFilterPropertyDataDefinition;
+ private SubstitutionFilterPropertyDataDefinition buildSubstitutionFilterPropertyDataDefinition(final FilterConstraintDto filterConstraint) {
+ final var substitutionFilterProperty = new SubstitutionFilterPropertyDataDefinition();
+ substitutionFilterProperty.setName(filterConstraint.getPropertyName());
+ substitutionFilterProperty.setConstraints(List.of(new FilterConstraintMapper().mapTo(filterConstraint)));
+ return substitutionFilterProperty;
}
public void addSubstitutionFilterInGraph(String componentId,
- ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> substitutionFilterProperties)
+ ListDataDefinition<SubstitutionFilterPropertyDataDefinition> substitutionFilterProperties)
throws BusinessLogicException {
Either<SubstitutionFilterDataDefinition, StorageOperationStatus> updateSubstitutionFilter;
Optional<SubstitutionFilterDataDefinition> substitutionFilter = createSubstitutionFilterIfNotExist(componentId, true,
ComponentTypeEnum.SERVICE);
if (substitutionFilter.isPresent()) {
- for (RequirementSubstitutionFilterPropertyDataDefinition filter : substitutionFilterProperties.getListToscaDataDefinition()) {
+ for (SubstitutionFilterPropertyDataDefinition filter : substitutionFilterProperties.getListToscaDataDefinition()) {
updateSubstitutionFilter = substitutionFilterOperation.addPropertyFilter(componentId, substitutionFilter.get(), filter);
if (updateSubstitutionFilter.isRight()) {
throw new BusinessLogicException(componentsUtils
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
index b4f6ee3950..8ad86b3510 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
@@ -63,7 +63,7 @@ import org.openecomp.sdc.be.model.heat.HeatParameterType;
import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
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.ValidValuesConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException;
import org.openecomp.sdc.be.utils.TypeUtils;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/NodeFilterUploadCreator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/NodeFilterUploadCreator.java
index 9d72eeca87..f34091de0f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/NodeFilterUploadCreator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/NodeFilterUploadCreator.java
@@ -49,22 +49,26 @@ public class NodeFilterUploadCreator {
return uploadNodeFilterInfo;
}
- private List<UploadNodeFilterPropertyInfo> createNodeFilterProperties(Object o) {
- if (!(o instanceof List)) {
+ private List<UploadNodeFilterPropertyInfo> createNodeFilterProperties(Object propertyNodeFilterYamlObject) {
+ if (!(propertyNodeFilterYamlObject instanceof List)) {
return null;
}
List<UploadNodeFilterPropertyInfo> retVal = new ArrayList<>();
- List<Map<String, Object>> propertiesList = (List<Map<String, Object>>) o;
+ List<Map<String, Object>> propertiesList = (List<Map<String, Object>>) propertyNodeFilterYamlObject;
for (Map<String, Object> map : propertiesList) {
final Map.Entry<String, Object> entry = map.entrySet().iterator().next();
- final Object value = entry.getValue();
- if (value instanceof Map) {
- List<String> valueList = new ArrayList<>();
- valueList.add(valueToProperty(entry.getValue()));
- retVal.add(new UploadNodeFilterPropertyInfo(entry.getKey(), valueList));
- } else if (value instanceof List) {
- List<String> propertiesVals = (List<String>) ((List) value).stream().map(this::valueToProperty).collect(Collectors.toList());
- retVal.add(new UploadNodeFilterPropertyInfo(entry.getKey(), propertiesVals));
+ final Object propertyConstraintClauses = entry.getValue();
+ if (propertyConstraintClauses instanceof Map) {
+ final List<String> propertyFilterConstraintList = new ArrayList<>();
+ propertyFilterConstraintList.add(valueToProperty(map));
+ retVal.add(new UploadNodeFilterPropertyInfo(entry.getKey(), propertyFilterConstraintList));
+ } else if (propertyConstraintClauses instanceof List) {
+ final List<String> propertyFilterConstraintList = ((List<Object>) propertyConstraintClauses).stream()
+ .map(propertyConstraintClause -> Map.of(entry.getKey(), propertyConstraintClause))
+ .map(this::valueToProperty)
+ .collect(Collectors.toList());
+
+ retVal.add(new UploadNodeFilterPropertyInfo(entry.getKey(), propertyFilterConstraintList));
}
}
return retVal;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
index ab43b4329e..8c46285240 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
@@ -77,7 +77,7 @@ import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
@@ -448,7 +448,7 @@ public class ServiceImportBusinessLogic {
Map<String, InputDefinition> inputs = parsedToscaYamlInfo.getInputs();
service = serviceImportParseLogic.createInputsOnService(service, inputs);
log.trace("************* Finished to add inputs from yaml {}", yamlName);
- ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> substitutionFilterProperties = parsedToscaYamlInfo.getSubstitutionFilterProperties();
+ ListDataDefinition<SubstitutionFilterPropertyDataDefinition> substitutionFilterProperties = parsedToscaYamlInfo.getSubstitutionFilterProperties();
service = serviceImportParseLogic.createSubstitutionFilterOnService(service, substitutionFilterProperties);
log.trace("************* Added Substitution filter from interface yaml {}", yamlName);
Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap = parsedToscaYamlInfo.getInstances();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
index 8cc5bd6fcb..b97645cc35 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
@@ -40,7 +40,7 @@ import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.CreatedFrom;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -1381,7 +1381,7 @@ public class ServiceImportParseLogic {
}
public Service createSubstitutionFilterOnService(Service service,
- ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> substitutionFilterProperties)
+ ListDataDefinition<SubstitutionFilterPropertyDataDefinition> substitutionFilterProperties)
throws BusinessLogicException {
if (substitutionFilterProperties == null || substitutionFilterProperties.isEmpty()) {
return service;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/FilterConstraintExceptionSupplier.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/FilterConstraintExceptionSupplier.java
new file mode 100644
index 0000000000..9f184aa2c2
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/FilterConstraintExceptionSupplier.java
@@ -0,0 +1,40 @@
+/*
+ * -
+ * ============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.components.impl.exceptions;
+
+import java.util.function.Supplier;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class FilterConstraintExceptionSupplier {
+
+ public static Supplier<ByActionStatusComponentException> filterConstraintNotProvided() {
+ return () -> new ByActionStatusComponentException(ActionStatus.FILTER_CONSTRAINT_MISSING);
+ }
+
+ public static Supplier<ByActionStatusComponentException> missingField(final String fieldName) {
+ return () -> new ByActionStatusComponentException(ActionStatus.FILTER_CONSTRAINT_MISSING_FIELD, fieldName);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtils.java
index a7dd5afc10..5ac9bcd2de 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtils.java
@@ -15,37 +15,39 @@
*/
package org.openecomp.sdc.be.components.impl.utils;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+import org.apache.commons.collections4.CollectionUtils;
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.model.UploadNodeFilterCapabilitiesInfo;
import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
import org.openecomp.sdc.be.model.UploadNodeFilterPropertyInfo;
-import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.be.utils.PropertyFilterConstraintDataDefinitionHelper;
public class CINodeFilterUtils {
- Logger log = Logger.getLogger(CINodeFilterUtils.class);
-
- public CINodeFilterDataDefinition getNodeFilterDataDefinition(UploadNodeFilterInfo uploadNodeFilterInfo, String uniqueId) {
- CINodeFilterDataDefinition nodeFilterDataDefinition = new CINodeFilterDataDefinition();
+ public CINodeFilterDataDefinition getNodeFilterDataDefinition(final UploadNodeFilterInfo uploadNodeFilterInfo, final String uniqueId) {
+ final var nodeFilterDataDefinition = new CINodeFilterDataDefinition();
nodeFilterDataDefinition.setName(uploadNodeFilterInfo.getName());
- List<RequirementNodeFilterPropertyDataDefinition> collect = uploadNodeFilterInfo.getProperties().stream().map(this::buildProperty)
+ final List<PropertyFilterDataDefinition> propertyFilterList = uploadNodeFilterInfo.getProperties().stream()
+ .map(this::buildOnePropertyFilterForEachConstraint)
+ .flatMap(Collection::stream)
.collect(Collectors.toList());
- ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> listDataDefinition = new ListDataDefinition<>();
- listDataDefinition.getListToscaDataDefinition().addAll(collect);
+ final ListDataDefinition<PropertyFilterDataDefinition> listDataDefinition = new ListDataDefinition<>();
+ listDataDefinition.getListToscaDataDefinition().addAll(propertyFilterList);
nodeFilterDataDefinition.setProperties(listDataDefinition);
- nodeFilterDataDefinition.setCapabilities(converCapabilties(uploadNodeFilterInfo.getCapabilities()));
+ nodeFilterDataDefinition.setCapabilities(convertCapabilities(uploadNodeFilterInfo.getCapabilities()));
nodeFilterDataDefinition.setID(uniqueId);
nodeFilterDataDefinition.setTosca_id(uploadNodeFilterInfo.getTosca_id());
return nodeFilterDataDefinition;
}
- private ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> converCapabilties(
+ private ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> convertCapabilities(
Map<String, UploadNodeFilterCapabilitiesInfo> capabilities) {
ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> listDataDefinition = new ListDataDefinition<>();
for (UploadNodeFilterCapabilitiesInfo capability : capabilities.values()) {
@@ -58,19 +60,43 @@ public class CINodeFilterUtils {
private RequirementNodeFilterCapabilityDataDefinition convertCapability(UploadNodeFilterCapabilitiesInfo capability) {
RequirementNodeFilterCapabilityDataDefinition retVal = new RequirementNodeFilterCapabilityDataDefinition();
retVal.setName(capability.getName());
- List<RequirementNodeFilterPropertyDataDefinition> props = capability.getProperties().stream().map(this::buildProperty)
+ List<PropertyFilterDataDefinition> props = capability.getProperties().stream().map(this::buildProperty)
.collect(Collectors.toList());
- ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> propsList = new ListDataDefinition<>();
+ ListDataDefinition<PropertyFilterDataDefinition> propsList = new ListDataDefinition<>();
propsList.getListToscaDataDefinition().addAll(props);
retVal.setProperties(propsList);
return retVal;
}
- private RequirementNodeFilterPropertyDataDefinition buildProperty(UploadNodeFilterPropertyInfo uploadNodeFilterPropertyInfo) {
- RequirementNodeFilterPropertyDataDefinition retVal = new RequirementNodeFilterPropertyDataDefinition();
- retVal.setName(uploadNodeFilterPropertyInfo.getName());
- List<String> propertyConstraints = uploadNodeFilterPropertyInfo.getValues();
- retVal.setConstraints(propertyConstraints);
- return retVal;
+ private PropertyFilterDataDefinition buildProperty(final UploadNodeFilterPropertyInfo uploadNodeFilterPropertyInfo) {
+ final var propertyFilter = new PropertyFilterDataDefinition();
+ propertyFilter.setName(uploadNodeFilterPropertyInfo.getName());
+ final List<String> propertyConstraints = uploadNodeFilterPropertyInfo.getValues();
+ if (CollectionUtils.isNotEmpty(propertyConstraints)) {
+ propertyFilter.setConstraints(
+ propertyConstraints.stream()
+ .map(PropertyFilterConstraintDataDefinitionHelper::convertLegacyConstraint)
+ .collect(Collectors.toList())
+ );
+ }
+ return propertyFilter;
+ }
+
+ private List<PropertyFilterDataDefinition> buildOnePropertyFilterForEachConstraint(final UploadNodeFilterPropertyInfo uploadNodeFilterProperty) {
+ final List<String> propertyConstraints = uploadNodeFilterProperty.getValues();
+ if (CollectionUtils.isNotEmpty(propertyConstraints)) {
+ return propertyConstraints.stream()
+ .map(PropertyFilterConstraintDataDefinitionHelper::convertLegacyConstraint)
+ .map(propertyFilterConstraint -> {
+ final var propertyFilter = new PropertyFilterDataDefinition();
+ propertyFilter.setName(uploadNodeFilterProperty.getName());
+ propertyFilter.setConstraints(List.of(propertyFilterConstraint));
+ return propertyFilter;
+ }).collect(Collectors.toList());
+ } else {
+ final var propertyFilter = new PropertyFilterDataDefinition();
+ propertyFilter.setName(uploadNodeFilterProperty.getName());
+ return List.of(propertyFilter);
+ }
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtils.java
index bd2187616c..4bd953fd3d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtils.java
@@ -28,7 +28,7 @@ import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentEx
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
-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.PropertyConstraintException;
/**
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/FilterConstraintValidatorImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/FilterConstraintValidatorImpl.java
new file mode 100644
index 0000000000..862b839326
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/FilterConstraintValidatorImpl.java
@@ -0,0 +1,64 @@
+/*
+ * -
+ * ============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.components.validation;
+
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.FilterConstraintExceptionSupplier;
+import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
+import org.openecomp.sdc.be.model.validation.FilterConstraintValidator;
+
+@org.springframework.stereotype.Component
+public class FilterConstraintValidatorImpl implements FilterConstraintValidator {
+
+ @Override
+ public void validate(final FilterConstraintDto filterConstraint) {
+ if (filterConstraint == null) {
+ throw FilterConstraintExceptionSupplier.filterConstraintNotProvided().get();
+ }
+
+ if (StringUtils.isBlank(filterConstraint.getPropertyName())) {
+ throw FilterConstraintExceptionSupplier.missingField("propertyName").get();
+ }
+
+ if (filterConstraint.getValueType() == null) {
+ throw FilterConstraintExceptionSupplier.missingField("valueType").get();
+ }
+
+ if (filterConstraint.getTargetType() == null) {
+ throw FilterConstraintExceptionSupplier.missingField("targetType").get();
+ }
+
+ if (filterConstraint.getTargetType() == PropertyFilterTargetType.CAPABILITY && StringUtils.isBlank(filterConstraint.getCapabilityName())) {
+ throw FilterConstraintExceptionSupplier.missingField("capabilityName").get();
+ }
+
+ if (filterConstraint.getValue() == null) {
+ throw FilterConstraintExceptionSupplier.missingField("value").get();
+ }
+
+ if (filterConstraint.getOperator() == null) {
+ throw FilterConstraintExceptionSupplier.missingField("operator").get();
+ }
+
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
index e62893a148..12b58ded4a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
@@ -19,33 +19,33 @@
*/
package org.openecomp.sdc.be.components.validation;
-import com.google.common.collect.ImmutableSet;
+import com.google.gson.Gson;
import fj.data.Either;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
-import java.util.Objects;
+import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
-import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
-import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
-import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
-import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.PropertySource;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.ToscaPropertyData;
+import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
-import org.openecomp.sdc.be.ui.model.UIConstraint;
+import org.openecomp.sdc.be.model.tosca.validators.DataTypeValidatorConverter;
+import org.openecomp.sdc.be.model.validation.FilterConstraintValidator;
import org.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,128 +54,192 @@ import org.springframework.beans.factory.annotation.Autowired;
@org.springframework.stereotype.Component("NodeFilterValidator")
public class NodeFilterValidator {
+ private static final Logger LOGGER = LoggerFactory.getLogger(NodeFilterValidator.class);
private static final String SOURCE = "Source";
- public static final Set<String> comparableTypes = ImmutableSet
+ private static final String TARGET = "Target";
+ private static final String INPUT_NOT_FOUND_LOG = "Input '{}' not found in parent component '{}', unique id '{}'";
+ private static final Set<String> TYPES_WITH_SCHEMA = Set.of(ToscaPropertyType.MAP.getType(), ToscaPropertyType.LIST.getType());
+ private static final Set<String> COMPARABLE_TYPES = Set
.of(ToscaPropertyType.STRING.getType(), ToscaPropertyType.INTEGER.getType(), ToscaPropertyType.FLOAT.getType());
- public static final Set<String> schemableTypes = ImmutableSet.of(ToscaPropertyType.MAP.getType(), ToscaPropertyType.LIST.getType());
- public static final Set<String> comparableConstraintsOperators = ImmutableSet
- .of(ConstraintConvertor.GREATER_THAN_OPERATOR, ConstraintConvertor.LESS_THAN_OPERATOR);
- protected final ToscaOperationFacade toscaOperationFacade;
- protected final ComponentsUtils componentsUtils;
- private static final Logger LOGGER = LoggerFactory.getLogger(NodeFilterValidator.class);
+ private final ComponentsUtils componentsUtils;
+ private final ApplicationDataTypeCache applicationDataTypeCache;
+ private final FilterConstraintValidator filterConstraintValidator;
@Autowired
- public NodeFilterValidator(final ToscaOperationFacade toscaOperationFacade, final ComponentsUtils componentsUtils) {
- this.toscaOperationFacade = toscaOperationFacade;
+ public NodeFilterValidator(final ComponentsUtils componentsUtils, final ApplicationDataTypeCache applicationDataTypeCache,
+ final FilterConstraintValidator filterConstraintValidator) {
this.componentsUtils = componentsUtils;
+ this.applicationDataTypeCache = applicationDataTypeCache;
+ this.filterConstraintValidator = filterConstraintValidator;
}
public Either<Boolean, ResponseFormat> validateComponentInstanceExist(final Component component, final String componentInstanceId) {
if (component == null || StringUtils.isEmpty(componentInstanceId)) {
- LOGGER.error("Input data cannot be empty");
- return getErrorResponse(ActionStatus.FILTER_NOT_FOUND);
+ LOGGER.error("Expecting a component and a component instance id, given was '{}' and '{}'", component, componentInstanceId);
+ final String componentName = component == null ? "?" : component.getName();
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, componentName, componentInstanceId));
}
if (CollectionUtils.isEmpty(component.getComponentInstances()) || component.getComponentInstances().stream()
.noneMatch(ci -> ci.getUniqueId().equals(componentInstanceId))) {
- LOGGER.error("Component Instance list is empty");
- return getErrorResponse(ActionStatus.FILTER_NOT_FOUND);
+ LOGGER.error("Component '{}' node instance list is empty or component instance '{}' not found",
+ component.getUniqueId(), componentInstanceId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND,
+ component.getName(), componentInstanceId));
}
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> getErrorResponse(ActionStatus actionStatus, String... variables) {
- ResponseFormat errorResponse = ResponseFormatManager.getInstance().getResponseFormat(actionStatus, variables);
- return Either.right(errorResponse);
- }
-
public Either<Boolean, ResponseFormat> validateFilter(final Component parentComponent, final String componentInstanceId,
- final List<String> uiConstraints, final NodeFilterConstraintAction action,
- final NodeFilterConstraintType nodeFilterConstraintType,
- final String capabilityName) {
- try {
- if (NodeFilterConstraintAction.ADD == action || NodeFilterConstraintAction.UPDATE == action) {
- for (final String uiConstraint : uiConstraints) {
- final UIConstraint constraint = new ConstraintConvertor().convert(uiConstraint);
- if (ConstraintConvertor.PROPERTY_CONSTRAINT.equals(constraint.getSourceType())) {
- final Either<Boolean, ResponseFormat> booleanResponseFormatEither = validatePropertyConstraint(parentComponent,
- componentInstanceId, constraint, capabilityName);
- if (booleanResponseFormatEither.isRight()) {
- return booleanResponseFormatEither;
- }
- }
- else if (ConstraintConvertor.SERVICE_INPUT_CONSTRAINT.equals(constraint.getSourceType())) {
- final Either<Boolean, ResponseFormat> booleanResponseFormatEither = validateInputConstraint(parentComponent,
- componentInstanceId, constraint);
- if (booleanResponseFormatEither.isRight()) {
- return booleanResponseFormatEither;
- }
- }
- else if (ConstraintConvertor.STATIC_CONSTRAINT.equals(constraint.getSourceType())) {
- Either<Boolean, ResponseFormat> booleanResponseFormatEither;
- if (NodeFilterConstraintType.PROPERTIES.equals(nodeFilterConstraintType)) {
- booleanResponseFormatEither = isComponentPropertyFilterValid(parentComponent, componentInstanceId, constraint);
- } else {
- booleanResponseFormatEither = isComponentCapabilityPropertyFilterValid(parentComponent, componentInstanceId, constraint);
- }
- if (booleanResponseFormatEither.isRight()) {
- return booleanResponseFormatEither;
- }
- }
- }
+ final List<FilterConstraintDto> filterConstraint) {
+ if (CollectionUtils.isEmpty(filterConstraint)) {
+ return Either.left(true);
+ }
+ for (final FilterConstraintDto filterConstraintDto : filterConstraint) {
+ final Either<Boolean, ResponseFormat> validationEither =
+ validateFilter(parentComponent, componentInstanceId, filterConstraintDto);
+ if (validationEither.isRight()) {
+ return validationEither;
}
- } catch (final Exception e) {
- LOGGER.debug("Provided constraint" + uiConstraints, e);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.CONSTRAINT_FORMAT_INCORRECT));
}
return Either.left(true);
}
-
- private Either<Boolean, ResponseFormat> isComponentCapabilityPropertyFilterValid(final Component parentComponent,
- final String componentInstanceId,
- final UIConstraint uiConstraint) {
- return validateStaticValueAndOperatorOfCapabilityProperties(parentComponent, componentInstanceId, uiConstraint);
+ public Either<Boolean, ResponseFormat> validateFilter(final Component parentComponent, final String componentInstanceId,
+ final FilterConstraintDto filterConstraint) {
+ validateFilterConstraint(filterConstraint);
+ switch (filterConstraint.getValueType()) {
+ case STATIC:
+ if (filterConstraint.isCapabilityPropertyFilter()) {
+ return validateStaticValueAndOperatorOfCapabilityProperties(parentComponent, componentInstanceId, filterConstraint);
+ } else {
+ return validateStaticValueAndOperator(parentComponent, componentInstanceId, filterConstraint);
+ }
+ case GET_PROPERTY:
+ return validatePropertyConstraint(parentComponent, componentInstanceId, filterConstraint, filterConstraint.getCapabilityName());
+ case GET_INPUT:
+ return validateInputConstraint(parentComponent, componentInstanceId, filterConstraint);
+ default:
+ return Either.left(true);
+ }
}
- private Either<Boolean, ResponseFormat> isComponentPropertyFilterValid(Component parentComponent, String componentInstanceId,
- UIConstraint constraint) {
- return validateStaticValueAndOperator(parentComponent, componentInstanceId, constraint);
+ private void validateFilterConstraint(final FilterConstraintDto filterConstraint) {
+ filterConstraintValidator.validate(filterConstraint);
}
private Either<Boolean, ResponseFormat> validatePropertyConstraint(final Component parentComponent, final String componentInstanceId,
- final UIConstraint uiConstraint, final String capabilityName) {
+ final FilterConstraintDto filterConstraint, final String capabilityName) {
String source = SOURCE;
- final Optional<ComponentInstance> optionalComponentInstance;
- final List<PropertyDefinition> propertyDefinitions = parentComponent.getProperties();
- final var SELF = "SELF";
- List<? extends PropertyDefinition> sourcePropertyDefinition =
- SELF.equalsIgnoreCase(uiConstraint.getSourceName()) && propertyDefinitions != null ? propertyDefinitions
- : Collections.emptyList();
- if (sourcePropertyDefinition.isEmpty() && !SELF.equalsIgnoreCase(uiConstraint.getSourceName())) {
- optionalComponentInstance = parentComponent.getComponentInstances().stream()
- .filter(componentInstance -> uiConstraint.getSourceName().equals(componentInstance.getName())).findFirst();
- if (optionalComponentInstance.isPresent()) {
- final List<ComponentInstanceProperty> componentInstanceProperties = parentComponent.getComponentInstancesProperties()
- .get(optionalComponentInstance.get().getUniqueId());
- sourcePropertyDefinition = componentInstanceProperties == null ? new ArrayList<>() : componentInstanceProperties;
- }
+ final ToscaGetFunctionDataDefinition toscaGetFunction = filterConstraint.getAsToscaGetFunction().orElse(null);
+ if (toscaGetFunction == null || !(filterConstraint.getValue() instanceof ToscaGetFunctionDataDefinition)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.TOSCA_FUNCTION_EXPECTED_ERROR));
}
- if (CollectionUtils.isNotEmpty(sourcePropertyDefinition)) {
- final Optional<? extends PropertyDefinition> sourceSelectedProperty = sourcePropertyDefinition.stream()
- .filter(property -> uiConstraint.getValue().equals(property.getName())).findFirst();
- Optional<? extends PropertyDefinition> targetComponentInstanceProperty = getProperty(parentComponent, componentInstanceId, capabilityName, uiConstraint.getServicePropertyName());
-
- source = !targetComponentInstanceProperty.isPresent() ? "Target" : SOURCE;
- if (sourceSelectedProperty.isPresent() && targetComponentInstanceProperty.isPresent()) {
- return validatePropertyData(uiConstraint, sourceSelectedProperty, targetComponentInstanceProperty);
+ final Optional<? extends ToscaPropertyData> sourceSelectedProperty = findPropertyFromGetFunction(parentComponent, toscaGetFunction);
+ if (sourceSelectedProperty.isPresent()) {
+ Optional<? extends PropertyDefinition> targetComponentInstanceProperty =
+ getInstanceProperties(parentComponent, componentInstanceId, capabilityName, filterConstraint.getPropertyName());
+
+ source = targetComponentInstanceProperty.isEmpty() ? TARGET : SOURCE;
+ if (targetComponentInstanceProperty.isPresent()) {
+ final ResponseFormat responseFormat = validatePropertyData(sourceSelectedProperty.get(), targetComponentInstanceProperty.get());
+ if (responseFormat != null) {
+ return Either.right(responseFormat);
+ }
+ return Either.left(true);
}
}
- final String missingProperty = source.equals(SOURCE) ? uiConstraint.getValue().toString() : uiConstraint.getServicePropertyName();
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.MAPPED_PROPERTY_NOT_FOUND, source, missingProperty));
+ final String missingProperty = SOURCE.equals(source) ? filterConstraint.getValue().toString() : filterConstraint.getPropertyName();
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.FILTER_PROPERTY_NOT_FOUND, source, missingProperty));
+ }
+
+ private Optional<? extends ToscaPropertyData> findPropertyFromGetFunction(final Component parentComponent,
+ final ToscaGetFunctionDataDefinition toscaGetFunction) {
+ List<? extends ToscaPropertyData> sourcePropertyDefinitions;
+ if (PropertySource.SELF == toscaGetFunction.getPropertySource()) {
+ sourcePropertyDefinitions = getSelfPropertyFromGetFunction(parentComponent, toscaGetFunction);
+ } else {
+ sourcePropertyDefinitions = getInstancePropertiesBasedOnGetFunctionSource(parentComponent, toscaGetFunction);
+ }
+ final List<String> propertyPath = toscaGetFunction.getPropertyPathFromSource();
+ final Optional<? extends ToscaPropertyData> sourceProperty = sourcePropertyDefinitions.stream()
+ .filter(propertyDefinition -> propertyDefinition.getName().equals(propertyPath.get(0))).findFirst();
+ if (sourceProperty.isEmpty() || propertyPath.size() == 1) {
+ return sourceProperty;
+ }
+ final Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypesEither =
+ applicationDataTypeCache.getAll(parentComponent.getModel());
+ if (allDataTypesEither.isRight()) {
+ return Optional.empty();
+ }
+ return findSubProperty(propertyPath.subList(1, propertyPath.size()), sourceProperty.get().getType(), allDataTypesEither.left().value());
+ }
+
+ private List<? extends ToscaPropertyData> getInstancePropertiesBasedOnGetFunctionSource(final Component parentComponent,
+ final ToscaGetFunctionDataDefinition toscaGetFunction) {
+ final ComponentInstance componentInstance = parentComponent.getComponentInstances().stream()
+ .filter(componentInstance1 -> componentInstance1.getName().equals(toscaGetFunction.getSourceName()))
+ .findFirst()
+ .orElse(null);
+ if (componentInstance == null) {
+ return List.of();
+ }
+ final List<? extends ToscaPropertyData> instanceProperties;
+ switch (toscaGetFunction.getFunctionType()) {
+ case GET_PROPERTY:
+ instanceProperties = parentComponent.getComponentInstancesProperties().get(componentInstance.getUniqueId());
+ break;
+ case GET_ATTRIBUTE:
+ instanceProperties = parentComponent.getComponentInstancesAttributes().get(componentInstance.getUniqueId());
+ break;
+ default:
+ instanceProperties = List.of();
+ }
+ if (instanceProperties == null) {
+ return List.of();
+ }
+ return instanceProperties;
+ }
+
+ private static List<? extends ToscaPropertyData> getSelfPropertyFromGetFunction(final Component component,
+ final ToscaGetFunctionDataDefinition toscaGetFunction) {
+ switch (toscaGetFunction.getFunctionType()) {
+ case GET_INPUT:
+ if (component.getInputs() != null) {
+ return component.getInputs();
+ }
+ break;
+ case GET_PROPERTY:
+ if (component.getProperties() != null) {
+ return component.getProperties();
+ }
+ break;
+ case GET_ATTRIBUTE:
+ if (component.getAttributes() != null) {
+ return component.getAttributes();
+ }
+ break;
+ }
+ return List.of();
}
-
- private Optional<ComponentInstanceProperty> getProperty(final Component parentComponent, final String componentInstanceId,
- final String capabilityName, final String propertyName) {
+ private Optional<PropertyDefinition> findSubProperty(final List<String> propertyPath, final String parentPropertyType,
+ final Map<String, DataTypeDefinition> modelDataTypes) {
+ final DataTypeDefinition dataTypeDefinition = modelDataTypes.get(parentPropertyType);
+ if (CollectionUtils.isEmpty(dataTypeDefinition.getProperties())) {
+ return Optional.empty();
+ }
+ final PropertyDefinition propertyDefinition = dataTypeDefinition.getProperties().stream()
+ .filter(propertyDefinition1 -> propertyDefinition1.getName().equals(propertyPath.get(0))).findFirst().orElse(null);
+ if (propertyDefinition == null) {
+ return Optional.empty();
+ }
+ if (propertyPath.size() == 1) {
+ return Optional.of(propertyDefinition);
+ }
+ return findSubProperty(propertyPath.subList(1, propertyPath.size()), propertyDefinition.getType(), modelDataTypes);
+ }
+
+ private Optional<ComponentInstanceProperty> getInstanceProperties(final Component parentComponent, final String componentInstanceId,
+ final String capabilityName, final String propertyName) {
if (StringUtils.isEmpty(capabilityName)) {
return parentComponent.getComponentInstancesProperties().get(componentInstanceId).stream()
.filter(property -> propertyName.equals(property.getName())).findFirst();
@@ -195,80 +259,109 @@ public class NodeFilterValidator {
}
private Either<Boolean, ResponseFormat> validateInputConstraint(final Component parentComponent, final String componentInstanceId,
- final UIConstraint uiConstraint) {
+ final FilterConstraintDto filterConstraint) {
final List<InputDefinition> sourceInputDefinition = parentComponent.getInputs();
- if (CollectionUtils.isNotEmpty(sourceInputDefinition)) {
- final Optional<? extends InputDefinition> sourceSelectedProperty = sourceInputDefinition.stream()
- .filter(input -> uiConstraint.getValue().equals(input.getName())).findFirst();
- final Optional<? extends PropertyDefinition> targetComponentInstanceProperty = parentComponent.getComponentInstancesProperties()
- .get(componentInstanceId).stream().filter(property -> uiConstraint.getServicePropertyName().equals(property.getName())).findFirst();
- if (sourceSelectedProperty.isPresent() && targetComponentInstanceProperty.isPresent()) {
- return validatePropertyData(uiConstraint, sourceSelectedProperty, targetComponentInstanceProperty);
+ if (CollectionUtils.isEmpty(sourceInputDefinition)) {
+ LOGGER.debug("Parent component '{}', unique id '{}', does not have inputs", parentComponent.getName(), parentComponent.getUniqueId());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_DOES_NOT_HAVE_INPUTS, parentComponent.getName()));
+ }
+ if (!(filterConstraint.getValue() instanceof ToscaGetFunctionDataDefinition)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.TOSCA_FUNCTION_EXPECTED_ERROR));
+ }
+ final ToscaGetFunctionDataDefinition getFunction = (ToscaGetFunctionDataDefinition) filterConstraint.getValue();
+ final List<String> propertyPathFromSource = getFunction.getPropertyPathFromSource();
+ Optional<? extends PropertyDefinition> sourceSelectedProperty =
+ sourceInputDefinition.stream().filter(input -> input.getName().equals(propertyPathFromSource.get(0))).findFirst();
+ if (sourceSelectedProperty.isEmpty()) {
+ LOGGER.debug(INPUT_NOT_FOUND_LOG,
+ propertyPathFromSource.get(0), parentComponent.getName(), parentComponent.getUniqueId());
+ return Either.right(
+ componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INPUT_NOT_FOUND, propertyPathFromSource.get(0), parentComponent.getName())
+ );
+ }
+ if (propertyPathFromSource.size() > 1) {
+ final Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypesEither =
+ applicationDataTypeCache.getAll(parentComponent.getModel());
+ if (allDataTypesEither.isRight()) {
+ LOGGER.error("Could not load data types for model {}", parentComponent.getModel());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.DATA_TYPES_NOT_LOADED, parentComponent.getModel()));
+ }
+ sourceSelectedProperty =
+ findSubProperty(propertyPathFromSource.subList(1, propertyPathFromSource.size()), sourceSelectedProperty.get().getType(),
+ allDataTypesEither.left().value());
+ }
+ final Optional<? extends PropertyDefinition> targetComponentInstanceProperty =
+ parentComponent.getComponentInstancesProperties()
+ .get(componentInstanceId).stream()
+ .filter(property -> filterConstraint.getPropertyName().equals(property.getName()))
+ .findFirst();
+ if (sourceSelectedProperty.isPresent() && targetComponentInstanceProperty.isPresent()) {
+ final ResponseFormat responseFormat = validatePropertyData(sourceSelectedProperty.get(), targetComponentInstanceProperty.get());
+ if (responseFormat != null) {
+ return Either.right(responseFormat);
}
+ return Either.left(true);
}
- LOGGER.debug("Parent component does not have inputs", parentComponent);
+
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INPUTS_NOT_FOUND));
}
- private Either<Boolean, ResponseFormat> validatePropertyData(UIConstraint uiConstraint,
- Optional<? extends PropertyDefinition> sourceSelectedProperty,
- Optional<? extends PropertyDefinition> targetComponentInstanceProperty) {
- if (sourceSelectedProperty.isPresent() && targetComponentInstanceProperty.isPresent()) {
- final PropertyDefinition sourcePropDefinition = sourceSelectedProperty.get();
- final String sourceType = sourcePropDefinition.getType();
- final PropertyDefinition targetPropDefinition = targetComponentInstanceProperty.get();
- final String targetType = targetPropDefinition.getType();
- if (sourceType.equals(targetType)) {
- if (schemableTypes.contains(sourceType)) {
- final SchemaDefinition sourceSchemaDefinition = sourcePropDefinition.getSchema();
- final SchemaDefinition targetSchemaDefinition = targetPropDefinition.getSchema();
- if (!sourceSchemaDefinition.equals(targetSchemaDefinition)) {
- return Either.right(componentsUtils
- .getResponseFormat(ActionStatus.SOURCE_TARGET_SCHEMA_MISMATCH, uiConstraint.getServicePropertyName(),
- uiConstraint.getValue().toString()));
- }
+ private <T extends ToscaPropertyData> ResponseFormat validatePropertyData(final T sourcePropDefinition,
+ final T targetPropDefinition) {
+ final String sourceType = sourcePropDefinition.getType();
+ final String targetType = targetPropDefinition.getType();
+ if (sourceType.equals(targetType)) {
+ if (TYPES_WITH_SCHEMA.contains(sourceType)) {
+ final String sourceSchemaType = sourcePropDefinition.getSchemaType();
+ final String targetSchemaType = targetPropDefinition.getSchemaType();
+ if (sourceSchemaType != null && !sourceSchemaType.equals(targetSchemaType)) {
+ return componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_SCHEMA_MISMATCH,
+ targetPropDefinition.getName(), targetSchemaType, sourcePropDefinition.getName(), sourceSchemaType);
}
- return Either.left(Boolean.TRUE);
- } else {
- return Either.right(componentsUtils
- .getResponseFormat(ActionStatus.SOURCE_TARGET_PROPERTY_TYPE_MISMATCH, uiConstraint.getServicePropertyName(),
- uiConstraint.getValue().toString()));
}
- } else {
- LOGGER.debug("Null value passed to `validatePropertyData` - sourceSelectedProperty: '{}' - targetComponentInstanceProperty: '{}'",
- sourceSelectedProperty, targetComponentInstanceProperty);
- return Either.right(componentsUtils
- .getResponseFormat(ActionStatus.GENERAL_ERROR, uiConstraint.getServicePropertyName(), uiConstraint.getValue().toString()));
+ return null;
}
+ return componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_PROPERTY_TYPE_MISMATCH,
+ sourcePropDefinition.getName(), sourcePropDefinition.getType(), targetPropDefinition.getName(), targetPropDefinition.getType());
}
private Either<Boolean, ResponseFormat> validateStaticValueAndOperator(final Component parentComponent, final String componentInstanceId,
- final UIConstraint uiConstraint) {
- if (!(Objects.nonNull(uiConstraint) && uiConstraint.getValue() instanceof String)) {
- return Either.left(false);
- }
- //TODO: get capabilities properties when constraint type is capabilities
- final Optional<ComponentInstanceProperty> componentInstanceProperty = parentComponent.getComponentInstancesProperties()
- .get(componentInstanceId).stream().filter(property -> uiConstraint.getServicePropertyName().equals(property.getName())).findFirst();
- if (!componentInstanceProperty.isPresent()) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT, uiConstraint.getServicePropertyName()));
- }
- if (comparableConstraintsOperators.contains(uiConstraint.getConstraintOperator()) && !comparableTypes
- .contains(componentInstanceProperty.get().getType())) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, uiConstraint.getServicePropertyName(),
- uiConstraint.getConstraintOperator()));
- }
- return isValidValueCheck(componentInstanceProperty.get().getType(), String.valueOf(uiConstraint.getValue()),
- uiConstraint.getServicePropertyName());
+ final FilterConstraintDto filterConstraint) {
+ final ComponentInstanceProperty componentInstanceProperty = parentComponent.getComponentInstancesProperties()
+ .get(componentInstanceId).stream().filter(property -> filterConstraint.getPropertyName().equals(property.getName()))
+ .findFirst()
+ .orElse(null);
+ if (componentInstanceProperty == null) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT, filterConstraint.getPropertyName()));
+ }
+ if (filterConstraint.getOperator().isComparable() && !COMPARABLE_TYPES.contains(componentInstanceProperty.getType())) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, filterConstraint.getPropertyName(),
+ filterConstraint.getOperator().getType()));
+ }
+ return isValidValueCheck(componentInstanceProperty.getType(), componentInstanceProperty.getSchemaType(), parentComponent.getModel(),
+ filterConstraint.getValue(), filterConstraint.getPropertyName());
+ }
+
+ private Either<Boolean, ResponseFormat> validateStaticSubstitutionFilter(final Component component,
+ final FilterConstraintDto filterConstraint) {
+
+ final PropertyDefinition componentProperty = component.getProperties().stream()
+ .filter(property -> property.getName().equals(filterConstraint.getPropertyName())).findFirst().orElse(null);
+ if (componentProperty == null) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT, filterConstraint.getPropertyName()));
+ }
+ if (filterConstraint.getOperator().isComparable() && !COMPARABLE_TYPES.contains(componentProperty.getType())) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, filterConstraint.getPropertyName(),
+ filterConstraint.getOperator().getType()));
+ }
+ return isValidValueCheck(componentProperty.getType(), componentProperty.getSchemaType(), component.getModel(),
+ filterConstraint.getValue(), filterConstraint.getPropertyName());
}
private Either<Boolean, ResponseFormat> validateStaticValueAndOperatorOfCapabilityProperties(final Component parentComponent,
final String componentInstanceId,
- final UIConstraint uiConstraint) {
- if (!(Objects.nonNull(uiConstraint) && uiConstraint.getValue() instanceof String)) {
- return Either.left(false);
- }
- Optional<ComponentInstanceProperty> optionalComponentInstanceProperty = Optional.empty();
+ final FilterConstraintDto filterConstraint) {
+ ComponentInstanceProperty componentInstanceProperty = null;
final Optional<ComponentInstance> optionalComponentInstances = parentComponent.getComponentInstances().stream()
.filter(componentInstance -> componentInstanceId.equalsIgnoreCase(componentInstance.getUniqueId())).findFirst();
if (optionalComponentInstances.isPresent()) {
@@ -277,99 +370,136 @@ public class NodeFilterValidator {
.allMatch(capabilityDefinition -> capabilityDefinition.getProperties() != null)).collect(Collectors.toList()).stream().filter(
capabilityDefinitions -> capabilityDefinitions.stream().allMatch(
capabilityDefinition -> capabilityDefinition.getProperties().stream().anyMatch(
- componentInstanceProperty -> uiConstraint.getServicePropertyName()
- .equalsIgnoreCase(componentInstanceProperty.getName())))).findFirst();
+ componentInstanceProperty1 -> filterConstraint.getPropertyName()
+ .equalsIgnoreCase(componentInstanceProperty1.getName())))).findFirst();
if (optionalCapabilityDefinitionList.isPresent() && !optionalCapabilityDefinitionList.get().isEmpty()) {
- optionalComponentInstanceProperty = getComponentInstanceProperty(optionalCapabilityDefinitionList.get().get(0), uiConstraint.getServicePropertyName());
+ componentInstanceProperty =
+ getComponentInstanceProperty(optionalCapabilityDefinitionList.get().get(0), filterConstraint.getPropertyName()).orElse(null);
}
}
- if (optionalComponentInstanceProperty.isEmpty()) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT, uiConstraint.getServicePropertyName()));
+ if (componentInstanceProperty == null) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT, filterConstraint.getPropertyName()));
}
- if (comparableConstraintsOperators.contains(uiConstraint.getConstraintOperator()) && !comparableTypes
- .contains(optionalComponentInstanceProperty.get().getType())) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, uiConstraint.getServicePropertyName(),
- uiConstraint.getConstraintOperator()));
+ if (filterConstraint.getOperator().isComparable() && !COMPARABLE_TYPES.contains(componentInstanceProperty.getType())) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, filterConstraint.getPropertyName(),
+ filterConstraint.getOperator().getType()));
}
- return isValidValueCheck(optionalComponentInstanceProperty.get().getType(), String.valueOf(uiConstraint.getValue()),
- uiConstraint.getServicePropertyName());
+ return isValidValueCheck(componentInstanceProperty.getType(), componentInstanceProperty.getSchemaType(), parentComponent.getModel(),
+ filterConstraint.getValue(), filterConstraint.getPropertyName());
}
private Optional<ComponentInstanceProperty> getComponentInstanceProperty(CapabilityDefinition capabilityDefinition, final String propertyName){
return capabilityDefinition.getProperties().stream().filter(property -> property.getName().equals(propertyName)).findAny();
}
- private Either<Boolean, ResponseFormat> isValidValueCheck(String type, String value, String propertyName) {
- ToscaPropertyType toscaPropertyType = ToscaPropertyType.isValidType(type);
- if (Objects.isNull(toscaPropertyType)) {
+ private Either<Boolean, ResponseFormat> isValidValueCheck(final String type, final String schemaType, final String model,
+ final Object value, final String propertyName) {
+ final Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypesEither =
+ applicationDataTypeCache.getAll(model);
+ if (allDataTypesEither.isRight()) {
+ LOGGER.error("Could not validate filter value. Could not load data types for model {}", model);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.DATA_TYPES_NOT_LOADED, model));
+ }
+ final Map<String, DataTypeDefinition> modelDataTypesMap = allDataTypesEither.left().value();
+ final ToscaPropertyType toscaPropertyType = ToscaPropertyType.isValidType(type);
+ if (toscaPropertyType == null && !modelDataTypesMap.containsKey(type)) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_PROPERTY_TYPE, type, propertyName));
}
- if (toscaPropertyType.getValidator().isValid(value, null)) {
- return Either.left(Boolean.TRUE);
+ final String valueAsJsonString;
+ try {
+ valueAsJsonString = new Gson().toJson(value);
+ } catch (final Exception e) {
+ LOGGER.debug("Unsupported property filter value", e);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, type, propertyName, String.valueOf(value)));
+ }
+ if (toscaPropertyType != null) {
+ if (toscaPropertyType.getValidator().isValid(valueAsJsonString, schemaType, modelDataTypesMap)) {
+ return Either.left(true);
+ }
+ } else {
+ if (DataTypeValidatorConverter.getInstance().isValid(valueAsJsonString, modelDataTypesMap.get(type), modelDataTypesMap)) {
+ return Either.left(true);
+ }
}
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, type, propertyName, value));
+
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, type, propertyName, valueAsJsonString));
}
- public Either<Boolean, ResponseFormat> validateComponentFilter(final Component component, final List<String> uiConstraints,
- final NodeFilterConstraintAction action) {
- try {
- if (NodeFilterConstraintAction.ADD == action || NodeFilterConstraintAction.UPDATE == action) {
- for (final String uiConstraint : uiConstraints) {
- final UIConstraint constraint = new ConstraintConvertor().convert(uiConstraint);
- if (ConstraintConvertor.PROPERTY_CONSTRAINT.equals(constraint.getSourceType())) {
- final Either<Boolean, ResponseFormat> booleanResponseFormatEither = validateComponentPropertyConstraint(component,
- constraint);
- if (booleanResponseFormatEither.isRight()) {
- return booleanResponseFormatEither;
- }
- } else if (ConstraintConvertor.STATIC_CONSTRAINT.equals(constraint.getSourceType())) {
- final Either<Boolean, ResponseFormat> booleanResponseFormatEither = validateComponentStaticValueAndOperator(component,
- constraint);
- if (booleanResponseFormatEither.isRight()) {
- return booleanResponseFormatEither;
- }
- }
- }
- }
- } catch (final Exception e) {
- LOGGER.debug("Provided constraint" + uiConstraints, e);
+ public Either<Boolean, ResponseFormat> validateSubstitutionFilter(final Component component, final List<FilterConstraintDto> filterConstraintList) {
+ if (CollectionUtils.isEmpty(filterConstraintList)) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.CONSTRAINT_FORMAT_INCORRECT));
}
+ for (final FilterConstraintDto filterConstraintDto : filterConstraintList) {
+ final Either<Boolean, ResponseFormat> validationEither = validateSubstitutionFilter(component, filterConstraintDto);
+ if (validationEither.isRight()) {
+ return validationEither;
+ }
+ }
return Either.left(true);
}
- private Either<Boolean, ResponseFormat> validateComponentPropertyConstraint(final Component component, final UIConstraint uiConstraint) {
- String source = SOURCE;
- final List<PropertyDefinition> propertyDefinitions = component.getProperties();
- if (CollectionUtils.isNotEmpty(propertyDefinitions)) {
- final Optional<? extends PropertyDefinition> sourceSelectedProperty = propertyDefinitions.stream()
- .filter(property -> uiConstraint.getValue().equals(property.getName())).findFirst();
- final Optional<? extends PropertyDefinition> targetComponentProperty = component.getProperties().stream()
- .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName())).findFirst();
- source = !targetComponentProperty.isPresent() ? "Target" : SOURCE;
- if (sourceSelectedProperty.isPresent() && targetComponentProperty.isPresent()) {
- return validatePropertyData(uiConstraint, sourceSelectedProperty, targetComponentProperty);
- }
+ public Either<Boolean, ResponseFormat> validateSubstitutionFilter(final Component component, final FilterConstraintDto filterConstraint) {
+ validateFilterConstraint(filterConstraint);
+ switch (filterConstraint.getValueType()) {
+ case STATIC:
+ return validateStaticSubstitutionFilter(component, filterConstraint);
+ case GET_PROPERTY:
+ case GET_ATTRIBUTE:
+ case GET_INPUT:
+ return validateSubstitutionFilterGetFunctionConstraint(component, filterConstraint);
+ default:
+ return Either.left(true);
}
- final String missingProperty = source.equals(SOURCE) ? uiConstraint.getValue().toString() : uiConstraint.getServicePropertyName();
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.MAPPED_PROPERTY_NOT_FOUND, source, missingProperty));
}
- private Either<Boolean, ResponseFormat> validateComponentStaticValueAndOperator(final Component component, final UIConstraint uiConstraint) {
- if (!(Objects.nonNull(uiConstraint) && uiConstraint.getValue() instanceof String)) {
- return Either.left(false);
+ private Either<Boolean, ResponseFormat> validateSubstitutionFilterGetFunctionConstraint(final Component component,
+ final FilterConstraintDto filterConstraint) {
+ final ToscaGetFunctionDataDefinition toscaGetFunction = filterConstraint.getAsToscaGetFunction().orElse(null);
+ if (toscaGetFunction == null) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.TOSCA_FUNCTION_EXPECTED_ERROR));
}
- final Optional<PropertyDefinition> componentProperty = component.getProperties().stream()
- .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName())).findFirst();
- if (componentProperty.isEmpty()) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT, uiConstraint.getServicePropertyName()));
+
+ if (CollectionUtils.isEmpty(component.getProperties())) {
+ return Either.right(
+ componentsUtils.getResponseFormat(ActionStatus.FILTER_PROPERTY_NOT_FOUND, TARGET, getPropertyType(toscaGetFunction),
+ filterConstraint.getPropertyName())
+ );
+ }
+
+ final Optional<? extends PropertyDefinition> targetComponentProperty = component.getProperties().stream()
+ .filter(property -> property.getName().equals(filterConstraint.getPropertyName())).findFirst();
+ if (targetComponentProperty.isEmpty()) {
+ return Either.right(
+ componentsUtils.getResponseFormat(ActionStatus.FILTER_PROPERTY_NOT_FOUND, TARGET, getPropertyType(toscaGetFunction),
+ filterConstraint.getPropertyName())
+ );
}
- if (comparableConstraintsOperators.contains(uiConstraint.getConstraintOperator()) && !comparableTypes
- .contains(componentProperty.get().getType())) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, uiConstraint.getServicePropertyName(),
- uiConstraint.getConstraintOperator()));
+
+ final Optional<? extends ToscaPropertyData> sourceSelectedProperty = findPropertyFromGetFunction(component, toscaGetFunction);
+ if (sourceSelectedProperty.isEmpty()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.FILTER_PROPERTY_NOT_FOUND, SOURCE, getPropertyType(toscaGetFunction),
+ String.join("->", toscaGetFunction.getPropertyPathFromSource())));
+ }
+
+ final ResponseFormat responseFormat = validatePropertyData(sourceSelectedProperty.get(), targetComponentProperty.get());
+ if (responseFormat != null) {
+ return Either.right(responseFormat);
}
- return isValidValueCheck(componentProperty.get().getType(), String.valueOf(uiConstraint.getValue()), uiConstraint.getServicePropertyName());
+ return Either.left(true);
}
+
+ private String getPropertyType(final ToscaGetFunctionDataDefinition toscaGetFunction) {
+ switch (toscaGetFunction.getType()) {
+ case GET_INPUT:
+ return "input";
+ case GET_PROPERTY:
+ return "property";
+ case GET_ATTRIBUTE:
+ return "attribute";
+ default:
+ return "";
+ }
+ }
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java
index a2c7aa2502..8e823bbe9f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java
@@ -19,15 +19,15 @@
*/
package org.openecomp.sdc.be.datamodel.utils;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
-import org.openecomp.sdc.be.model.tosca.constraints.ConstraintType;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType;
+import org.openecomp.sdc.be.datatypes.enums.PropertySource;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
import org.slf4j.Logger;
@@ -37,91 +37,92 @@ import org.yaml.snakeyaml.Yaml;
public class ConstraintConvertor {
- public static final String EQUAL_OPERATOR = ConstraintType.EQUAL.getTypes().get(1);
- public static final String GREATER_THAN_OPERATOR = ConstraintType.GREATER_THAN.getTypes().get(1);
- public static final String LESS_THAN_OPERATOR = ConstraintType.LESS_THAN.getTypes().get(1);
- public static final String GREATER_OR_EQUAL_OPERATOR = ConstraintType.GREATER_OR_EQUAL.getTypes().get(1);
- public static final String LESS_OR_EQUAL_OPERATOR = ConstraintType.LESS_OR_EQUAL.getTypes().get(1);
public static final String STATIC_CONSTRAINT = "static";
public static final String PROPERTY_CONSTRAINT = "property";
public static final String SERVICE_INPUT_CONSTRAINT = "service_input";
public static final String SELF = "SELF";
private static final Logger logger = LoggerFactory.getLogger(ConstraintConvertor.class);
- private static Set<String> SUPPORTED_CONSTRAINT_LIST = ImmutableSet.of(EQUAL_OPERATOR, GREATER_THAN_OPERATOR, LESS_THAN_OPERATOR, GREATER_OR_EQUAL_OPERATOR, LESS_OR_EQUAL_OPERATOR);
- private static Set<String> SUPPORTED_FUNCTIONS = ImmutableSet
- .of(ToscaFunctions.GET_INPUT.getFunctionName(), ToscaFunctions.GET_PROPERTY.getFunctionName());
+ private static final Set<ConstraintType> SUPPORTED_CONSTRAINT_LIST =
+ Set.of(ConstraintType.EQUAL, ConstraintType.GREATER_THAN, ConstraintType.LESS_THAN,
+ ConstraintType.GREATER_OR_EQUAL, ConstraintType.LESS_OR_EQUAL);
- public UIConstraint convert(String inConstraint) {
- return convert(inConstraint, "");
+ public UIConstraint convert(final String constraintValue) {
+ return convert(constraintValue, null);
}
- public UIConstraint convert(String inConstraint, String valueType) {
+ public UIConstraint convert(final String inConstraint, final String valueType) {
Yaml yamlSource = new Yaml();
UIConstraint uiConstraint = new UIConstraint();
Object content1 = yamlSource.load(inConstraint);
if (!(content1 instanceof Map)) {
return null;
}
- Map map1 = (Map) content1;
- Object key = map1.keySet().iterator().next();
- uiConstraint.setServicePropertyName(key.toString());
- Object content2 = map1.get(key);
- if (!(content2 instanceof Map)) {
+ Map propertyAndConstraintMap = (Map) content1;
+ Object propertyNameKey = propertyAndConstraintMap.keySet().iterator().next();
+ uiConstraint.setServicePropertyName(propertyNameKey.toString());
+ Object operatorMapObj = propertyAndConstraintMap.get(propertyNameKey);
+ if (!(operatorMapObj instanceof Map)) {
return null;
}
- Map map2 = (Map) content2;
- Object key2 = map2.keySet().iterator().next();
- final String operator = key2.toString();
- if (SUPPORTED_CONSTRAINT_LIST.contains(operator)) {
+ Map operatorMap = (Map) operatorMapObj;
+ Object operatorKey = operatorMap.keySet().iterator().next();
+ final String operator = (String) operatorKey;
+ final Optional<ConstraintType> constraintType = ConstraintType.findByType(operator);
+ if (constraintType.isPresent() && SUPPORTED_CONSTRAINT_LIST.contains(constraintType.get())) {
uiConstraint.setConstraintOperator(operator);
}
- Object content3 = map2.get(key2);
- if (content3 instanceof String || content3 instanceof Number || content3 instanceof Boolean) {
- uiConstraint.setValue(content3);
+ Object constraintValueObj = operatorMap.get(operatorKey);
+ if (constraintValueObj instanceof String || constraintValueObj instanceof Number || constraintValueObj instanceof Boolean) {
+ uiConstraint.setValue(constraintValueObj);
uiConstraint.setSourceType(STATIC_CONSTRAINT);
uiConstraint.setSourceName(STATIC_CONSTRAINT);
return uiConstraint;
- } else if (content3 instanceof List) {
- List list1 = (List) content3;
+ } else if (constraintValueObj instanceof List) {
uiConstraint.setSourceType(STATIC_CONSTRAINT);
uiConstraint.setSourceName(STATIC_CONSTRAINT);
- uiConstraint.setValue(list1);
+ uiConstraint.setValue(constraintValueObj);
return uiConstraint;
- } else if (valueType != null && valueType.equals("string")) {
+ } else if ("string".equals(valueType)) {
uiConstraint.setSourceType(STATIC_CONSTRAINT);
uiConstraint.setSourceName(STATIC_CONSTRAINT);
- DumperOptions options = new DumperOptions();
- options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
- Yaml yaml = new Yaml(options);
- String yamlString = yaml.dump(content3);
- uiConstraint.setValue(yamlString);
+ uiConstraint.setValue(dumpYamlString(constraintValueObj));
return uiConstraint;
- } else if (content3 instanceof Map) {
- return handleMap(uiConstraint, content3);
+ } else if (constraintValueObj instanceof Map) {
+ return handleMap(uiConstraint, (Map<Object, Object>) constraintValueObj);
}
return null;
}
- private UIConstraint handleMap(UIConstraint uiConstraint, Object content3) {
- Map map3 = (Map) content3;
- Map.Entry entry = (Map.Entry) map3.entrySet().iterator().next();
+ private String dumpYamlString(final Object constraintValueObj) {
+ final var dumperOptions = new DumperOptions();
+ dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
+ return new Yaml(dumperOptions).dump(constraintValueObj);
+ }
+
+ private UIConstraint handleMap(final UIConstraint uiConstraint, final Map<Object, Object> constraintValueAsMap) {
+ final Map.Entry<Object, Object> entry = constraintValueAsMap.entrySet().iterator().next();
final String firstKey = entry.getKey().toString().trim();
- if (!SUPPORTED_FUNCTIONS.contains(firstKey)) {
- uiConstraint.setValue(content3);
+ final ToscaFunctionType toscaFunctionType = ToscaFunctionType.findType(firstKey).orElse(null);
+ if (toscaFunctionType == null) {
+ uiConstraint.setValue(constraintValueAsMap);
return uiConstraint;
}
- if (ToscaFunctions.GET_INPUT.getFunctionName().equals(firstKey)) {
- uiConstraint.setSourceType(SERVICE_INPUT_CONSTRAINT);
- uiConstraint.setValue(entry.getValue());
- return uiConstraint;
- } else if (ToscaFunctions.GET_PROPERTY.getFunctionName().equals(firstKey)) {
- uiConstraint.setSourceType(PROPERTY_CONSTRAINT);
- final List<String> value = (List<String>) entry.getValue();
- uiConstraint.setSourceName(value.get(0));
- uiConstraint.setValue(value.get(1));
- return uiConstraint;
+ uiConstraint.setValue(constraintValueAsMap);
+ uiConstraint.setSourceType(toscaFunctionType.getName());
+ switch (toscaFunctionType) {
+ case GET_INPUT:
+ uiConstraint.setSourceName(PropertySource.SELF.getName());
+ break;
+ case GET_PROPERTY:
+ case GET_ATTRIBUTE:
+ final List<String> value = (List<String>) entry.getValue();
+ uiConstraint.setSourceName(value.get(0));
+ break;
+ default:
+ break;
}
- return null;
+
+ return uiConstraint;
}
public List<String> convertToList(List<UIConstraint> uiConstraints) {
@@ -135,29 +136,39 @@ public class ConstraintConvertor {
return retVal;
}
- public String convert(UIConstraint uiConstraint) {
+ public String convert(final UIConstraint uiConstraint) {
try {
- Map map1 = new HashMap();
- Map map2 = new HashMap();
- map1.put(uiConstraint.getServicePropertyName(), map2);
- if (uiConstraint.getSourceType().equals(STATIC_CONSTRAINT)) {
- Object value = uiConstraint.getValue();
- if (value instanceof String) {
- value = new Yaml().load(value.toString());
+ final Map<String, Object> constraintAsMap = new HashMap<>();
+ switch (uiConstraint.getSourceType()) {
+ case STATIC_CONSTRAINT: {
+ Object value = uiConstraint.getValue();
+ if (value instanceof String) {
+ value = new Yaml().load(value.toString());
+ }
+ constraintAsMap.put(uiConstraint.getConstraintOperator(), value);
+ break;
+ }
+ case PROPERTY_CONSTRAINT:
+ constraintAsMap.put(uiConstraint.getConstraintOperator(),
+ Map.of(ToscaFunctions.GET_PROPERTY.getFunctionName(), List.of(uiConstraint.getSourceName(), uiConstraint.getValue()))
+ );
+ break;
+ case SERVICE_INPUT_CONSTRAINT:
+ constraintAsMap.put(uiConstraint.getConstraintOperator(), Map.of(ToscaFunctions.GET_INPUT.getFunctionName(), uiConstraint.getValue()));
+ break;
+ default: {
+ if (ToscaFunctionType.findType(uiConstraint.getSourceType()).isPresent()) {
+ Object value = uiConstraint.getValue();
+ if (value instanceof String) {
+ value = new Yaml().load((String) value);
+ }
+ constraintAsMap.put(uiConstraint.getConstraintOperator(), value);
+ }
}
- map2.put(uiConstraint.getConstraintOperator(), value);
- } else if (uiConstraint.getSourceType().equals(PROPERTY_CONSTRAINT)) {
- List list1 = Arrays.asList(uiConstraint.getSourceName(), uiConstraint.getValue());
- Map map3 = ImmutableMap.of(ToscaFunctions.GET_PROPERTY.getFunctionName(), list1);
- map2.put(uiConstraint.getConstraintOperator(), map3);
- } else if (uiConstraint.getSourceType().equals(SERVICE_INPUT_CONSTRAINT)) {
- Map map3 = ImmutableMap.of(ToscaFunctions.GET_INPUT.getFunctionName(), uiConstraint.getValue());
- map2.put(uiConstraint.getConstraintOperator(), map3);
}
- Yaml yamlSource = new Yaml();
- return yamlSource.dump(map1);
- } catch (NullPointerException ex) {
- logger.error(ex.getMessage(), ex);
+ return new Yaml().dump(Map.of(uiConstraint.getServicePropertyName(), constraintAsMap));
+ } catch (final Exception ex) {
+ logger.error("Could not convert constraint", ex);
}
return null;
}
@@ -187,13 +198,12 @@ public class ConstraintConvertor {
uiConstraint.setSourceName(STATIC_CONSTRAINT);
return uiConstraint;
} else if (constraintValue instanceof List) {
- final List constraintValueList = (List) constraintValue;
uiConstraint.setSourceType(STATIC_CONSTRAINT);
uiConstraint.setSourceName(STATIC_CONSTRAINT);
- uiConstraint.setValue(constraintValueList);
+ uiConstraint.setValue(constraintValue);
return uiConstraint;
} else if (constraintValue instanceof Map) {
- return handleMap(uiConstraint, constraintValue);
+ return handleMap(uiConstraint, (Map<Object, Object>) constraintValue);
}
return null;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
index 7d58687bfd..313a303b61 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
@@ -80,9 +80,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
import org.openecomp.sdc.be.dao.graph.datatype.AdditionalInformationEnum;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
-import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterInfo;
-import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ToscaFunction;
import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionJsonDeserializer;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
@@ -138,7 +136,7 @@ public class ComponentsUtils {
private static final String CONVERT_JSON_TO_OBJECT = "convertJsonToObject";
private static final Logger log = Logger.getLogger(ComponentsUtils.class);
private static final String PARTNER_NAME = "UNKNOWN";
- private static LoggerSdcAudit audit = new LoggerSdcAudit(DmaapConsumer.class);
+ private static final LoggerSdcAudit audit = new LoggerSdcAudit(DmaapConsumer.class);
private final AuditingManager auditingManager;
private final ResponseFormatManager responseFormatManager;
@@ -174,27 +172,7 @@ public class ComponentsUtils {
return false;
}
return componentInstance.getNodeFilter().getProperties().getListToscaDataDefinition().stream()
- .anyMatch(property -> isPropertyConstraintChangedByCi(property, componentInstanceName));
- }
-
- private static boolean isPropertyConstraintChangedByCi(
- final RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition, final String componentInstanceName) {
- final List<String> constraints = requirementNodeFilterPropertyDataDefinition.getConstraints();
- if (constraints == null) {
- return false;
- }
- return constraints.stream().anyMatch(constraint -> isConstraintChangedByCi(constraint, componentInstanceName));
- }
-
- private static boolean isConstraintChangedByCi(final String constraint, final String componentInstanceName) {
- final UIConstraint uiConstraint = new ConstraintConvertor().convert(constraint);
- if (uiConstraint == null || uiConstraint.getSourceType() == null) {
- return false;
- }
- if (!uiConstraint.getSourceType().equals(ConstraintConvertor.PROPERTY_CONSTRAINT)) {
- return false;
- }
- return uiConstraint.getSourceName().equals(componentInstanceName);
+ .anyMatch(property -> ServiceFilterUtils.isPropertyConstraintChangedByCi(property, componentInstanceName));
}
public AuditingManager getAuditingManager() {
@@ -1554,7 +1532,7 @@ public class ComponentsUtils {
log.error(EcompLoggerErrorCode.DATA_ERROR, FAILED_TO_PARSE_CONSTRAINT_DATA, constraintData);
return Collections.emptyList();
}
- return uiConstraintsMaps.stream().map(dataMap -> new com.fasterxml.jackson.databind.ObjectMapper().convertValue(dataMap, UIConstraint.class))
+ return uiConstraintsMaps.stream().map(dataMap -> new ObjectMapper().convertValue(dataMap, UIConstraint.class))
.collect(Collectors.toList());
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java
index 866affc509..c3fdaa6bed 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java
@@ -24,11 +24,18 @@ import org.apache.commons.collections.CollectionUtils;
import org.javatuples.Pair;
import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
-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.elements.ToscaConcatFunction;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunction;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionParameter;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType;
+import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.Service;
-import org.openecomp.sdc.be.ui.model.UIConstraint;
+import org.openecomp.sdc.be.ui.mapper.FilterConstraintMapper;
public class ServiceFilterUtils {
@@ -48,12 +55,19 @@ public class ServiceFilterUtils {
|| ci.getNodeFilter().getProperties().getListToscaDataDefinition() == null) {
return false;
}
- return ci.getNodeFilter().getProperties().getListToscaDataDefinition().stream().flatMap(prop -> prop.getConstraints().stream())
- .map(String::new)
- .filter(constraint -> new ConstraintConvertor().convert(constraint).getSourceType().equals(ConstraintConvertor.PROPERTY_CONSTRAINT))
- .anyMatch(constraintStr -> {
- UIConstraint uiConstraint = new ConstraintConvertor().convert(constraintStr);
- return uiConstraint.getSourceName().equals(ciName) && uiConstraint.getValue().equals(propertyName);
+ return ci.getNodeFilter().getProperties().getListToscaDataDefinition().stream()
+ .flatMap(prop -> prop.getConstraints().stream())
+ .filter(constraint ->
+ List.of(ConstraintConvertor.PROPERTY_CONSTRAINT, ToscaFunctionType.GET_PROPERTY.getName())
+ .contains(constraint.getValueType().getName())
+ )
+ .map(new FilterConstraintMapper()::mapFrom)
+ .anyMatch(constraint -> {
+ final ToscaGetFunctionDataDefinition toscaGetFunction = constraint.getAsToscaGetFunction().orElse(null);
+ if (toscaGetFunction == null) {
+ return false;
+ }
+ return toscaGetFunction.getSourceName().equals(ciName) && toscaGetFunction.getPropertyPathFromSource().contains(propertyName);
});
}
@@ -69,22 +83,59 @@ public class ServiceFilterUtils {
return new Pair<>(ci.getUniqueId(), ci.getNodeFilter());
}
- private static void renamePropertyCiNames(RequirementNodeFilterPropertyDataDefinition property, String oldName, String newName) {
- final List<String> constraints = property.getConstraints().stream().map(getConstraintString(oldName, newName)).collect(Collectors.toList());
- property.setConstraints(constraints);
+ private static void renamePropertyCiNames(final PropertyFilterDataDefinition propertyFilter, final String oldInstanceName,
+ final String newInstanceName) {
+ final List<FilterValueType> instanceValueTypes =
+ List.of(FilterValueType.GET_PROPERTY, FilterValueType.GET_ATTRIBUTE, FilterValueType.CONCAT);
+ final List<PropertyFilterConstraintDataDefinition> constraints = propertyFilter.getConstraints().stream()
+ .filter(propertyFilter1 -> instanceValueTypes.contains(propertyFilter1.getValueType()))
+ .map(replaceConstraintsInstanceSource(oldInstanceName, newInstanceName))
+ .collect(Collectors.toList());
+ propertyFilter.setConstraints(constraints);
}
- private static Function<String, String> getConstraintString(String oldName, String newName) {
+ private static Function<PropertyFilterConstraintDataDefinition, PropertyFilterConstraintDataDefinition> replaceConstraintsInstanceSource(
+ final String oldInstanceName, final String newInstanceName) {
+
return constraint -> {
- final ConstraintConvertor constraintConvertor = new ConstraintConvertor();
- UIConstraint uiConstraint = constraintConvertor.convert(constraint);
- if (uiConstraint.getSourceName().equals(oldName)) {
- uiConstraint.setSourceName(newName);
+ final ToscaFunction toscaFunction = new FilterConstraintMapper().parseValueToToscaFunction(constraint.getValue()).orElse(null);
+ if (toscaFunction == null) {
+ return constraint;
}
- return constraintConvertor.convert(uiConstraint);
+ renameToscaFunctionComponentInstance(toscaFunction, oldInstanceName, newInstanceName);
+ return constraint;
};
}
+ private static void renameToscaFunctionComponentInstance(final ToscaFunction toscaFunction, final String oldInstanceName,
+ final String newInstanceName) {
+ switch (toscaFunction.getType()) {
+ case GET_PROPERTY:
+ case GET_ATTRIBUTE: {
+ final ToscaGetFunctionDataDefinition toscaGetFunctionDataDefinition = (ToscaGetFunctionDataDefinition) toscaFunction;
+ if (toscaGetFunctionDataDefinition.getSourceName().equals(oldInstanceName)) {
+ toscaGetFunctionDataDefinition.setSourceName(newInstanceName);
+ }
+ break;
+ }
+ case CONCAT: {
+ final ToscaConcatFunction toscaConcatFunction = (ToscaConcatFunction) toscaFunction;
+ for (final ToscaFunctionParameter parameter : toscaConcatFunction.getParameters()) {
+ switch (parameter.getType()) {
+ case GET_PROPERTY:
+ case GET_ATTRIBUTE:
+ case CONCAT:
+ renameToscaFunctionComponentInstance((ToscaFunction) parameter, oldInstanceName, newInstanceName);
+ break;
+ default:
+ }
+ }
+ break;
+ }
+ default:
+ }
+ }
+
public static Set<String> getNodesFiltersToBeDeleted(Service service, String ciName) {
return service.getComponentInstances().stream().filter(ci -> isNodeFilterUsingChangedCi(ci, ciName)).map(ComponentInstance::getName)
.collect(Collectors.toSet());
@@ -106,24 +157,24 @@ public class ServiceFilterUtils {
.anyMatch(property -> isPropertyConstraintChangedByCi(property, name));
}
- private static boolean isPropertyConstraintChangedByCi(RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition,
+ public static boolean isPropertyConstraintChangedByCi(PropertyFilterDataDefinition propertyFilterDataDefinition,
String name) {
- List<String> constraints = requirementNodeFilterPropertyDataDefinition.getConstraints();
- if (constraints == null) {
+ List<PropertyFilterConstraintDataDefinition> constraints = propertyFilterDataDefinition.getConstraints();
+ if (CollectionUtils.isEmpty(constraints)) {
return false;
}
return constraints.stream().anyMatch(constraint -> isConstraintChangedByCi(constraint, name));
}
- private static boolean isConstraintChangedByCi(String constraint, String name) {
- UIConstraint uiConstraint = new ConstraintConvertor().convert(constraint);
- if (uiConstraint == null || uiConstraint.getSourceType() == null) {
- return false;
- }
- if (!uiConstraint.getSourceType().equals(ConstraintConvertor.PROPERTY_CONSTRAINT)) {
- return false;
+ private static boolean isConstraintChangedByCi(final PropertyFilterConstraintDataDefinition constraint, final String name) {
+ if (constraint.getValueType() == FilterValueType.GET_PROPERTY || constraint.getValueType() == FilterValueType.GET_ATTRIBUTE) {
+ final ToscaFunction toscaFunction = new FilterConstraintMapper().parseValueToToscaFunction(constraint.getValue()).orElse(null);
+ if (toscaFunction != null) {
+ final ToscaGetFunctionDataDefinition toscaGetFunction = (ToscaGetFunctionDataDefinition) toscaFunction;
+ return toscaGetFunction.getSourceName().equals(name);
+ }
}
- return uiConstraint.getSourceName().equals(name);
+ return false;
}
public static Set<String> getNodesFiltersToBeDeleted(Service service, InputDefinition changedInput) {
@@ -139,17 +190,20 @@ public class ServiceFilterUtils {
.anyMatch(property -> isPropertyConstraintChangedByInput(property, changedInput));
}
- private static boolean isPropertyConstraintChangedByInput(RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition,
- InputDefinition changedInput) {
- List<String> constraints = requirementNodeFilterPropertyDataDefinition.getConstraints();
+ private static boolean isPropertyConstraintChangedByInput(final PropertyFilterDataDefinition propertyFilterDataDefinition,
+ final InputDefinition changedInput) {
+ final List<PropertyFilterConstraintDataDefinition> constraints = propertyFilterDataDefinition.getConstraints();
return constraints.stream().anyMatch(constraint -> isConstraintChangedByInput(constraint, changedInput));
}
- private static boolean isConstraintChangedByInput(String constraint, InputDefinition changedInput) {
- UIConstraint uiConstraint = new ConstraintConvertor().convert(constraint);
- if (!uiConstraint.getSourceType().equals(ConstraintConvertor.SERVICE_INPUT_CONSTRAINT)) {
- return false;
+ private static boolean isConstraintChangedByInput(final PropertyFilterConstraintDataDefinition constraint, final InputDefinition changedInput) {
+ if (constraint.getValueType() == FilterValueType.GET_INPUT) {
+ final ToscaFunction toscaFunction = new FilterConstraintMapper().parseValueToToscaFunction(constraint.getValue()).orElse(null);
+ if (toscaFunction != null) {
+ final ToscaGetFunctionDataDefinition toscaGetFunction = (ToscaGetFunctionDataDefinition) toscaFunction;
+ return toscaGetFunction.getPropertyPathFromSource().contains(changedInput.getName());
+ }
}
- return uiConstraint.getValue().equals(changedInput.getName());
+ return false;
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServlet.java
index c66bb8a8ec..87de704750 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServlet.java
@@ -25,7 +25,6 @@ import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
-import io.swagger.v3.oas.annotations.tags.Tags;
import java.util.Optional;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -47,17 +46,19 @@ import org.openecomp.sdc.be.components.impl.ComponentNodeFilterBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
-import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
+import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
import org.openecomp.sdc.be.tosca.utils.NodeFilterConverter;
+import org.openecomp.sdc.be.ui.mapper.FilterConstraintMapper;
import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.Constants;
@@ -65,7 +66,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Path("/v1/catalog")
-@Tags({@Tag(name = "SDCE-2 APIs")})
+@Tag(name = "SDCE-2 APIs")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Singleton
@@ -122,21 +123,20 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet {
final User userModifier = componentNodeFilterBusinessLogic.validateUser(userId);
final ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
try {
- final Optional<UIConstraint> convertResponse = componentsUtils.parseToConstraint(constraintData, userModifier, componentTypeEnum);
- if (convertResponse.isEmpty()) {
- LOGGER.error(FAILED_TO_PARSE_COMPONENT);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
final Optional<NodeFilterConstraintType> nodeFilterConstraintType = NodeFilterConstraintType.parse(constraintType);
if (nodeFilterConstraintType.isEmpty()) {
return buildErrorResponse(
getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT_PARAM, INVALID_NODE_FILTER_CONSTRAINT_TYPE, constraintType));
}
- final UIConstraint uiConstraint = convertResponse.get();
- final String constraint = new ConstraintConvertor().convert(uiConstraint);
+ final UIConstraint uiConstraint = componentsUtils.parseToConstraint(constraintData, userModifier, componentTypeEnum).orElse(null);
+ if (uiConstraint == null) {
+ LOGGER.error(FAILED_TO_PARSE_COMPONENT);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ final FilterConstraintDto filterConstraintDto = new FilterConstraintMapper().mapFrom(uiConstraint);
final Optional<CINodeFilterDataDefinition> actionResponse = componentNodeFilterBusinessLogic
- .addNodeFilter(componentId.toLowerCase(), componentInstanceId, NodeFilterConstraintAction.ADD, uiConstraint.getServicePropertyName(),
- constraint, true, componentTypeEnum, nodeFilterConstraintType.get(),
+ .addNodeFilter(componentId.toLowerCase(), componentInstanceId,
+ filterConstraintDto, true, componentTypeEnum, nodeFilterConstraintType.get(),
StringUtils.isEmpty(uiConstraint.getCapabilityName()) ? "" : uiConstraint.getCapabilityName());
if (actionResponse.isEmpty()) {
LOGGER.error(FAILED_TO_CREATE_NODE_FILTER);
@@ -144,6 +144,10 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet {
}
return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
new NodeFilterConverter().convertToUi(actionResponse.get()));
+ } catch (final ComponentException e) {
+ throw e;
+ } catch (final BusinessLogicException e) {
+ return buildErrorResponse(e.getResponseFormat());
} catch (final Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError(NODE_FILTER_CREATION);
LOGGER.error(CREATE_NODE_FILTER_WITH_AN_ERROR, e);
@@ -236,7 +240,7 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet {
getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT_PARAM, INVALID_NODE_FILTER_CONSTRAINT_TYPE, constraintType));
}
final Optional<CINodeFilterDataDefinition> actionResponse = componentNodeFilterBusinessLogic
- .deleteNodeFilter(componentId.toLowerCase(), componentInstanceId, NodeFilterConstraintAction.DELETE, null, index, true,
+ .deleteNodeFilter(componentId.toLowerCase(), componentInstanceId, index, true,
ComponentTypeEnum.findByParamName(componentType), nodeFilterConstraintType.get());
if (actionResponse.isEmpty()) {
LOGGER.debug(FAILED_TO_DELETE_NODE_FILTER);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServlet.java
index 067e68bcb8..596237065f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServlet.java
@@ -25,9 +25,9 @@ import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
-import io.swagger.v3.oas.annotations.tags.Tags;
import java.util.List;
import java.util.Optional;
+import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest;
@@ -48,16 +48,18 @@ import org.openecomp.sdc.be.components.impl.ComponentSubstitutionFilterBusinessL
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
import org.openecomp.sdc.be.tosca.utils.SubstitutionFilterConverter;
+import org.openecomp.sdc.be.ui.mapper.FilterConstraintMapper;
import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.be.ui.model.UINodeFilter;
import org.openecomp.sdc.be.user.UserBusinessLogic;
@@ -66,7 +68,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Path("/v1/catalog/{componentType}/{componentId}/substitutionFilter/{constraintType}")
-@Tags({@Tag(name = "SDCE-2 APIs")})
+@Tag(name = "SDCE-2 APIs")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Singleton
@@ -79,13 +81,17 @@ public class ComponentSubstitutionFilterServlet extends AbstractValidationsServl
private static final String INVALID_CONSTRAINTYPE_ENUM = "Invalid value for NodeFilterConstraintType enum %s";
private static final String FAILED_TO_ADD_SUBSTITUTION_FILTER = "Failed to add substitution filter";
private static final String ADD_SUBSTITUTION_FILTER = "Add Substitution Filter";
- private static final String ADD_SUBSTITUTION_FILTER_WITH_AN_ERROR = "Add substitution filter with an error";
+ private static final String ADD_SUBSTITUTION_FILTER_WITH_AN_ERROR = "An unexpected error has occurred while adding a substitution filter";
private static final String FAILED_TO_UPDATE_SUBSTITUTION_FILTER = "Failed to update substitution filter";
private static final String SUBSTITUTION_FILTER_UPDATE = "Substitution Filter Update";
private static final String UPDATE_SUBSTITUTION_FILTER_WITH_AN_ERROR = "Update substitution filter with an error {}";
private static final String FAILED_TO_DELETE_SUBSTITUTION_FILTER = "Failed to delete substitution filter";
private static final String SUBSTITUTION_FILTER_DELETE = "Substitution Filter Delete";
private static final String DELETE_SUBSTITUTION_FILTER_WITH_AN_ERROR = "Delete substitution filter with an error";
+ private static final List<ComponentTypeEnum> EXPECTED_COMPONENT_TYPES = List.of(ComponentTypeEnum.SERVICE, ComponentTypeEnum.RESOURCE);
+ private static final String EXPECTED_COMPONENT_TYPES_AS_STRING = EXPECTED_COMPONENT_TYPES.stream()
+ .map(ComponentTypeEnum::findParamByType)
+ .collect(Collectors.joining(", "));
private final ComponentSubstitutionFilterBusinessLogic componentSubstitutionFilterBusinessLogic;
@Inject
@@ -125,21 +131,22 @@ public class ComponentSubstitutionFilterServlet extends AbstractValidationsServl
LOGGER.error(FAILED_TO_PARSE_COMPONENT);
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
- final UIConstraint uiConstraint = convertResponse.get();
- final String constraint = new ConstraintConvertor().convert(uiConstraint);
+ final FilterConstraintDto filterConstraintDto = new FilterConstraintMapper().mapFrom(convertResponse.get());
final Optional<NodeFilterConstraintType> nodeFilterConstraintType = NodeFilterConstraintType.parse(constraintType);
if (nodeFilterConstraintType.isEmpty()) {
return buildErrorResponse(
getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT_PARAM, INVALID_CONSTRAINTYPE_ENUM, constraintType));
}
final Optional<SubstitutionFilterDataDefinition> actionResponse = componentSubstitutionFilterBusinessLogic
- .addSubstitutionFilter(componentId.toLowerCase(), uiConstraint.getServicePropertyName(), constraint, true, componentTypeEnum);
+ .addSubstitutionFilter(componentId.toLowerCase(), filterConstraintDto, true, componentTypeEnum);
if (actionResponse.isEmpty()) {
LOGGER.error(FAILED_TO_ADD_SUBSTITUTION_FILTER);
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
final UINodeFilter uiFilter = new SubstitutionFilterConverter().convertToUi(actionResponse.get());
return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), uiFilter);
+ } catch (final BusinessLogicException e) {
+ return buildErrorResponse(e.getResponseFormat());
} catch (final Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError(ADD_SUBSTITUTION_FILTER);
LOGGER.error(ADD_SUBSTITUTION_FILTER_WITH_AN_ERROR, e);
@@ -156,11 +163,67 @@ public class ComponentSubstitutionFilterServlet extends AbstractValidationsServl
@ApiResponse(responseCode = "403", description = "Restricted operation"),
@ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
- public Response updateSubstitutionFilter(@Parameter(description = "UIConstraint data", required = true) String constraintData,
+ public Response updateSubstitutionFilters(@Parameter(description = "UIConstraint data", required = true) String constraintData,
+ @Parameter(description = "Component Id") @PathParam("componentId") String componentId,
+ @Parameter(description = "valid value: resources / services", schema = @Schema(allowableValues = {
+ ComponentTypeEnum.SERVICE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("componentType") final String componentType,
+ @Parameter(description = "Constraint type. Valid values: properties / capabilities", schema = @Schema(allowableValues = {
+ NodeFilterConstraintType.PROPERTIES_PARAM_NAME,
+ NodeFilterConstraintType.CAPABILITIES_PARAM_NAME})) @PathParam("constraintType") final String constraintType,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ LOGGER.debug(START_HANDLE_REQUEST_OF, request.getMethod(), request.getRequestURI());
+ LOGGER.debug(MODIFIER_ID_IS, userId);
+ final User userModifier = componentSubstitutionFilterBusinessLogic.validateUser(userId);
+ try {
+ final ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ final List<UIConstraint> uiConstraints = componentsUtils.validateAndParseConstraint(componentTypeEnum, constraintData, userModifier);
+ if (CollectionUtils.isEmpty(uiConstraints)) {
+ LOGGER.error("Failed to Parse Constraint data {} when executing {} ", constraintData, SUBSTITUTION_FILTER_UPDATE);
+ return buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR, "Failed to parse constraint data"));
+ }
+ final List<FilterConstraintDto> filterConstraintList = uiConstraints.stream()
+ .map(uiConstraint -> new FilterConstraintMapper().mapFrom(uiConstraint))
+ .collect(Collectors.toList());
+ final Optional<NodeFilterConstraintType> nodeFilterConstraintType = NodeFilterConstraintType.parse(constraintType);
+ if (nodeFilterConstraintType.isEmpty()) {
+ return buildErrorResponse(
+ getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT_PARAM, INVALID_CONSTRAINTYPE_ENUM, constraintType));
+ }
+ final Optional<SubstitutionFilterDataDefinition> actionResponse = componentSubstitutionFilterBusinessLogic
+ .updateSubstitutionFilter(componentId.toLowerCase(), filterConstraintList, true, componentTypeEnum);
+ if (actionResponse.isEmpty()) {
+ LOGGER.error(FAILED_TO_UPDATE_SUBSTITUTION_FILTER);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ new SubstitutionFilterConverter().convertToUi(actionResponse.get()));
+ } catch (final BusinessLogicException e) {
+ return buildErrorResponse(e.getResponseFormat());
+ } catch (final Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(SUBSTITUTION_FILTER_UPDATE);
+ LOGGER.error(UPDATE_SUBSTITUTION_FILTER_WITH_AN_ERROR, e.getMessage(), e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @PUT
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/{constraintIndex}")
+ @Operation(description = "Update Component Substitution Filter Constraint", method = "PUT", summary = "Update Component Substitution Filter Constraint", responses = {
+ @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
+ @ApiResponse(responseCode = "201", description = "Update Substitution Filter Constraint"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateSubstitutionFilter(@Parameter(description = "Filter constraint information", required = true) UIConstraint uiConstraint,
+ @Parameter(description = "Constraint Index") @PathParam("constraintIndex") int index,
@Parameter(description = "Component Id") @PathParam("componentId") String componentId,
- @Parameter(description = "valid value: resources / services", schema = @Schema(allowableValues = {
+ @Parameter(description = "The component type", schema = @Schema(allowableValues = {
ComponentTypeEnum.SERVICE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("componentType") final String componentType,
+ ComponentTypeEnum.RESOURCE_PARAM_NAME})) @PathParam("componentType") final String componentType,
@Parameter(description = "Constraint type. Valid values: properties / capabilities", schema = @Schema(allowableValues = {
NodeFilterConstraintType.PROPERTIES_PARAM_NAME,
NodeFilterConstraintType.CAPABILITIES_PARAM_NAME})) @PathParam("constraintType") final String constraintType,
@@ -168,28 +231,32 @@ public class ComponentSubstitutionFilterServlet extends AbstractValidationsServl
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
LOGGER.debug(START_HANDLE_REQUEST_OF, request.getMethod(), request.getRequestURI());
LOGGER.debug(MODIFIER_ID_IS, userId);
- final User userModifier = componentSubstitutionFilterBusinessLogic.validateUser(userId);
+ componentSubstitutionFilterBusinessLogic.validateUser(userId);
try {
final ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
- final List<UIConstraint> uiConstraints = componentsUtils.validateAndParseConstraint(componentTypeEnum, constraintData, userModifier);
- if (CollectionUtils.isEmpty(uiConstraints)) {
- LOGGER.error("Failed to Parse Constraint data {} when executing {} ", constraintData, SUBSTITUTION_FILTER_UPDATE);
- return buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR, "Failed to parse constraint data"));
+ if (componentTypeEnum == null || !EXPECTED_COMPONENT_TYPES.contains(componentTypeEnum)) {
+ return buildErrorResponse(
+ getComponentsUtils().getResponseFormat(ActionStatus.INVALID_COMPONENT_TYPE, componentType, EXPECTED_COMPONENT_TYPES_AS_STRING));
}
- final List<String> constraints = new ConstraintConvertor().convertToList(uiConstraints);
final Optional<NodeFilterConstraintType> nodeFilterConstraintType = NodeFilterConstraintType.parse(constraintType);
- if (!nodeFilterConstraintType.isPresent()) {
+ if (nodeFilterConstraintType.isEmpty()) {
return buildErrorResponse(
getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT_PARAM, INVALID_CONSTRAINTYPE_ENUM, constraintType));
}
+ final FilterConstraintDto filterConstraintDto = new FilterConstraintMapper().mapFrom(uiConstraint);
+
final Optional<SubstitutionFilterDataDefinition> actionResponse = componentSubstitutionFilterBusinessLogic
- .updateSubstitutionFilter(componentId.toLowerCase(), constraints, true, componentTypeEnum);
- if (!actionResponse.isPresent()) {
+ .updateSubstitutionFilter(componentId.toLowerCase(), filterConstraintDto, index , true);
+ if (actionResponse.isEmpty()) {
LOGGER.error(FAILED_TO_UPDATE_SUBSTITUTION_FILTER);
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
new SubstitutionFilterConverter().convertToUi(actionResponse.get()));
+ } catch (final BusinessLogicException e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(SUBSTITUTION_FILTER_UPDATE);
+ LOGGER.error(UPDATE_SUBSTITUTION_FILTER_WITH_AN_ERROR, e.getMessage(), e);
+ return buildErrorResponse(e.getResponseFormat());
} catch (final Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError(SUBSTITUTION_FILTER_UPDATE);
LOGGER.error(UPDATE_SUBSTITUTION_FILTER_WITH_AN_ERROR, e.getMessage(), e);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
index 25d0287d54..f3327d7206 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -71,11 +71,13 @@ import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
+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.elements.RequirementSubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunction;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
@@ -1044,11 +1046,10 @@ public class ToscaExportHandler {
private Object convertToToscaObject(String value) {
try {
ToscaMapValueConverter mapConverterInst = ToscaMapValueConverter.getInstance();
- JsonParser jsonParser = new JsonParser();
StringReader reader = new StringReader(value);
JsonReader jsonReader = new JsonReader(reader);
jsonReader.setLenient(true);
- JsonElement jsonElement = jsonParser.parse(jsonReader);
+ JsonElement jsonElement = JsonParser.parseReader(jsonReader);
if (jsonElement.isJsonObject()) {
JsonObject jsonObj = jsonElement.getAsJsonObject();
if (jsonObj.entrySet().size() == 1 && jsonObj.has(ToscaFunctions.GET_INPUT.getFunctionName())) {
@@ -1613,14 +1614,13 @@ public class ToscaExportHandler {
}
NodeFilter nodeFilter = new NodeFilter();
ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> origCapabilities = inNodeFilter.getCapabilities();
- ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> origProperties = inNodeFilter.getProperties();
+ ListDataDefinition<PropertyFilterDataDefinition> origProperties = inNodeFilter.getProperties();
List<Map<String, CapabilityFilter>> capabilitiesCopy = new ArrayList<>();
- List<Map<String, List<Object>>> propertiesCopy = new ArrayList<>();
copyNodeFilterCapabilitiesTemplate(origCapabilities, capabilitiesCopy);
- copyNodeFilterProperties(origProperties, propertiesCopy);
if (CollectionUtils.isNotEmpty(capabilitiesCopy)) {
nodeFilter.setCapabilities(capabilitiesCopy);
}
+ final List<Map<String, List<Object>>> propertiesCopy = copyNodeFilterProperties(origProperties);
if (CollectionUtils.isNotEmpty(propertiesCopy)) {
nodeFilter.setProperties(propertiesCopy);
}
@@ -1634,10 +1634,8 @@ public class ToscaExportHandler {
return null;
}
NodeFilter nodeFilter = new NodeFilter();
- ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> origProperties = substitutionFilterDataDefinition.getProperties();
- List<Map<String, List<Object>>> propertiesCopy = new ArrayList<>();
- copySubstitutionFilterProperties(origProperties, propertiesCopy);
- if (CollectionUtils.isNotEmpty(propertiesCopy)) {
+ final List<Map<String, List<Object>>> propertiesCopy = copySubstitutionPropertiesFilter(substitutionFilterDataDefinition.getProperties());
+ if (!propertiesCopy.isEmpty()) {
nodeFilter.setProperties(propertiesCopy);
}
nodeFilter.setTosca_id(cloneToscaId(substitutionFilterDataDefinition.getTosca_id()));
@@ -1661,81 +1659,71 @@ public class ToscaExportHandler {
}
for (RequirementNodeFilterCapabilityDataDefinition capability : origCapabilities.getListToscaDataDefinition()) {
Map<String, CapabilityFilter> capabilityFilterCopyMap = new HashMap<>();
- CapabilityFilter capabilityFilter = new CapabilityFilter();
- List<Map<String, List<Object>>> propertiesCopy = new ArrayList<>();
- copyNodeFilterProperties(capability.getProperties(), propertiesCopy);
- capabilityFilter.setProperties(propertiesCopy);
+ final var capabilityFilter = new CapabilityFilter();
+ capabilityFilter.setProperties(copyNodeFilterProperties(capability.getProperties()));
capabilityFilterCopyMap.put(capability.getName(), capabilityFilter);
capabilitiesCopy.add(capabilityFilterCopyMap);
}
}
- private void copyNodeFilterProperties(ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> origProperties,
- List<Map<String, List<Object>>> propertiesCopy) {
+ private List<Map<String, List<Object>>> copyNodeFilterProperties(final ListDataDefinition<PropertyFilterDataDefinition> origProperties) {
if (origProperties == null || origProperties.getListToscaDataDefinition() == null || origProperties.isEmpty()) {
- return;
+ return Collections.emptyList();
}
- Map<String, List<Object>> propertyMapCopy = new HashMap<>();
- for (RequirementNodeFilterPropertyDataDefinition propertyDataDefinition : origProperties.getListToscaDataDefinition()) {
- for (String propertyInfoEntry : propertyDataDefinition.getConstraints()) {
- Map<String, List<Object>> propertyValObj = new YamlUtil().yamlToObject(propertyInfoEntry, Map.class);
- String propertyName = propertyDataDefinition.getName();
- if (propertyMapCopy.containsKey(propertyName)) {
- addPropertyConstraintValueToList(propertyName, propertyValObj, propertyMapCopy.get(propertyName));
- } else {
- if (propertyName != null) {
- List<Object> propsList = new ArrayList<>();
- addPropertyConstraintValueToList(propertyName, propertyValObj, propsList);
- propertyMapCopy.put(propertyName, propsList);
- } else {
- propertyMapCopy.putAll(propertyValObj);
+ List<Map<String, List<Object>>> propertiesCopy = new ArrayList<>();
+ Map<String, List<Object>> propertyFilterDefinitionMap = new HashMap<>();
+ for (final PropertyFilterDataDefinition propertyFilter : origProperties.getListToscaDataDefinition()) {
+ final String propertyName = propertyFilter.getName();
+ for (final PropertyFilterConstraintDataDefinition filterConstraint : propertyFilter.getConstraints()) {
+ propertyFilterDefinitionMap.compute(propertyName, (propertyName1, constraints) -> {
+ if (constraints == null) {
+ constraints = new ArrayList<>();
}
- }
+ constraints.add(buildNodeFilterValue(filterConstraint));
+ return constraints;
+ });
}
}
- propertyMapCopy.entrySet().stream().forEach(entry -> addCalculatedConstraintsIntoPropertiesList(propertiesCopy, entry));
+ propertyFilterDefinitionMap.entrySet().stream()
+ .map(entry -> Map.of(entry.getKey(), entry.getValue()))
+ .forEach(propertiesCopy::add);
+ return propertiesCopy;
}
- private void copySubstitutionFilterProperties(final ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> origProperties,
- final List<Map<String, List<Object>>> propertiesCopy) {
+ private List<Map<String, List<Object>>> copySubstitutionPropertiesFilter(
+ final ListDataDefinition<SubstitutionFilterPropertyDataDefinition> origProperties) {
+
if (origProperties == null || origProperties.getListToscaDataDefinition() == null || origProperties.isEmpty()) {
- return;
+ return Collections.emptyList();
}
- final Map<String, List<Object>> propertyMapCopy = new HashMap<>();
- for (final RequirementSubstitutionFilterPropertyDataDefinition propertyDataDefinition : origProperties.getListToscaDataDefinition()) {
- for (final String propertyInfoEntry : propertyDataDefinition.getConstraints()) {
- final Map<String, List<Object>> propertyValObj = new YamlUtil().yamlToObject(propertyInfoEntry, Map.class);
- final String propertyName = propertyDataDefinition.getName();
- if (propertyMapCopy.containsKey(propertyName)) {
- addPropertyConstraintValueToList(propertyName, propertyValObj, propertyMapCopy.get(propertyName));
- } else {
- if (propertyName != null) {
- final List<Object> propsList = new ArrayList<>();
- addPropertyConstraintValueToList(propertyName, propertyValObj, propsList);
- propertyMapCopy.put(propertyName, propsList);
- } else {
- propertyMapCopy.putAll(propertyValObj);
+ List<Map<String, List<Object>>> propertiesCopy = new ArrayList<>();
+ Map<String, List<Object>> propertyFilterDefinitionMap = new HashMap<>();
+ for (final SubstitutionFilterPropertyDataDefinition propertyFilter : origProperties.getListToscaDataDefinition()) {
+ final String propertyName = propertyFilter.getName();
+ for (final PropertyFilterConstraintDataDefinition filterConstraint : propertyFilter.getConstraints()) {
+ propertyFilterDefinitionMap.compute(propertyName, (propertyName1, constraints) -> {
+ if (constraints == null) {
+ constraints = new ArrayList<>();
}
- }
+ constraints.add(buildNodeFilterValue(filterConstraint));
+ return constraints;
+ });
}
}
- propertyMapCopy.entrySet().forEach(entry -> addCalculatedConstraintsIntoPropertiesList(propertiesCopy, entry));
+ propertyFilterDefinitionMap.entrySet().stream()
+ .map(entry -> Map.of(entry.getKey(), entry.getValue()))
+ .forEach(propertiesCopy::add);
+ return propertiesCopy;
}
- private void addPropertyConstraintValueToList(String propertyName, Map<String, List<Object>> propertyValObj, List<Object> propsList) {
- if (propertyValObj.containsKey(propertyName)) {
- propsList.add(propertyValObj.get(propertyName));
+ private static Object buildNodeFilterValue(final PropertyFilterConstraintDataDefinition filterConstraint) {
+ if (filterConstraint.getValue() instanceof ToscaFunction) {
+ return Map.of(filterConstraint.getOperator().getType(), ((ToscaFunction) filterConstraint.getValue()).getJsonObjectValue());
} else {
- propsList.add(propertyValObj);
+ return Map.of(filterConstraint.getOperator().getType(), filterConstraint.getValue());
}
}
- private void addCalculatedConstraintsIntoPropertiesList(List<Map<String, List<Object>>> propertiesCopy, Entry<String, List<Object>> entry) {
- Map<String, List<Object>> tempMap = new HashMap<>();
- tempMap.put(entry.getKey(), entry.getValue());
- propertiesCopy.add(tempMap);
- }
-
private Map<String, String[]> buildSubstitutionMappingPropertyMapping(final Component component) {
if (component == null || CollectionUtils.isEmpty(component.getInputs())) {
return Collections.emptyMap();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraint.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraint.java
index ab1137342d..6049be2fd6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraint.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraint.java
@@ -18,7 +18,7 @@
*/
package org.openecomp.sdc.be.tosca.model;
-import org.openecomp.sdc.be.model.tosca.constraints.ConstraintType;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
/**
* Represents a Tosca Property Constraint
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 e7bade9421..8e73f6985b 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
@@ -22,7 +22,7 @@ import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
-import org.openecomp.sdc.be.model.tosca.constraints.ConstraintType;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
/**
* Represents a tosca valid_values constraint
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java
index 48932fefd7..6ef6c0dc3c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java
@@ -19,11 +19,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
-import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
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.model.dto.FilterConstraintDto;
+import org.openecomp.sdc.be.ui.mapper.FilterConstraintMapper;
import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.be.ui.model.UINodeFilter;
@@ -35,36 +36,38 @@ public class NodeFilterConverter {
public UINodeFilter convertToUi(final CINodeFilterDataDefinition inNodeFilter) {
final UINodeFilter uiNodeFilter = new UINodeFilter();
- final ConstraintConvertor constraintConvertor = new ConstraintConvertor();
- final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> nodeFilterProperties = inNodeFilter.getProperties();
+
+ final ListDataDefinition<PropertyFilterDataDefinition> nodeFilterProperties = inNodeFilter.getProperties();
if (nodeFilterProperties != null && !nodeFilterProperties.isEmpty()) {
- final List<UIConstraint> propertiesConstraint = nodeFilterProperties.getListToscaDataDefinition().stream().map(property -> {
- if(property.getType() != null) {
- return constraintConvertor.convert(property.getConstraints().iterator().next(), property.getType());
- } else {
- return constraintConvertor.convert(property.getConstraints().iterator().next());
- }}).collect(Collectors.toList());
+ final var filterConstraintMapper = new FilterConstraintMapper();
+ final List<UIConstraint> propertiesConstraint = nodeFilterProperties.getListToscaDataDefinition().stream()
+ .map(property -> property.getConstraints().iterator().next())
+ .map(filterConstraintMapper::mapFrom)
+ .map(filterConstraintMapper::mapToUiConstraint)
+ .collect(Collectors.toList());
uiNodeFilter.setProperties(propertiesConstraint);
}
final ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> nodeFilterCapabilities = inNodeFilter.getCapabilities();
if (nodeFilterCapabilities != null && !nodeFilterCapabilities.isEmpty()) {
final List<UIConstraint> capabilitiesConstraint = new ArrayList<>();
- nodeFilterCapabilities.getListToscaDataDefinition().forEach(
- requirementNodeFilterCapabilityDataDefinition -> convertCapabilityConstraint(requirementNodeFilterCapabilityDataDefinition,
- capabilitiesConstraint));
+ nodeFilterCapabilities.getListToscaDataDefinition()
+ .forEach(requirementNodeFilterCapabilityDataDefinition ->
+ capabilitiesConstraint.addAll(convertCapabilityConstraint(requirementNodeFilterCapabilityDataDefinition))
+ );
uiNodeFilter.setCapabilities(capabilitiesConstraint);
}
return uiNodeFilter;
}
- private void convertCapabilityConstraint(final RequirementNodeFilterCapabilityDataDefinition requirementNodeFilterCapabilityDataDefinition,
- final List<UIConstraint> capabilitiesConstraint) {
- final ConstraintConvertor constraintConvertor = new ConstraintConvertor();
- requirementNodeFilterCapabilityDataDefinition.getProperties().getListToscaDataDefinition().forEach(property -> {
+ private List<UIConstraint> convertCapabilityConstraint(final RequirementNodeFilterCapabilityDataDefinition nodeFilterCapability) {
+ final var filterConstraintMapper = new FilterConstraintMapper();
+ final List<UIConstraint> uiConstraints = new ArrayList<>();
+ nodeFilterCapability.getProperties().getListToscaDataDefinition().forEach(property -> {
final UIConstraint uiConstraint = new UIConstraint();
- uiConstraint.setCapabilityName(requirementNodeFilterCapabilityDataDefinition.getName());
- capabilitiesConstraint.add(
- constraintConvertor.getUiConstraint(property.getConstraints().iterator().next(), uiConstraint));
+ uiConstraint.setCapabilityName(nodeFilterCapability.getName());
+ final FilterConstraintDto filterConstraintDto = filterConstraintMapper.mapFrom(property.getConstraints().iterator().next());
+ uiConstraints.add(filterConstraintMapper.mapToUiConstraint(filterConstraintDto));
});
+ return uiConstraints;
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/SubstitutionFilterConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/SubstitutionFilterConverter.java
index c083099629..562e4ea8fd 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/SubstitutionFilterConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/SubstitutionFilterConverter.java
@@ -22,11 +22,11 @@ import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
-import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterCapabilityDataDefinition;
-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.ui.mapper.FilterConstraintMapper;
import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.be.ui.model.UINodeFilter;
@@ -34,39 +34,45 @@ public class SubstitutionFilterConverter {
public UINodeFilter convertToUi(final SubstitutionFilterDataDefinition inSubstitutionFilter) {
final UINodeFilter uiNodeFilter = new UINodeFilter();
- final ConstraintConvertor constraintConvertor = new ConstraintConvertor();
- final List<UIConstraint> uiPropertyFilters = extractPropertyFilter(inSubstitutionFilter, constraintConvertor);
+
+ final List<UIConstraint> uiPropertyFilters = extractPropertyFilter(inSubstitutionFilter);
if (!uiPropertyFilters.isEmpty()) {
uiNodeFilter.setProperties(uiPropertyFilters);
}
- final List<UIConstraint> uiCapabilityFilters = extractCapabilitiesFilter(inSubstitutionFilter, constraintConvertor);
+ final List<UIConstraint> uiCapabilityFilters = extractCapabilitiesFilter(inSubstitutionFilter);
if (!uiCapabilityFilters.isEmpty()) {
uiNodeFilter.setCapabilities(uiCapabilityFilters);
}
return uiNodeFilter;
}
- private List<UIConstraint> extractPropertyFilter(final SubstitutionFilterDataDefinition substitutionFilter,
- final ConstraintConvertor constraintConvertor) {
- final ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> substitutionFilterProperties = substitutionFilter
+ private List<UIConstraint> extractPropertyFilter(final SubstitutionFilterDataDefinition substitutionFilter) {
+ final ListDataDefinition<SubstitutionFilterPropertyDataDefinition> substitutionFilterProperties = substitutionFilter
.getProperties();
if (substitutionFilterProperties != null && !substitutionFilterProperties.isEmpty() && CollectionUtils
.isNotEmpty(substitutionFilterProperties.getListToscaDataDefinition())) {
- return substitutionFilterProperties.getListToscaDataDefinition().stream().map(property -> property.getConstraints().iterator().next())
- .map(constraintConvertor::convert).collect(Collectors.toList());
+ final var filterConstraintMapper = new FilterConstraintMapper();
+ return substitutionFilterProperties.getListToscaDataDefinition().stream()
+ .map(property -> property.getConstraints().iterator().next())
+ .map(filterConstraintMapper::mapFrom)
+ .map(filterConstraintMapper::mapToUiConstraint)
+ .collect(Collectors.toList());
}
return Collections.emptyList();
}
- private List<UIConstraint> extractCapabilitiesFilter(final SubstitutionFilterDataDefinition substitutionFilter,
- final ConstraintConvertor constraintConvertor) {
+ private List<UIConstraint> extractCapabilitiesFilter(final SubstitutionFilterDataDefinition substitutionFilter) {
final ListDataDefinition<RequirementSubstitutionFilterCapabilityDataDefinition> substitutionFilterCapabilities = substitutionFilter
.getCapabilities();
if (substitutionFilterCapabilities != null && !substitutionFilterCapabilities.isEmpty() && CollectionUtils
.isNotEmpty(substitutionFilterCapabilities.getListToscaDataDefinition())) {
+ final var filterConstraintMapper = new FilterConstraintMapper();
return substitutionFilterCapabilities.getListToscaDataDefinition().stream()
.map(capabilities -> capabilities.getProperties().getListToscaDataDefinition().iterator().next())
- .map(property -> property.getConstraints().iterator().next()).map(constraintConvertor::convert).collect(Collectors.toList());
+ .map(property -> property.getConstraints().iterator().next())
+ .map(filterConstraintMapper::mapFrom)
+ .map(filterConstraintMapper::mapToUiConstraint)
+ .collect(Collectors.toList());
}
return Collections.emptyList();
}
diff --git a/catalog-be/src/main/resources/config/error-configuration.yaml b/catalog-be/src/main/resources/config/error-configuration.yaml
index 96bfa245e3..81e302f8bd 100644
--- a/catalog-be/src/main/resources/config/error-configuration.yaml
+++ b/catalog-be/src/main/resources/config/error-configuration.yaml
@@ -111,7 +111,7 @@ errors:
message: "Error: Invalid userId '%1'.",
messageId: "SVC4008"
}
-#---------SVC4009-----------------------------
+ #---------SVC4009-----------------------------
USER_DEFINED: {
code: 400,
message: "Error: User Defined '%1'.",
@@ -1436,10 +1436,10 @@ errors:
message: "Error: artifact %1 is defined in CSAR %2 manifest but is not provided",
messageId: "SVC4618"
}
-#---------SVC4619------------------------------
-# %1 - artifact name
-# %2 - artifact type
-# %3 - existing artifact type
+ #---------SVC4619------------------------------
+ # %1 - artifact name
+ # %2 - artifact type
+ # %3 - existing artifact type
ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR: {
code: 400,
message: "Error: artifact %1 in type %2 already exists in type %3.",
@@ -1803,9 +1803,11 @@ errors:
messageId: "SVC4669"
}
#---------SVC4670------------------------------
+ # %1 - artifactname
+ # %2 - validname
ARTIFACT_NAME_INVALID: {
code: 400,
- message: "Error: Artifact name is invalid.",
+ message: "Error: Artifact name '%1' is invalid. Only the following characters are allowed in the Artifact Name: '%2'.",
messageId: "SVC4670"
}
#---------SVC4671------------------------------
@@ -2010,29 +2012,29 @@ errors:
#---------SVC4695-----------------------------
# %1 - Interface Operation Name
INTERFACE_OPERATION_NAME_ALREADY_IN_USE: {
- code: 409,
- message: "Error: Interface Operation name '%1' already in use, Your current changes will not be saved.",
- messageId: "SVC4695"
+ code: 409,
+ message: "Error: Interface Operation name '%1' already in use, Your current changes will not be saved.",
+ messageId: "SVC4695"
}
#---------SVC4696-----------------------------
# %1 - Interface Operation Name
INTERFACE_OPERATION_NAME_INVALID: {
- code: 400,
- message: "Error: Interface Operation name '%1' is Invalid, Operation name should not contain special character, space and should not be greater than 200 characters.",
- messageId: "SVC4696"
+ code: 400,
+ message: "Error: Interface Operation name '%1' is Invalid, Operation name should not contain special character, space and should not be greater than 200 characters.",
+ messageId: "SVC4696"
}
#---------SVC4697-----------------------------
INTERFACE_OPERATION_NAME_MANDATORY: {
- code: 400,
- message: "Error: Interface Operation name is mandatory, Operation name can't be empty.",
- messageId: "SVC4697"
+ code: 400,
+ message: "Error: Interface Operation name is mandatory, Operation name can't be empty.",
+ messageId: "SVC4697"
}
-#---------SVC4698-----------------------------
-# %1 - Interface type
+ #---------SVC4698-----------------------------
+ # %1 - Interface type
INTERFACE_OPERATION_INVALID_FOR_LOCAL_TYPE: {
- code: 400,
- message: "Error: Invalid input, only one operation is allowed in local interface type '%1'.",
- messageId: "SVC4698"
+ code: 400,
+ message: "Error: Invalid input, only one operation is allowed in local interface type '%1'.",
+ messageId: "SVC4698"
}
#---------SVC4699-----------------------------
# %1 - Interface Operation input parameter name
@@ -2047,18 +2049,18 @@ errors:
message: "Error: Interface operation input parameter name should not be empty.",
messageId: "SVC4700"
}
-#---------SVC4701-----------------------------
-# %1 - component Id
+ #---------SVC4701-----------------------------
+ # %1 - component Id
INTERFACE_OPERATION_NOT_FOUND: {
- code: 404,
- message: "Error: Interface operation not found in the component '%1'.",
- messageId: "SVC4701"
+ code: 404,
+ message: "Error: Interface operation not found in the component '%1'.",
+ messageId: "SVC4701"
}
#---------SVC4702-----------------------------
INTERFACE_OPERATION_NOT_DELETED: {
- code: 400,
- message: "Error: Failed to delete interface operation.",
- messageId: "SVC4702"
+ code: 400,
+ message: "Error: Failed to delete interface operation.",
+ messageId: "SVC4702"
}
#SVC4732
INTERFACE_UNKNOWN: {
@@ -2129,32 +2131,32 @@ errors:
message: "Error: CSAR packaging failed for %1 %2.",
messageId: "SVC4706"
}
-#---------SVC4708-----------------------------
-# %1 - Interface Operation input property name, component type
+ #---------SVC4708-----------------------------
+ # %1 - Interface Operation input property name, component type
INTERFACE_OPERATION_INPUT_PROPERTY_NOT_FOUND_IN_COMPONENT: {
code: 404,
message: "Error: Interface operation input parameter property '%1' not found in '%2' input properties, capability properties or outputs of other operations.",
messageId: "SVC4708"
}
-#---------SVC4709-----------------------------
-# %1 - Interface Operation output parameter name
+ #---------SVC4709-----------------------------
+ # %1 - Interface Operation output parameter name
INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE: {
code: 400,
message: "Error: Interface Operation output parameter name '%1' already in use, Your current changes will not be saved.",
messageId: "SVC4708"
}
-#---------SVC4710-----------------------------
+ #---------SVC4710-----------------------------
INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY: {
code: 400,
message: "Error: Interface operation output parameter name should not be empty.",
messageId: "SVC4710"
}
-#---------SVC4711-----------------------------
-# %1 - interface Id
+ #---------SVC4711-----------------------------
+ # %1 - interface Id
INTERFACE_NOT_FOUND_IN_COMPONENT: {
- code: 404,
- message: "Error: Interface not found in the component '%1'.",
- messageId: "SVC4711"
+ code: 404,
+ message: "Error: Interface not found in the component '%1'.",
+ messageId: "SVC4711"
}
#---------SVC4709-----------------------------
INVALID_PROPERTY_CONSTRAINTS: {
@@ -2266,18 +2268,18 @@ errors:
message: "Error: Missing value for the mandatory %1 property" ,
messageId: "SVC4721"
}
-#---------SVC4712-----------------------------
+ #---------SVC4712-----------------------------
INTERFACE_LIFECYCLE_TYPES_NOT_FOUND: {
- code: 404,
- message: "Error: Interface Lifecycle types not found.",
- messageId: "SVC4712"
+ code: 404,
+ message: "Error: Interface Lifecycle types not found.",
+ messageId: "SVC4712"
}
-#---------SVC4713-----------------------------
-# %1 - Interface Operation Name
+ #---------SVC4713-----------------------------
+ # %1 - Interface Operation Name
INTERFACE_OPERATION_INVALID_FOR_GLOBAL_TYPE: {
- code: 400,
- message: "Error: Invalid input, only pre-defined operation names are allowed in global interface type '%1'",
- messageId: "SVC4713"
+ code: 400,
+ message: "Error: Invalid input, only pre-defined operation names are allowed in global interface type '%1'",
+ messageId: "SVC4713"
}
#---------SVC4714-----------------------------
@@ -2300,13 +2302,14 @@ errors:
messageId: "SVC4716"
}
- #---------SVC4717----------------------------
- # %1 - Property Name
- MAPPED_PROPERTY_NOT_FOUND: {
- code: 400,
- message: "Error: %1 property does not exist.",
- messageId: "SVC4717"
- }
+ #---------SVC4184----------------------------
+ # %1 - Source type
+ # %2 - Property Type
+ # %3 - Property Name
+ FILTER_PROPERTY_NOT_FOUND:
+ code: 400
+ message: "%1 %2 %3 does not exist."
+ messageId: "SVC4184"
#---------SVC4718----------------------------
# %1 - Property Name
@@ -2324,13 +2327,13 @@ errors:
messageId: "SVC4719"
}
- #---------SVC4720----------------------------
+ #---------SVC4182----------------------------
# %1 - Property Name
# %2 - Operator Type
SOURCE_TARGET_PROPERTY_TYPE_MISMATCH: {
code: 400,
- message: "Error: %1 property and %2 property type is not same.",
- messageId: "SVC4720"
+ message: "Error: Property '%1' type '%2' does not match with property '%3' type '%4'.",
+ messageId: "SVC4182"
}
#---------SVC4721----------------------------
@@ -2342,78 +2345,471 @@ errors:
messageId: "SVC4721"
}
- #---------SVC4722------------------------------
- # %1 Directive value set
+ #---------SVC4722------------------------------
+ # %1 Directive value set
DIRECTIVES_INVALID_VALUE: {
- code: 404,
- message: "Error: Invalid directive value : '%1' .",
- messageId: "SVC4722"
+ code: 404,
+ message: "Error: Invalid directive value : '%1' .",
+ messageId: "SVC4722"
}
-#---------SVC4723-----------------------------
-# %1 - Interface Operation output name
+ #---------SVC4723-----------------------------
+ # %1 - Interface Operation output name
INTERFACE_OPERATION_MAPPED_OUTPUT_MODIFIED: {
code: 400,
message: "Error: Cannot update or delete interface operation output(s) '%1' mapped to an operation input",
messageId: "SVC4723"
}
-#---------SVC4724-----------------------------
-# %1 - Interface Operation output name
+ #---------SVC4724-----------------------------
+ # %1 - Interface Operation output name
INTERFACE_OPERATION_DELETE_WITH_MAPPED_OUTPUT: {
code: 400,
message: "Error: Cannot delete interface operation with output(s) '%1' mapped to another operation input",
messageId: "SVC4724"
}
-#---------SVC4725-----------------------------
+ #---------SVC4725-----------------------------
INVALID_CONSUMPTION_TYPE: {
code: 400,
message: "Error: Given value is different than input type. Needs to be %1",
messageId: "SVC4725"
}
-#---------SVC4726-----------------------------
+ #---------SVC4726-----------------------------
INVALID_PROPERTY_VALUES: {
code: 400,
message: "Error: Invalid property values provided:\n %1",
messageId: "SVC4726"
}
-#---------SVC4727------------------------------
+ #---------SVC4727------------------------------
INVALID_PROPERTY_NAME: {
code: 400,
message: "Error: Property name contains invalid characters. It should have only letters, numbers and underscores.",
messageId: "SVC4727"
}
-#---------SVC4728------------------------------
+ #---------SVC4728------------------------------
FAILED_TO_CREATE_OR_UPDATE_CAPABILITY_PROPERTIES: {
code: 500,
message: "Error: Failed to create or update capabilities properties",
messageId: "SVC4728"
}
-#---------SVC4729------------------------------
+ #---------SVC4729------------------------------
# %1 - resource Id
CAPABILITY_PROPERTIES_NOT_FOUND: {
code: 400,
message: "Error: Capability properties not found in the resource '%1'.",
messageId: "SVC4729"
}
-#---------SVC4730------------------------------
+ #---------SVC4730------------------------------
# %1 - property name
PROPERTY_EXCEEDS_LIMIT: {
- code: 400,
- message: "Error: Invalid Content. %1 exceeds limit.",
- messageId: "SVC4722"
+ code: 400,
+ message: "Error: Invalid Content. %1 exceeds limit.",
+ messageId: "SVC4722"
}
-#---------SVC4731------------------------------
+ #---------SVC4731------------------------------
INVALID_PROPERY: {
# %1 - property name
- code: 400,
- message: 'Error: Invalid Content. %1 has invalid format.',
- messageId: "SVC4723"
+ code: 400,
+ message: 'Error: Invalid Content. %1 has invalid format.',
+ messageId: "SVC4723"
}
-#---------SVC4732------------------------------
+ #---------SVC4734------------------------------
# %1 - list of validation errors
INVALID_PM_DICTIONARY_FILE: {
code: 400,
message: 'Error: Invalid PM Dictionary File. %1',
- messageId: "SVC4732"
- } \ No newline at end of file
+ messageId: "SVC4734"
+ }
+ #-----------SVC4735---------------------------
+ #%1 - input name
+ INPUT_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Input with '%1' name already exists.",
+ messageId: "SVC4735"
+ }
+ #---------SVC4736------------------------------
+ INVALID_INPUT_NAME: {
+ code: 400,
+ message: "Error: Input name contains invalid characters. It should have only letters, numbers and underscores.",
+ messageId: "SVC4736"
+ }
+ #---------SVC4139------------------------------
+ # %1 - The action that is not supported
+ NOT_SUPPORTED: {
+ code: 400,
+ message: '%1 is not yet supported',
+ messageId: "SVC4139"
+ }
+ #---------SVC4140------------------------------
+ # %1 - Component uid
+ COMPONENT_FIND_ERROR: {
+ code: 500,
+ message: "An unexpected error occurred while retrieving the component '%1'.",
+ messageId: "SVC4140"
+ }
+ #---------SVC4141------------------------------
+ # %1 - Component uid
+ COMPONENT_CAPABILITIES_FIND_ERROR: {
+ code: 500,
+ message: "An unexpected error occurred while retrieving the component '%1' capabilities.",
+ messageId: "SVC4141"
+ }
+ #---------SVC4142------------------------------
+ # %1 - Component uid or name
+ COMPONENT_NOT_FOUND: {
+ code: 404,
+ message: "Component '%1' was not found.",
+ messageId: "SVC4142"
+ }
+ #---------SVC4143------------------------------
+ # %1 - Capability name
+ COMPONENT_INSTANCE_CAPABILITY_UPDATE_ERROR: {
+ code: 500,
+ message: "An unexpected error occurred while updating the capability '%1'.",
+ messageId: "SVC4143"
+ }
+
+ #---------SVC4144------------------------------
+ # %1 - "Model name"
+ MODEL_ALREADY_EXISTS: {
+ code: 409,
+ message: "Error: Model name '%1' already exists.",
+ messageId: "SVC4144"
+ }
+
+ #---------SVC4145------------------------------
+ # %1 - "Model name"
+ INVALID_MODEL: {
+ code: 400,
+ message: "Invalid model '%1'.",
+ messageId: "SVC4145"
+ }
+
+ #---------SVC4146------------------------------
+ MODEL_IMPORTS_IS_EMPTY: {
+ code: 400,
+ message: "Given model imports zip is empty.",
+ messageId: "SVC4146"
+ }
+
+ #---------SVC4147------------------------------
+ COULD_NOT_READ_MODEL_IMPORTS: {
+ code: 400,
+ message: "Could not read imports zip.",
+ messageId: "SVC4147"
+ }
+
+ #---------SVC4148------------------------------
+ # %1 - "Model name"
+ MODEL_NOT_FOUND: {
+ code: 404,
+ message: "Error: Model name '%1' not found. Please, make sure the model is created.",
+ messageId: "SVC4148"
+ }
+
+ #---------SVC4149------------------------------
+ MODEL_NAME_CANNOT_BE_EMPTY: {
+ code: 409,
+ message: "Error: Model name cannot be empty.",
+ messageId: "SVC4149"
+ }
+
+ #-----------SVC4150---------------------------
+ # %1 - "Component name"
+ # %2 - "Model name"
+ COMPONENT_WITH_MODEL_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Component %1 with Model %2 already exist.",
+ messageId: "SVC4150"
+ }
+ #-----------SVC4151---------------------------
+ # %1 - "Component name"
+ # %2 - "Vendor release"
+ # %3 - "Model name"
+ COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS_IN_MODEL: {
+ code: 409,
+ message: "Error: Component '%1' with Vendor Release '%2' already exists in Model '%3'.",
+ messageId: "SVC4151"
+ }
+ #-----------SVC4152---------------------------
+ # %1 - "Component name"
+ # %2 - "Vendor release"
+ COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS: {
+ code: 409,
+ message: "Error: Component '%1' with Vendor Release '%2' already exists.",
+ messageId: "SVC4152"
+ }
+
+ #-----------SVC4153---------------------------
+ # %1 - "Model name"
+ DATA_TYPES_NOT_LOADED: {
+ code: 500,
+ message: "Could not fetch data types from data base with model %1",
+ messageId: "SVC4153"
+ }
+
+ #-----------SVC4154---------------------------
+ # %1 - "Model name"
+ UNKNOWN_MODEL_TYPE: {
+ code: 400,
+ message: "Error: Model type %1 not known in the system",
+ messageId: "SVC4154"
+ }
+
+ #-----------SVC4154---------------------------
+ CSAR_TOSCA_IMPORTS_ERROR: {
+ code: 500,
+ message: "Error: An error has occurred while including the default TOSCA imports in the CSAR",
+ messageId: "SVC4154"
+ }
+
+ #-----------SVC4155---------------------------
+ # %1 - "VSP id"
+ # %2 - "VSP version id"
+ VSP_FIND_ERROR: {
+ code: 500,
+ message: "An error has occurred while retrieving the Vendor Software Product of id '%1', version id '%2'",
+ messageId: "SVC4155"
+ }
+
+ #-----------SVC4156---------------------------
+ # %1 - "VSP id"
+ # %2 - "VSP version id"
+ VSP_NOT_FOUND: {
+ code: 404,
+ message: "Could not find Vendor Software Product of id '%1', version id '%2'",
+ messageId: "SVC4156"
+ }
+
+ #-----------SVC4157---------------------------
+ # %1 - "The model name"
+ # %2 - "List of allowed models"
+ VSP_MODEL_NOT_ALLOWED: {
+ code: 400,
+ message: "The Model '%1' is not allowed for the imported Vendor Software Product. Allowed Models: '%2'",
+ messageId: "SVC4157"
+ }
+
+ #---------SVC4158-----------------------------
+ # %1 - Valid artifact label name
+ INVALID_ARTIFACT_LABEL_NAME: {
+ code: 400,
+ message: "Invalid label name. Only the following characters are allowed in label name: '%1'",
+ messageId: "SVC4158"
+ }
+
+ #---------SVC4159-----------------------------
+ # %1 - The model name
+ COULD_NOT_DELETE_MODEL: {
+ code: 500,
+ message: "Could not delete the model '%1'.",
+ messageId: "SVC4159"
+ }
+
+ #---------SVC4160-----------------------------
+ # %1 - The model name
+ COULD_NOT_DELETE_MODEL_ELEMENTS: {
+ code: 500,
+ message: "Could not delete the model '%1' elements.",
+ messageId: "SVC4160"
+ }
+ #---------SVC4161-----------------------------
+ INVALID_NODE_TYPES_YAML: {
+ code: 400,
+ message: "Invalid node_types TOSCA yaml",
+ messageId: "SVC4161"
+ }
+
+ #---------SVC4162-----------------------------
+ # %1 - The janusgraph status
+ FAILED_CREATE_ARTIFACTS_TYPES: {
+ code: 500,
+ message: "Failed to create artifact types with status '%1'.",
+ messageId: "SVC4162"
+ }
+
+ #---------SVC4163-----------------------------
+ # %1 - The janusgraph status
+ ARTIFACT_TYPE_ALREADY_EXIST: {
+ code: 409,
+ message: "Artifact type '%1' already exist.",
+ messageId: "SVC4163"
+ }
+
+ #---------SVC4692-----------------------------
+ # %1 - Component name
+ COMPONENT_NOT_ARCHIVED: {
+ code: 403,
+ message: "Component '%1' is not archived",
+ messageId: "SVC4692"
+ }
+
+ #---------SVC4693-----------------------------
+ # %1 - List of services
+ COMPONENT_IN_USE_BY_ANOTHER_COMPONENT: {
+ code: 403,
+ message: "Component is in use by '%1'",
+ messageId: "SVC4693"
+ }
+
+ #---------SVC4164-----------------------------
+ # %1 - componentType
+ # %2 - component name
+ CANNOT_DELETE_SYSTEM_DEPLOYED_RESOURCES: {
+ code: 409,
+ message: "System deployed '%1' cannot be deleted '%2'",
+ messageId: "SVC4164"
+ }
+
+ #---------SVC4165-----------------------------
+ # %1 - input origin
+ TOSCA_GET_FUNCTION_INPUTS_ONLY_SELF_ERROR: {
+ code: 400,
+ message: "Invalid get_input definition. Inputs can only be get from SELF, the given origin was '%1'",
+ messageId: "SVC4165"
+ }
+
+ #---------SVC4166-----------------------------
+ # %1 - input name
+ # %2 - input origin
+ TOSCA_GET_FUNCTION_INPUTS_NOT_FOUND: {
+ code: 404,
+ message: "The given input '%1' was not found on '%2'.",
+ messageId: "SVC4166"
+ }
+
+ #---------SVC4167-----------------------------
+ # %1 - Tosca function
+ # %2 - Referred input type
+ # %3 - Selected property type
+ TOSCA_GET_FUNCTION_TYPE_DIVERGE: {
+ code: 400,
+ message: "Could not set %1. Referred input type '%2' diverges from the selected property type '%3'.",
+ messageId: "SVC4167"
+ }
+
+ #---------SVC4168-----------------------------
+ # %1 - Tosca function
+ # %2 - Referred input schema
+ # %3 - Selected property schema
+ TOSCA_GET_FUNCTION_SCHEMA_DIVERGE: {
+ code: 400,
+ message: "Could not set %1. Referred input schema '%2' diverges from the selected property schema '%3'.",
+ messageId: "SVC4168"
+ }
+
+ #---------SVC4169-----------------------------
+ # %1 - Property type (property|input|attribute)
+ # %1 - Property name
+ # %2 - Property origin
+ TOSCA_GET_FUNCTION_PROPERTY_NOT_FOUND: {
+ code: 404,
+ message: "The given %1 '%2' was not found on '%3'.",
+ messageId: "SVC4169"
+ }
+
+ #---------SVC4170-----------------------------
+ # %1 - Property type (property|input|attribute)
+ # %2 - Property name/path
+ # %3 - Property data type
+ TOSCA_GET_FUNCTION_PROPERTY_DATA_TYPE_NOT_FOUND: {
+ code: 404,
+ message: "The %1 '%2' type '%3' was not found.",
+ messageId: "SVC4170"
+ }
+
+ #---------SVC4171-----------------------------
+ # %1 - Instance name
+ TOSCA_GET_FUNCTION_INSTANCE_NOT_FOUND: {
+ code: 404,
+ message: "The instance '%1' was not found.",
+ messageId: "SVC4171"
+ }
+
+ #-----------SVC4172---------------------------
+ #%1 - TOSCA function attribute
+ TOSCA_FUNCTION_MISSING_ATTRIBUTE: {
+ code: 400,
+ message: "Missing TOSCA function '%1'.",
+ messageId: "SVC4172"
+ }
+
+ #-----------SVC4173---------------------------
+ RELATIONSHIP_TEMPLATE_NOT_FOUND: {
+ code: 404,
+ message: "Relationship_templates entry not found in TOSCA CSAR.",
+ messageId: "SVC4173"
+ }
+
+ #-----------SVC4174---------------------------
+ RELATIONSHIP_TEMPLATE_DEFINITION_NOT_FOUND: {
+ code: 404,
+ message: "Relationship_templates definition not found in TOSCA CSAR.",
+ messageId: "SVC4174"
+ }
+
+ #-----------SVC4175---------------------------
+ TOSCA_FUNCTION_EXPECTED_ERROR: {
+ code: 400,
+ message: "Expecting a Tosca Function value.",
+ messageId: "SVC4175"
+ }
+
+ #-----------SVC4176---------------------------
+ FILTER_CONSTRAINT_MISSING: {
+ code: 400,
+ message: "The filter constraint was not provided.",
+ messageId: "SVC4176"
+ }
+
+ #-----------SVC4177---------------------------
+ #%1 - The missing field
+ FILTER_CONSTRAINT_MISSING_FIELD: {
+ code: 400,
+ message: "Required field '%1' is missing in the filter constraint.",
+ messageId: "SVC4177"
+ }
+
+ #%1 - the component id
+ SUBSTITUTION_FILTER_NOT_FOUND: {
+ code: 404,
+ message: 'Substitution filter not found in the component "%1"',
+ messageId: "SVC4178"
+ }
+
+ # %1 - Component name
+ COMPONENT_DOES_NOT_HAVE_INPUTS: {
+ code: 400,
+ message: "Component '%1' does not have inputs.",
+ messageId: "SVC4179"
+ }
+
+ # %1 - Input name
+ # %2 - Component name
+ COMPONENT_INPUT_NOT_FOUND: {
+ code: 400,
+ message: "Input '%1' does not exist in '%2'.",
+ messageId: "SVC4180"
+ }
+
+ # %1 - Target property name
+ # %2 - Source property name
+ SOURCE_TARGET_SCHEMA_MISMATCH: {
+ code: 400,
+ message: "Target property '%1' schema '%2' does not match with source property '%3' schema '%4'.",
+ messageId: "SVC4181"
+ }
+
+ # %1 - Property name
+ # %2 - Component name
+ COMPONENT_PROPERTY_NOT_FOUND:
+ code: 400
+ message: "Property '%1' does not exist in '%2'."
+ messageId: "SVC4183"
+
+ # %1 - The component type
+ # %2 - The expected component types
+ INVALID_COMPONENT_TYPE:
+ code: 400
+ message: "Invalid component type '%1'. Expected types are: %2"
+ messageId: "SVC4185"
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java
index aae88ab153..1bf075e2f6 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java
@@ -25,47 +25,42 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import fj.data.Either;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
-import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
import org.openecomp.sdc.be.components.validation.NodeFilterValidator;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
-import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
+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.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -78,15 +73,18 @@ import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
import org.openecomp.sdc.be.model.UploadNodeFilterPropertyInfo;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeFilterOperation;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
+import org.openecomp.sdc.be.ui.mapper.FilterConstraintMapper;
import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.exception.ResponseFormat;
@ExtendWith(MockitoExtension.class)
-public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock {
+class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock {
private static final String servicePropertyName = "resourceType";
private static final String constraintOperator = "equal";
@@ -119,9 +117,8 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
private Resource resource;
private ComponentInstance componentInstance;
private CINodeFilterDataDefinition ciNodeFilterDataDefinition;
- private RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition;
- private String constraint;
private UIConstraint uiConstraint;
+ private FilterConstraintDto filterConstraintDto;
@BeforeEach
public void init() {
@@ -141,7 +138,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void createWhenNodeFilterExistsTest() throws BusinessLogicException {
+ void createWhenNodeFilterExistsTest() throws BusinessLogicException {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
@@ -155,7 +152,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void createNodeFilterFailTest() {
+ void createNodeFilterFailTest() {
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
@@ -175,7 +172,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void createNodeFilterIfNotExist() throws BusinessLogicException {
+ void createNodeFilterIfNotExist() throws BusinessLogicException {
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
@@ -197,7 +194,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void deleteNodeFilterIfExistsTest() throws BusinessLogicException {
+ void deleteNodeFilterIfExistsTest() throws BusinessLogicException {
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
@@ -211,7 +208,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void deleteWhenNodeFilterExistsTest() throws BusinessLogicException {
+ void deleteWhenNodeFilterExistsTest() throws BusinessLogicException {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
@@ -236,7 +233,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void deleteNodeFilterIfExistsFailTest() {
+ void deleteNodeFilterIfExistsFailTest() {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
@@ -260,129 +257,130 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void addNodeFilterPropertiesTest() throws BusinessLogicException {
+ void addNodeFilterPropertiesTest() throws BusinessLogicException {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
- when(nodeFilterValidator
- .validateFilter(resource, componentInstanceId,
- requirementNodeFilterPropertyDataDefinition.getConstraints(),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, "")).thenReturn(Either.left(true));
+ when(nodeFilterValidator.validateFilter(resource, componentInstanceId, filterConstraintDto))
+ .thenReturn(Either.left(true));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
- when(nodeFilterOperation.addNewProperty(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
- any(RequirementNodeFilterPropertyDataDefinition.class))).thenReturn(Either.left(ciNodeFilterDataDefinition));
+ when(nodeFilterOperation.addPropertyFilter(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ any(PropertyFilterDataDefinition.class))).thenReturn(Either.left(ciNodeFilterDataDefinition));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
final Optional<CINodeFilterDataDefinition> result = componentNodeFilterBusinessLogic
- .addNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.ADD,
- "MyPropertyName", constraint, true, ComponentTypeEnum.RESOURCE,
- NodeFilterConstraintType.PROPERTIES, "");
+ .addNodeFilter(componentId, componentInstanceId, filterConstraintDto, true, ComponentTypeEnum.RESOURCE,
+ NodeFilterConstraintType.PROPERTIES, null);
assertThat(result).isPresent();
assertThat(result.get().getProperties().getListToscaDataDefinition()).hasSize(1);
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
- verify(nodeFilterValidator, times(1)).validateFilter(resource, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, "");
+ verify(nodeFilterValidator, times(1))
+ .validateFilter(resource, componentInstanceId, filterConstraintDto);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource);
verify(nodeFilterOperation, times(1))
- .addNewProperty(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
- any(RequirementNodeFilterPropertyDataDefinition.class));
+ .addPropertyFilter(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ any(PropertyFilterDataDefinition.class));
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Resource);
}
@Test
- public void addNodeFilterCapabilitiesTest() throws BusinessLogicException {
+ void addNodeFilterCapabilitiesTest() throws BusinessLogicException {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
-
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
- when(nodeFilterValidator
- .validateFilter(resource, componentInstanceId,
- requirementNodeFilterPropertyDataDefinition.getConstraints(),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.CAPABILITIES, capabilityName)).thenReturn(Either.left(true));
+ when(nodeFilterValidator.validateFilter(resource, componentInstanceId, filterConstraintDto))
+ .thenReturn(Either.left(true));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
- when(nodeFilterOperation.addNewCapabilities(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ when(nodeFilterOperation.addCapabilities(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
any(RequirementNodeFilterCapabilityDataDefinition.class))).thenReturn(Either.left(ciNodeFilterDataDefinition));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
final Optional<CINodeFilterDataDefinition> result = componentNodeFilterBusinessLogic
- .addNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.ADD,
- "MyPropertyName", constraint, true, ComponentTypeEnum.RESOURCE,
- NodeFilterConstraintType.CAPABILITIES, capabilityName);
+ .addNodeFilter(componentId, componentInstanceId, filterConstraintDto, true, ComponentTypeEnum.RESOURCE,
+ NodeFilterConstraintType.CAPABILITIES, capabilityName
+ );
assertThat(result).isPresent();
assertThat(result.get().getProperties().getListToscaDataDefinition()).hasSize(1);
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
- verify(nodeFilterValidator, times(1)).validateFilter(resource, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.ADD, NodeFilterConstraintType.CAPABILITIES, capabilityName);
+ verify(nodeFilterValidator, times(1))
+ .validateFilter(resource, componentInstanceId, filterConstraintDto);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource);
verify(nodeFilterOperation, times(1))
- .addNewCapabilities(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ .addCapabilities(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
any(RequirementNodeFilterCapabilityDataDefinition.class));
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Resource);
}
@Test
- public void addNodeFilterFailTest() {
+ void addNodeFilterFailTest() {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator
- .validateFilter(resource, componentInstanceId,
- requirementNodeFilterPropertyDataDefinition.getConstraints(),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, capabilityName)).thenReturn(Either.left(true));
+ .validateFilter(resource, componentInstanceId, filterConstraintDto)).thenReturn(Either.left(true));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
-
- final List<String> constraints = requirementNodeFilterPropertyDataDefinition.getConstraints();
- assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
- .addNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.ADD,
- "MyPropertyName", constraint, true, ComponentTypeEnum.RESOURCE,
+ when(nodeFilterOperation
+ .addPropertyFilter(eq(componentId), eq(componentInstanceId), eq(ciNodeFilterDataDefinition), any(PropertyFilterDataDefinition.class)))
+ .thenReturn(Either.right(StorageOperationStatus.COMPONENT_IS_IN_USE));
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.COMPONENT_IS_IN_USE)).thenReturn(ActionStatus.COMPONENT_IN_USE);
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormatByResource(ActionStatus.COMPONENT_IN_USE, resource.getSystemName())).thenReturn(expectedResponse);
+
+ final BusinessLogicException businessLogicException = assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
+ .addNodeFilter(componentId, componentInstanceId, filterConstraintDto, true, ComponentTypeEnum.RESOURCE,
NodeFilterConstraintType.PROPERTIES, capabilityName));
+ assertEquals(expectedResponse, businessLogicException.getResponseFormat());
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource);
- verify(nodeFilterValidator, times(1)).validateFilter(resource, componentInstanceId,
- constraints, NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, capabilityName);
- verify(nodeFilterOperation, times(0))
- .addNewProperty(componentId, componentInstanceId, ciNodeFilterDataDefinition,
- requirementNodeFilterPropertyDataDefinition);
+
+ verify(nodeFilterValidator, times(1))
+ .validateFilter(resource, componentInstanceId, filterConstraintDto);
+ verify(nodeFilterOperation, times(1))
+ .addPropertyFilter(eq(componentId), eq(componentInstanceId), eq(ciNodeFilterDataDefinition),
+ any(PropertyFilterDataDefinition.class));
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Resource);
+ verify(janusGraphDao, times(1)).rollback();
+ verify(janusGraphDao, never()).commit();
}
@Test
- public void addNodeFilterFailFetchComponentTest() {
+ void addNodeFilterFailFetchComponentTest() {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId))
- .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND)).thenReturn(ActionStatus.COMPONENT_NOT_FOUND);
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NOT_FOUND)).thenReturn(expectedResponse);
- assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
- .addNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.ADD,
- "MyPropertyName", constraint, true, ComponentTypeEnum.RESOURCE,
+ final BusinessLogicException businessLogicException = assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
+ .addNodeFilter(componentId, componentInstanceId, filterConstraintDto, true, ComponentTypeEnum.RESOURCE,
NodeFilterConstraintType.PROPERTIES, capabilityName));
+ assertEquals(expectedResponse, businessLogicException.getResponseFormat());
}
@Test
- public void deleteNodeFilterTest() throws BusinessLogicException {
+ void deleteNodeFilterTest() throws BusinessLogicException {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
- when(nodeFilterValidator.validateFilter(resource, componentInstanceId, singletonList(constraint),
- NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, "")).thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
@@ -395,8 +393,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
.thenReturn(StorageOperationStatus.OK);
final Optional<CINodeFilterDataDefinition> deleteNodeFilterResult = componentNodeFilterBusinessLogic
- .deleteNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.DELETE, constraint,
- 0, true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES);
+ .deleteNodeFilter(componentId, componentInstanceId, 0, true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES);
assertThat(deleteNodeFilterResult).isPresent();
@@ -404,9 +401,6 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource);
verify(nodeFilterValidator, times(1))
.validateComponentInstanceExist(resource, componentInstanceId);
- verify(nodeFilterValidator, times(1))
- .validateFilter(resource, componentInstanceId, singletonList(constraint),
- NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, "");
verify(nodeFilterOperation, times(1))
.deleteConstraint(componentId, componentInstanceId, ciNodeFilterDataDefinition, 0,
NodeFilterConstraintType.PROPERTIES);
@@ -414,14 +408,12 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void deleteNodeFilterFailTest() {
+ void deleteNodeFilterFailTest() {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
- when(nodeFilterValidator.validateFilter(resource, componentInstanceId, singletonList(constraint),
- NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, "")).thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
@@ -434,64 +426,48 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
.thenReturn(StorageOperationStatus.OK);
assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
- .deleteNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.DELETE, constraint,
- 0, true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES));
+ .deleteNodeFilter(componentId, componentInstanceId, 0, true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource);
verify(nodeFilterValidator, times(1))
- .validateFilter(resource, componentInstanceId, singletonList(constraint),
- NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, "");
- verify(nodeFilterValidator, times(1))
.validateComponentInstanceExist(resource, componentInstanceId);
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Resource);
}
@Test
- public void deleteNodeFilterFailValidationTest() {
+ void deleteNodeFilterFailValidationTest() {
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
- when(nodeFilterValidator.validateFilter(resource, componentInstanceId, singletonList(constraint),
- NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, "")).thenReturn(Either.left(true));
assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
- .deleteNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.DELETE, constraint,
- 0, true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES));
+ .deleteNodeFilter(componentId, componentInstanceId, 0, true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(nodeFilterValidator, times(1))
- .validateFilter(resource, componentInstanceId, singletonList(constraint),
- NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, "");
- verify(nodeFilterValidator, times(1))
.validateComponentInstanceExist(resource, componentInstanceId);
}
@Test
- public void updateNodeFilterTest() throws BusinessLogicException {
+ void updateNodeFilterTest() throws BusinessLogicException {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
when(nodeFilterValidator
- .validateFilter(ArgumentMatchers.any(Component.class), anyString(), anyList(),
- ArgumentMatchers.any(NodeFilterConstraintAction.class),
- ArgumentMatchers.any(NodeFilterConstraintType.class), anyString())).thenReturn(Either.left(true));
+ .validateFilter(any(Component.class), anyString(), any(FilterConstraintDto.class))
+ ).thenReturn(Either.left(true));
- when(nodeFilterValidator
- .validateFilter(ArgumentMatchers.any(Component.class), anyString(), anyList(),
- ArgumentMatchers.any(NodeFilterConstraintAction.class),
- ArgumentMatchers.any(NodeFilterConstraintType.class), isNull())).thenReturn(Either.left(true));
-
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
when(nodeFilterOperation.deleteConstraint(componentId, componentInstanceId, ciNodeFilterDataDefinition,
0, NodeFilterConstraintType.PROPERTIES)).thenReturn(Either.left(ciNodeFilterDataDefinition));
- when(nodeFilterOperation.addNewProperty(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
- any(RequirementNodeFilterPropertyDataDefinition.class))).thenReturn(Either.left(ciNodeFilterDataDefinition));
+ when(nodeFilterOperation.addPropertyFilter(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ any(PropertyFilterDataDefinition.class))).thenReturn(Either.left(ciNodeFilterDataDefinition));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
@@ -505,20 +481,16 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void updateNodeFilterFailTest() throws BusinessLogicException {
+ void updateNodeFilterFailTest() {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
when(nodeFilterValidator
- .validateFilter(ArgumentMatchers.any(Component.class), anyString(), anyList(),
- ArgumentMatchers.any(NodeFilterConstraintAction.class),
- ArgumentMatchers.any(NodeFilterConstraintType.class), anyString())).thenReturn(Either.left(true));
- when(nodeFilterValidator
- .validateFilter(ArgumentMatchers.any(Component.class), anyString(), anyList(),
- ArgumentMatchers.any(NodeFilterConstraintAction.class),
- ArgumentMatchers.any(NodeFilterConstraintType.class), isNull())).thenReturn(Either.left(true));
+ .validateFilter(any(Component.class), anyString(), any(FilterConstraintDto.class))
+ ).thenReturn(Either.left(true));
+
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
@@ -526,8 +498,8 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
when(nodeFilterOperation.deleteConstraint(componentId, componentInstanceId, ciNodeFilterDataDefinition,
0, NodeFilterConstraintType.PROPERTIES)).thenReturn(Either.left(ciNodeFilterDataDefinition));
- when(nodeFilterOperation.addNewProperty(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
- any(RequirementNodeFilterPropertyDataDefinition.class))).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ when(nodeFilterOperation.addPropertyFilter(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ any(PropertyFilterDataDefinition.class))).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
@@ -538,14 +510,10 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void updateNodeFilterFailValidationTest() {
+ void updateNodeFilterFailValidationTest() {
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
- when(nodeFilterValidator
- .validateFilter(ArgumentMatchers.any(Component.class), anyString(), anyList(),
- ArgumentMatchers.any(NodeFilterConstraintAction.class),
- ArgumentMatchers.any(NodeFilterConstraintType.class), anyString())).thenReturn(Either.left(true));
assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
.updateNodeFilter(componentId, componentInstanceId, uiConstraint, ComponentTypeEnum.RESOURCE,
@@ -555,55 +523,49 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void testAssociateNodeFilterToComponentInstance() {
+ void testAssociateNodeFilterToComponentInstance() {
CINodeFilterDataDefinition ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
UploadNodeFilterInfo filter = new UploadNodeFilterInfo();
UploadNodeFilterPropertyInfo propertyDataDefinition = new UploadNodeFilterPropertyInfo();
propertyDataDefinition.setName("order");
- propertyDataDefinition.setValues(Collections.singletonList("order: {equal: 2"));
- List<UploadNodeFilterPropertyInfo> propertyList = new LinkedList<>();
- propertyList.add(propertyDataDefinition);
+ propertyDataDefinition.setValues(Collections.singletonList("order: {equal: 2}"));
filter.setProperties(Collections.singletonList(propertyDataDefinition));
Map<String, UploadNodeFilterInfo> nodeFilterMap = new HashMap<>();
nodeFilterMap.put(componentInstanceId, filter);
when(nodeFilterOperation.createNodeFilter(componentId, componentInstanceId)).thenReturn(Either.left(ciNodeFilterDataDefinition));
- when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
- when(nodeFilterOperation.addNewProperty(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
- any(RequirementNodeFilterPropertyDataDefinition.class))).thenReturn(Either.left(ciNodeFilterDataDefinition));
+ when(nodeFilterOperation.addPropertyFilter(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ any(PropertyFilterDataDefinition.class))).thenReturn(Either.left(ciNodeFilterDataDefinition));
StorageOperationStatus status = componentNodeFilterBusinessLogic.associateNodeFilterToComponentInstance(componentId, nodeFilterMap);
assertEquals(StorageOperationStatus.OK, status);
}
@Test
- public void testAssociateNodeFilterToComponentInstanceFail() {
+ void testAssociateNodeFilterToComponentInstanceFail() {
CINodeFilterDataDefinition ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
UploadNodeFilterInfo filter = new UploadNodeFilterInfo();
UploadNodeFilterPropertyInfo propertyDataDefinition = new UploadNodeFilterPropertyInfo();
propertyDataDefinition.setName("order");
- propertyDataDefinition.setValues(Collections.singletonList("order: {equal: 2"));
- List<UploadNodeFilterPropertyInfo> propertyList = new LinkedList<>();
- propertyList.add(propertyDataDefinition);
+ propertyDataDefinition.setValues(Collections.singletonList("order: {equal: 2}"));
filter.setProperties(Collections.singletonList(propertyDataDefinition));
Map<String, UploadNodeFilterInfo> nodeFilterMap = new HashMap<>();
nodeFilterMap.put(componentInstanceId, filter);
when(nodeFilterOperation.createNodeFilter(componentId, componentInstanceId)).thenReturn(Either.left(ciNodeFilterDataDefinition));
- when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
- when(nodeFilterOperation.addNewProperty(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
- any(RequirementNodeFilterPropertyDataDefinition.class))).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ when(nodeFilterOperation.addPropertyFilter(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ any(PropertyFilterDataDefinition.class))).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
- Assertions.assertThrows(ComponentException.class, () -> componentNodeFilterBusinessLogic.associateNodeFilterToComponentInstance(componentId,
+ assertThrows(ComponentException.class, () -> componentNodeFilterBusinessLogic.associateNodeFilterToComponentInstance(componentId,
nodeFilterMap));
}
@Test
- public void validateUserTes() {
+ void validateUserTes() {
final String USER_ID = "jh0003";
final User user = new User();
user.setUserId(USER_ID);
@@ -615,54 +577,54 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
assertTrue(Role.ADMIN.name().equalsIgnoreCase(result.getRole()));
}
- public void initResource() {
- try {
- resource = new Resource();
- resource.setName("MyResource");
- resource.setUniqueId(componentId);
- resource.setToscaResourceName("My_Resource_Tosca_Name");
- resource.addCategory("Network Layer 2-3", "Router");
- resource.setDescription("My short description");
-
- componentInstance = new ComponentInstance();
- componentInstance.setUniqueId(componentInstanceId);
- componentInstance.setName("myComponentInstance");
- componentInstance.setDirectives(ConfigurationManager.getConfigurationManager().getConfiguration()
- .getDirectives());
-
- uiConstraint = new UIConstraint(servicePropertyName, constraintOperator, sourceType, sourceName, propertyValue);
- constraint = new ConstraintConvertor().convert(uiConstraint);
-
- requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition();
- requirementNodeFilterPropertyDataDefinition.setName(uiConstraint.getServicePropertyName());
- requirementNodeFilterPropertyDataDefinition.setConstraints(new LinkedList<>(Arrays.asList(constraint)));
-
- final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> listDataDefinition =
- new ListDataDefinition<>(new LinkedList<>(Arrays.asList(requirementNodeFilterPropertyDataDefinition)));
-
- ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
- ciNodeFilterDataDefinition.setProperties(listDataDefinition);
- ciNodeFilterDataDefinition.setID("NODE_FILTER_UID");
-
- resource.setComponentInstances(singletonList(componentInstance));
-
- final PropertyDefinition property = new PropertyDefinition();
- property.setName(uiConstraint.getServicePropertyName());
-
- final List<ComponentInstanceProperty> origProperties = new ArrayList<>();
- final ComponentInstanceProperty origProperty = new ComponentInstanceProperty();
- origProperty.setName(uiConstraint.getServicePropertyName());
- origProperty.setValue(propertyValue);
- origProperty.setType(uiConstraint.getSourceType());
- origProperties.add(origProperty);
-
- final Map<String, List<ComponentInstanceProperty>> componentInstanceProps = new HashMap<>();
- componentInstanceProps.put(componentInstanceId, origProperties);
-
- resource.setComponentInstancesProperties(componentInstanceProps);
- resource.setProperties(new LinkedList<>(Arrays.asList(property)));
- } catch (final Exception e) {
- fail(e.getMessage());
- }
+ private void initResource() {
+ resource = new Resource();
+ resource.setName("MyResource");
+ resource.setUniqueId(componentId);
+ resource.setToscaResourceName("My_Resource_Tosca_Name");
+ resource.addCategory("Network Layer 2-3", "Router");
+ resource.setDescription("My short description");
+
+ componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(componentInstanceId);
+ componentInstance.setName("myComponentInstance");
+ componentInstance.setDirectives(ConfigurationManager.getConfigurationManager().getConfiguration()
+ .getDirectives());
+
+ uiConstraint = new UIConstraint(servicePropertyName, constraintOperator, sourceType, sourceName, propertyValue);
+ final FilterConstraintMapper filterConstraintMapper = new FilterConstraintMapper();
+ filterConstraintDto = filterConstraintMapper.mapFrom(uiConstraint);
+
+ PropertyFilterDataDefinition propertyFilterDataDefinition = new PropertyFilterDataDefinition();
+ propertyFilterDataDefinition.setName(uiConstraint.getServicePropertyName());
+ final PropertyFilterConstraintDataDefinition propertyFilterConstraint =
+ filterConstraintMapper.mapTo(filterConstraintDto);
+ propertyFilterDataDefinition.setConstraints(new LinkedList<>(List.of(propertyFilterConstraint)));
+
+ final ListDataDefinition<PropertyFilterDataDefinition> listDataDefinition =
+ new ListDataDefinition<>(new LinkedList<>(singletonList(propertyFilterDataDefinition)));
+
+ ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
+ ciNodeFilterDataDefinition.setProperties(listDataDefinition);
+ ciNodeFilterDataDefinition.setID("NODE_FILTER_UID");
+
+ resource.setComponentInstances(singletonList(componentInstance));
+
+ final PropertyDefinition property = new PropertyDefinition();
+ property.setName(uiConstraint.getServicePropertyName());
+
+ final List<ComponentInstanceProperty> origProperties = new ArrayList<>();
+ final ComponentInstanceProperty origProperty = new ComponentInstanceProperty();
+ origProperty.setName(uiConstraint.getServicePropertyName());
+ origProperty.setValue(propertyValue);
+ origProperty.setType(uiConstraint.getSourceType());
+ origProperties.add(origProperty);
+
+ final Map<String, List<ComponentInstanceProperty>> componentInstanceProps = new HashMap<>();
+ componentInstanceProps.put(componentInstanceId, origProperties);
+
+ resource.setComponentInstancesProperties(componentInstanceProps);
+ resource.setProperties(new LinkedList<>(List.of(property)));
}
+
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java
index 7435a8b6e2..c8692634c4 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java
@@ -36,7 +36,6 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
-
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -45,29 +44,30 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
-import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
import org.openecomp.sdc.be.components.validation.NodeFilterValidator;
import org.openecomp.sdc.be.components.validation.UserValidations;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
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.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.SubstitutionFilterOperation;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
+import org.openecomp.sdc.be.ui.mapper.FilterConstraintMapper;
import org.openecomp.sdc.be.ui.model.UIConstraint;
@ExtendWith(MockitoExtension.class)
-public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLogicMock {
+class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLogicMock {
private static final String servicePropertyName = "controller_actor";
private static final String constraintOperator = "equal";
@@ -97,8 +97,9 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
private Component component;
private SubstitutionFilterDataDefinition substitutionFilterDataDefinition;
- private RequirementSubstitutionFilterPropertyDataDefinition requirementSubstitutionFilterPropertyDataDefinition;
+ private SubstitutionFilterPropertyDataDefinition substitutionFilterPropertyDataDefinition;
private String constraint;
+ private FilterConstraintDto filterConstraintDto;
@BeforeEach
public void init() {
@@ -118,7 +119,7 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
}
@Test
- public void doNotCreateSubstitutionFilterAsExistsTest() throws BusinessLogicException {
+ void doNotCreateSubstitutionFilterAsExistsTest() throws BusinessLogicException {
component.setSubstitutionFilter(substitutionFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
@@ -131,7 +132,7 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
}
@Test
- public void createSubstitutionFilterIfNotExistTest() throws BusinessLogicException {
+ void createSubstitutionFilterIfNotExistTest() throws BusinessLogicException {
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
@@ -151,7 +152,7 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
}
@Test
- public void createSubstitutionFilterIfNotExistFailTest() {
+ void createSubstitutionFilterIfNotExistFailTest() {
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
@@ -170,124 +171,111 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
}
@Test
- public void addSubstitutionFilterTest() throws BusinessLogicException {
+ void addSubstitutionFilterTest() throws BusinessLogicException {
component.setSubstitutionFilter(substitutionFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- when(nodeFilterValidator.validateComponentFilter(component, Collections.singletonList(constraint),
- NodeFilterConstraintAction.ADD)).thenReturn(Either.left(true));
+ when(nodeFilterValidator.validateSubstitutionFilter(component, filterConstraintDto)).thenReturn(Either.left(true));
when(substitutionFilterOperation
.addPropertyFilter(anyString(), any(SubstitutionFilterDataDefinition.class),
- any(RequirementSubstitutionFilterPropertyDataDefinition.class)))
+ any(SubstitutionFilterPropertyDataDefinition.class)))
.thenReturn(Either.left(substitutionFilterDataDefinition));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
final Optional<SubstitutionFilterDataDefinition> result = componentSubstitutionFilterBusinessLogic
- .addSubstitutionFilter(componentId, servicePropertyName, constraint, true,
- ComponentTypeEnum.SERVICE);
+ .addSubstitutionFilter(componentId, filterConstraintDto, true, ComponentTypeEnum.SERVICE);
assertThat(result).isPresent();
assertThat(result.get().getProperties().getListToscaDataDefinition()).hasSize(1);
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
- verify(nodeFilterValidator, times(1)).validateComponentFilter(component,
- Collections.singletonList(constraint), NodeFilterConstraintAction.ADD);
+ verify(nodeFilterValidator, times(1)).validateSubstitutionFilter(component, filterConstraintDto);
verify(substitutionFilterOperation, times(1))
.addPropertyFilter(anyString(), any(SubstitutionFilterDataDefinition.class),
- any(RequirementSubstitutionFilterPropertyDataDefinition.class));
+ any(SubstitutionFilterPropertyDataDefinition.class));
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Service);
}
@Test
- public void addSubstitutionFilterFailTest() {
+ void addSubstitutionFilterFailTest() {
component.setSubstitutionFilter(substitutionFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- when(nodeFilterValidator.validateComponentFilter(component, Collections.singletonList(constraint),
- NodeFilterConstraintAction.ADD)).thenReturn(Either.left(true));
+ when(nodeFilterValidator.validateSubstitutionFilter(component, filterConstraintDto)).thenReturn(Either.left(true));
when(substitutionFilterOperation
.addPropertyFilter(componentId, substitutionFilterDataDefinition,
- requirementSubstitutionFilterPropertyDataDefinition))
+ substitutionFilterPropertyDataDefinition))
.thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
assertThrows(BusinessLogicException.class, () -> componentSubstitutionFilterBusinessLogic
- .addSubstitutionFilter(componentId, servicePropertyName, constraint, true,
- ComponentTypeEnum.SERVICE));
+ .addSubstitutionFilter(componentId, filterConstraintDto, true, ComponentTypeEnum.SERVICE));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
- verify(nodeFilterValidator, times(1)).validateComponentFilter(component,
- Collections.singletonList(constraint), NodeFilterConstraintAction.ADD);
+ verify(nodeFilterValidator, times(1)).validateSubstitutionFilter(component, filterConstraintDto);
verify(substitutionFilterOperation, times(0))
.addPropertyFilter(componentId, substitutionFilterDataDefinition,
- requirementSubstitutionFilterPropertyDataDefinition);
+ substitutionFilterPropertyDataDefinition);
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Service);
}
@Test
- public void updateSubstitutionFilterTest() throws BusinessLogicException {
+ void updateSubstitutionFilterTest() throws BusinessLogicException {
component.setSubstitutionFilter(substitutionFilterDataDefinition);
- final List<String> constraints = requirementSubstitutionFilterPropertyDataDefinition.getConstraints();
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- when(nodeFilterValidator.validateComponentFilter(component, Collections.singletonList(constraint),
- NodeFilterConstraintAction.UPDATE)).thenReturn(Either.left(true));
- when(substitutionFilterOperation.updateProperties(anyString(), any(SubstitutionFilterDataDefinition.class), anyList()))
+ when(nodeFilterValidator.validateSubstitutionFilter(component, List.of(filterConstraintDto))).thenReturn(Either.left(true));
+ when(substitutionFilterOperation.updatePropertyFilters(anyString(), any(SubstitutionFilterDataDefinition.class), anyList()))
.thenReturn(Either.left(substitutionFilterDataDefinition));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
final Optional<SubstitutionFilterDataDefinition> result = componentSubstitutionFilterBusinessLogic
- .updateSubstitutionFilter(componentId, Collections.singletonList(constraint),
- true, ComponentTypeEnum.SERVICE);
+ .updateSubstitutionFilter(componentId, List.of(filterConstraintDto), true, ComponentTypeEnum.SERVICE);
assertThat(result).isPresent();
assertThat(result.get().getProperties().getListToscaDataDefinition()).hasSize(1);
verify(substitutionFilterOperation, times(1))
- .updateProperties(anyString(), any(SubstitutionFilterDataDefinition.class), anyList());
- verify(nodeFilterValidator, times(1)).validateComponentFilter(component,
- Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE);
+ .updatePropertyFilters(anyString(), any(SubstitutionFilterDataDefinition.class), anyList());
+ verify(nodeFilterValidator, times(1)).validateSubstitutionFilter(component, List.of(filterConstraintDto));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Service);
}
@Test
- public void updateSubstitutionFilterFailTest() {
+ void updateSubstitutionFilterFailTest() {
component.setSubstitutionFilter(substitutionFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- when(nodeFilterValidator.validateComponentFilter(component, Collections.singletonList(constraint),
- NodeFilterConstraintAction.UPDATE)).thenReturn(Either.left(true));
+ when(nodeFilterValidator.validateSubstitutionFilter(component, List.of(filterConstraintDto))).thenReturn(Either.left(true));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- final List<String> constraints = requirementSubstitutionFilterPropertyDataDefinition.getConstraints();
assertThrows(BusinessLogicException.class, () -> componentSubstitutionFilterBusinessLogic
- .updateSubstitutionFilter(componentId, constraints, true, ComponentTypeEnum.SERVICE));
+ .updateSubstitutionFilter(componentId, List.of(filterConstraintDto), true, ComponentTypeEnum.SERVICE));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
- verify(nodeFilterValidator, times(1)).validateComponentFilter(component,
- Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE);
+ verify(nodeFilterValidator, times(1)).validateSubstitutionFilter(component, List.of(filterConstraintDto));
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Service);
}
@Test
- public void deleteSubstitutionFilterTest() throws BusinessLogicException {
+ void deleteSubstitutionFilterTest() throws BusinessLogicException {
substitutionFilterDataDefinition.setProperties(new ListDataDefinition<>());
component.setSubstitutionFilter(substitutionFilterDataDefinition);
@@ -310,7 +298,7 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
}
@Test
- public void deleteSubstitutionFilterFailTest() {
+ void deleteSubstitutionFilterFailTest() {
component.setSubstitutionFilter(substitutionFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
@@ -322,7 +310,6 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- final List<String> constraints = requirementSubstitutionFilterPropertyDataDefinition.getConstraints();
assertThrows(BusinessLogicException.class, () -> componentSubstitutionFilterBusinessLogic
.deleteSubstitutionFilter(componentId, anyInt(),true, ComponentTypeEnum.SERVICE));
@@ -341,16 +328,18 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
final UIConstraint uiConstraint =
new UIConstraint(servicePropertyName, constraintOperator, sourceType, sourceName, propertyValue);
+ final FilterConstraintMapper filterConstraintMapper = new FilterConstraintMapper();
+ filterConstraintDto = filterConstraintMapper.mapFrom(uiConstraint);
constraint = new ConstraintConvertor().convert(uiConstraint);
- requirementSubstitutionFilterPropertyDataDefinition = new RequirementSubstitutionFilterPropertyDataDefinition();
- requirementSubstitutionFilterPropertyDataDefinition.setName(uiConstraint.getServicePropertyName());
- requirementSubstitutionFilterPropertyDataDefinition
- .setConstraints(Collections.singletonList(constraint));
+ substitutionFilterPropertyDataDefinition = new SubstitutionFilterPropertyDataDefinition();
+ substitutionFilterPropertyDataDefinition.setName(uiConstraint.getServicePropertyName());
+ substitutionFilterPropertyDataDefinition
+ .setConstraints(List.of(filterConstraintMapper.mapTo(filterConstraintDto)));
- final ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> listDataDefinition =
+ final ListDataDefinition<SubstitutionFilterPropertyDataDefinition> listDataDefinition =
new ListDataDefinition<>(
- Collections.singletonList(requirementSubstitutionFilterPropertyDataDefinition));
+ Collections.singletonList(substitutionFilterPropertyDataDefinition));
substitutionFilterDataDefinition = new SubstitutionFilterDataDefinition();
substitutionFilterDataDefinition.setProperties(listDataDefinition);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtilsTest.java
index b5baca1b98..eaefe42bdc 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtilsTest.java
@@ -22,26 +22,25 @@
package org.openecomp.sdc.be.components.impl.utils;
-import org.junit.Test;
-import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
-import org.openecomp.sdc.be.model.UploadNodeFilterCapabilitiesInfo;
-import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
-import org.openecomp.sdc.be.model.UploadNodeFilterPropertyInfo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
+import org.openecomp.sdc.be.model.UploadNodeFilterCapabilitiesInfo;
+import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
+import org.openecomp.sdc.be.model.UploadNodeFilterPropertyInfo;
-import static org.junit.Assert.assertEquals;
-public class CINodeFilterUtilsTest {
+class CINodeFilterUtilsTest {
- private CINodeFilterUtils ciNodeFilterUtils;
+ private final CINodeFilterUtils ciNodeFilterUtils = new CINodeFilterUtils();
@Test
- public void testNodeFilterDataDefinition(){
- ciNodeFilterUtils = new CINodeFilterUtils();
+ void testNodeFilterDataDefinition() {
UploadNodeFilterInfo uNodeFilterInfo = new UploadNodeFilterInfo();
UploadNodeFilterPropertyInfo propertyInfo = new UploadNodeFilterPropertyInfo();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtilsTest.java
index 8095a6d3e7..1f1cc5e1eb 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtilsTest.java
@@ -29,7 +29,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
-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.InRangeConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.PatternConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.ValidValuesConstraint;
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/FilterConstraintValidatorImplTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/FilterConstraintValidatorImplTest.java
new file mode 100644
index 0000000000..afa339f95e
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/FilterConstraintValidatorImplTest.java
@@ -0,0 +1,125 @@
+/*
+ * -
+ * ============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.components.validation;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.stream.Stream;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.FilterConstraintExceptionSupplier;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+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.model.validation.FilterConstraintValidator;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+
+class FilterConstraintValidatorImplTest {
+
+ private final FilterConstraintValidator filterConstraintValidator = new FilterConstraintValidatorImpl();
+
+ @BeforeAll
+ static void setUp() {
+ String appConfigDir = "src/test/resources/config/catalog-be";
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
+ new ConfigurationManager(configurationSource);
+ }
+
+ @Test
+ void validatePropertyFilterSuccess() {
+ final FilterConstraintDto filterConstraintDto = buildFilterConstraintDto("aProperty", null, ConstraintType.EQUAL, FilterValueType.STATIC,
+ PropertyFilterTargetType.PROPERTY, "any");
+ assertDoesNotThrow(() -> filterConstraintValidator.validate(filterConstraintDto));
+ }
+
+ @Test
+ void validateCapabilityFilterSuccess() {
+ final var filterConstraintDto = new FilterConstraintDto();
+ filterConstraintDto.setCapabilityName("aCapability");
+ filterConstraintDto.setPropertyName("aProperty");
+ filterConstraintDto.setTargetType(PropertyFilterTargetType.CAPABILITY);
+ filterConstraintDto.setOperator(ConstraintType.EQUAL);
+ filterConstraintDto.setValueType(FilterValueType.STATIC);
+ filterConstraintDto.setValue("any");
+ assertDoesNotThrow(() -> filterConstraintValidator.validate(filterConstraintDto));
+ }
+
+ @ParameterizedTest
+ @MethodSource("provideMissingFieldParameters")
+ void missingFieldError(FilterConstraintDto filterConstraintDto, ComponentException expectedException) {
+ final ByActionStatusComponentException actualException =
+ assertThrows(ByActionStatusComponentException.class, () -> filterConstraintValidator.validate(filterConstraintDto));
+ assertEquals(actualException.getActionStatus(), expectedException.getActionStatus());
+ assertArrayEquals(actualException.getParams(), expectedException.getParams());
+ }
+
+ public static Stream<Arguments> provideMissingFieldParameters() {
+ final var filterConstraintMissingValue = buildFilterConstraintDto("aProperty", null, ConstraintType.EQUAL, FilterValueType.STATIC, PropertyFilterTargetType.PROPERTY, null);
+ final var filterConstraintMissingValueType = buildFilterConstraintDto("aProperty", null, ConstraintType.EQUAL, null, PropertyFilterTargetType.PROPERTY, "any");
+ final var filterConstraintMissingPropertyName = buildFilterConstraintDto(null, null, ConstraintType.EQUAL, FilterValueType.STATIC, PropertyFilterTargetType.PROPERTY, "any");
+ final var filterConstraintMissingCapabilityName = buildFilterConstraintDto("aProperty", null, ConstraintType.EQUAL, FilterValueType.STATIC, PropertyFilterTargetType.CAPABILITY, "any");
+ final var filterConstraintMissingOperator = buildFilterConstraintDto("aProperty", null, null, FilterValueType.STATIC, PropertyFilterTargetType.PROPERTY, "any");
+ final var filterConstraintMissingTargetType = buildFilterConstraintDto("aProperty", null, ConstraintType.EQUAL, FilterValueType.STATIC, null, "any");
+
+ return Stream.of(
+ Arguments.of(filterConstraintMissingValue, FilterConstraintExceptionSupplier.missingField("value").get()),
+ Arguments.of(filterConstraintMissingValueType, FilterConstraintExceptionSupplier.missingField("valueType").get()),
+ Arguments.of(filterConstraintMissingPropertyName, FilterConstraintExceptionSupplier.missingField("propertyName").get()),
+ Arguments.of(filterConstraintMissingCapabilityName, FilterConstraintExceptionSupplier.missingField("capabilityName").get()),
+ Arguments.of(filterConstraintMissingOperator, FilterConstraintExceptionSupplier.missingField("operator").get()),
+ Arguments.of(filterConstraintMissingTargetType, FilterConstraintExceptionSupplier.missingField("targetType").get())
+ );
+ }
+
+ @Test
+ void validateNullFilterConstraint() {
+ final ByActionStatusComponentException actualException = assertThrows(ByActionStatusComponentException.class,
+ () -> filterConstraintValidator.validate(null));
+ final ByActionStatusComponentException expectedException = FilterConstraintExceptionSupplier.filterConstraintNotProvided().get();
+ assertEquals(actualException.getActionStatus(), expectedException.getActionStatus());
+ assertArrayEquals(actualException.getParams(), expectedException.getParams());
+ }
+
+ private static FilterConstraintDto buildFilterConstraintDto(String propertyName, String capabilityName, ConstraintType constraintType,
+ FilterValueType filterValueType, PropertyFilterTargetType targetType, Object value) {
+ final var filterConstraintMissingValueType = new FilterConstraintDto();
+ filterConstraintMissingValueType.setPropertyName(propertyName);
+ filterConstraintMissingValueType.setCapabilityName(capabilityName);
+ filterConstraintMissingValueType.setTargetType(targetType);
+ filterConstraintMissingValueType.setOperator(constraintType);
+ filterConstraintMissingValueType.setValueType(filterValueType);
+ filterConstraintMissingValueType.setValue(value);
+ return filterConstraintMissingValueType;
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java
deleted file mode 100644
index 621b14102f..0000000000
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java
+++ /dev/null
@@ -1,391 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 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.components.validation;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import fj.data.Either;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import org.junit.Assert;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.InjectMocks;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
-import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
-import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.ComponentInstanceProperty;
-import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.Service;
-import org.openecomp.sdc.common.impl.ExternalConfiguration;
-import org.openecomp.sdc.common.impl.FSConfigurationSource;
-import org.openecomp.sdc.exception.ResponseFormat;
-
-public class NodeFilterValidationTest {
-
- private static final String EMPTY_STR = "";
- private static final String UI_CONSTRAINT_STATIC = "Prop1: {equal: 'value'}";
- private static final String INNER_SERVICE = "innerService";
- private static final String PROPERTY_NAME = "Prop1";
- private static final String VALUE = "value";
- private static final String FLOAT_TYPE = "float";
- private static final String STRING_TYPE = "string";
- private static final String LIST_TYPE = "list";
- private static final String COMPONENT1_ID = "component1";
- private static final String INTEGER_TYPE = "integer";
- private static final String PARENTSERVICE_ID = "parentservice";
- private static final String COMPONENT2_ID = "component2";
- private ComponentsUtils componentsUtils;
-
- @InjectMocks
- private NodeFilterValidator nodeFilterValidator;
-
- @BeforeEach
- public void setup() {
- componentsUtils = Mockito.mock(ComponentsUtils.class);
- MockitoAnnotations.openMocks(this);
- new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
- }
-
- @Test
- public void testValidateComponentInstanceExist() {
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateComponentInstanceExist(null, INNER_SERVICE);
- assertTrue(either.isRight());
- assertEquals("Error: Internal Server Error. Please try again later.", either.right().value().getText());
- assertEquals(500, either.right().value().getStatus());
-
- Service service = createService("booleanIncorrect");
- either = nodeFilterValidator.validateComponentInstanceExist(service, INNER_SERVICE);
- assertTrue(either.isRight());
- assertEquals("Error: Internal Server Error. Please try again later.", either.right().value().getText());
- assertEquals(500, either.right().value().getStatus());
-
- List<ComponentInstance> list = new LinkedList<>();
- ComponentInstance instance = new ComponentInstance();
- instance.setUniqueId("uniqueId");
- list.add(instance);
- service.setComponentInstances(list);
- either = nodeFilterValidator.validateComponentInstanceExist(service, "uniqueId");
- assertTrue(either.isLeft());
- }
-
- @Test
- public void testValidateNodeFilterStaticIncorrectPropertyTypeProvided() {
- Service service = createService("booleanIncorrect");
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
- assertTrue(either.isRight());
-
- either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.CAPABILITIES, EMPTY_STR);
- assertTrue(either.isRight());
- }
-
- @Test
- public void testValidateComponentFilter() {
- Service service = createService("booleanIncorrect");
- String property = "Prop1: {equal: {get_property: ['test','test2']}}";
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(property),
- NodeFilterConstraintAction.ADD);
- assertTrue(either.isRight());
-
- property = "Prop1: {equal: {get_property: ['parentservice','Prop1']}}";
- either =
- nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(property),
- NodeFilterConstraintAction.ADD);
- assertTrue(either.isLeft());
-
- String staticStr = "Prop1: {equal: 1}";
- either = nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(staticStr),
- NodeFilterConstraintAction.ADD);
- assertTrue(either.isLeft());
- assertTrue(either.left().value());
-
- staticStr = "Prop1: {equal: 'true'}";
- either = nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(staticStr),
- NodeFilterConstraintAction.ADD);
- assertTrue(either.isRight());
-
- staticStr = "Prop1: {greater_than: '3'}";
- either = nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(staticStr),
- NodeFilterConstraintAction.ADD);
- assertTrue(either.isRight());
-
- staticStr = "test: {greater_than: '3'}";
- either = nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(staticStr),
- NodeFilterConstraintAction.ADD);
- assertTrue(either.isRight());
- }
-
- @Test
- public void testValidateNodeFilterStaticIncorrectOperatorProvidedBoolean() {
- Service service = createService("boolean");
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")
- .replace("equal", "greater_than")),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertFalse(either.isLeft());
- }
-
- @Test
- public void testValidateNodeFilterStaticIncorrectValueProvidedBoolean() {
- Service service = createService("boolean");
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "trues")),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertFalse(either.isLeft());
- }
-
- @Test
- public void testValidateNodeFilterStaticIncorrectOperatorProvidedString() {
- Service service = createService(STRING_TYPE);
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")
- .replace("equal", "greater_than")),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertTrue(either.isLeft());
- }
-
- @Test
- public void testValidateNodeFilterIntegerValueSuccess() {
- Service service = createService(INTEGER_TYPE);
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "1")),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertTrue(either.isLeft());
- }
-
- @Test
- public void testValidateNodeFilterIntegerValueFail() {
- Service service = createService(INTEGER_TYPE);
-
- Mockito.when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, "param1"))
- .thenReturn(new ResponseFormat());
-
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "1.0")),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertTrue(either.isRight());
- }
-
- @Test
- public void testValidateNodeFilterFloatValueSuccess() {
- Service service = createService(FLOAT_TYPE);
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "1.0")),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertTrue(either.isLeft());
- }
-
- @Test
- public void testValidateNodeFilterFloatValueFail() {
- Service service = createService(FLOAT_TYPE);
-
- Mockito.when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, "param1"))
- .thenReturn(new ResponseFormat());
-
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertTrue(either.isRight());
- }
-
- @Test
- public void testValidateNodeFilterStringValueSuccess() {
- Service service = createService(STRING_TYPE);
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertTrue(either.isLeft());
- }
-
- @Test
- public void testValidatePropertyConstraintBrotherSuccess() {
- Service service = createService(STRING_TYPE);
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
- + " equal: { get_property :[component2, Prop1]}\n"), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertTrue(either.isLeft());
- }
-
- @Test
- public void testValidatePropertyConstraintParentSuccess() {
- Service service = createService(STRING_TYPE);
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
- + " equal: { get_property : [SELF, Prop1]}\n"), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertTrue(either.isLeft());
- }
-
- @Test
- public void testValidatePropertyConstraintBrotherPropertyTypeMismatch() {
- Service service = createService(STRING_TYPE);
- service.getComponentInstancesProperties().get(COMPONENT2_ID).get(0).setType(INTEGER_TYPE);
-
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
- + " equal: { get_property : [component2, Prop1]}\n"), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertFalse(either.isLeft());
- }
-
- @Test
- public void testValidatePropertyConstraintParentPropertyTypeMismatch() {
- Service service = createService(STRING_TYPE);
- service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(INTEGER_TYPE);
-
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
- + " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertFalse(either.isLeft());
- }
-
- @Test
- public void testValidatePropertyConstraintParentPropertyNotFound() {
- Service service = createService(STRING_TYPE);
- service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
-
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
- + " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertFalse(either.isLeft());
- }
-
- @Test
- public void testvalidatePropertyConstraintBrotherPropertyNotFound() {
- Service service = createService(STRING_TYPE);
- service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
-
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
- + " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertFalse(either.isLeft());
- }
-
- @Test
- public void testValidatePropertyConstraintParentPropertySchemaMismatch() {
- Service service = createService(LIST_TYPE,STRING_TYPE);
- service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(LIST_TYPE);
-
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
- + " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertFalse(either.isLeft());
- }
-
- private Service createService(String type) {
- return createService(type, null);
- }
-
- private Service createService(String type, String schemaType) {
- Service service = new Service();
- service.setName(PARENTSERVICE_ID);
-
- PropertyDefinition propertyDefinition = new PropertyDefinition();
- propertyDefinition.setName(PROPERTY_NAME);
- propertyDefinition.setType(type);
- if (schemaType != null){
- SchemaDefinition schemaDefinition = new SchemaDefinition();
- PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
- schemaProperty.setType(schemaType);
- schemaDefinition.setProperty(schemaProperty);
- propertyDefinition.setSchema(schemaDefinition);
- }
- service.setProperties(Collections.singletonList(propertyDefinition));
-
- ComponentInstance componentInstance = new ComponentInstance();
- componentInstance.setUniqueId(COMPONENT1_ID);
- componentInstance.setName(COMPONENT1_ID);
-
- ComponentInstance componentInstance2 = new ComponentInstance();
- componentInstance2.setUniqueId(COMPONENT2_ID);
- componentInstance2.setName(COMPONENT2_ID);
-
- service.setComponentInstances(Arrays.asList(componentInstance, componentInstance2));
-
- ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
- componentInstanceProperty.setName(PROPERTY_NAME);
- componentInstanceProperty.setType(type);
-
- ComponentInstanceProperty componentInstanceProperty2 = new ComponentInstanceProperty();
- componentInstanceProperty2.setName(PROPERTY_NAME);
- componentInstanceProperty2.setType(type);
-
- Map<String, List<ComponentInstanceProperty>> componentInstancePropertyMap = new HashMap<>();
- componentInstancePropertyMap.put(componentInstance.getUniqueId(),
- Collections.singletonList(componentInstanceProperty));
- componentInstancePropertyMap.put(componentInstance2.getUniqueId(),
- Collections.singletonList(componentInstanceProperty2));
- componentInstancePropertyMap.put(INNER_SERVICE, Collections.singletonList(componentInstanceProperty));
-
- service.setComponentInstancesProperties(componentInstancePropertyMap);
-
- return service;
- }
-
-}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidatorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidatorTest.java
new file mode 100644
index 0000000000..e1d8e46d74
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidatorTest.java
@@ -0,0 +1,553 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 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.components.validation;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+import fj.data.Either;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+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.datatypes.enums.PropertySource;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.be.model.validation.FilterConstraintValidator;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+class NodeFilterValidatorTest {
+
+ private static final String INNER_SERVICE = "innerService";
+ private static final String PROPERTY_NAME = "Prop1";
+ private static final String COMPONENT1_ID = "component1";
+ private static final String PARENTSERVICE_ID = "parentservice";
+ private static final String COMPONENT2_ID = "component2";
+ private ComponentsUtils componentsUtils;
+
+ @Mock
+ ApplicationDataTypeCache applicationDataTypeCache;
+ @Mock
+ private FilterConstraintValidator filterConstraintValidator;
+ @InjectMocks
+ private NodeFilterValidator nodeFilterValidator;
+ private FilterConstraintDto baseFilterConstraintDto;
+
+ @BeforeEach
+ void setup() {
+ componentsUtils = Mockito.mock(ComponentsUtils.class);
+ MockitoAnnotations.openMocks(this);
+ baseFilterConstraintDto = new FilterConstraintDto();
+ baseFilterConstraintDto.setPropertyName(PROPERTY_NAME);
+ baseFilterConstraintDto.setValueType(FilterValueType.STATIC);
+ baseFilterConstraintDto.setOperator(ConstraintType.EQUAL);
+ baseFilterConstraintDto.setTargetType(PropertyFilterTargetType.PROPERTY);
+ baseFilterConstraintDto.setValue("value");
+ when(applicationDataTypeCache.getAll(any())).thenReturn(Either.left(Map.of()));
+ new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
+ }
+
+ @Test
+ void testValidateComponentInstanceExist() {
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, "?", INNER_SERVICE)).thenReturn(expectedResponse);
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateComponentInstanceExist(null, INNER_SERVICE);
+ assertTrue(either.isRight());
+ assertEquals(expectedResponse, either.right().value());
+
+ Service service = createService("booleanIncorrect");
+ when(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, service.getName(), INNER_SERVICE))
+ .thenReturn(expectedResponse);
+ either = nodeFilterValidator.validateComponentInstanceExist(service, INNER_SERVICE);
+ assertTrue(either.isRight());
+ assertEquals(expectedResponse, either.right().value());
+
+ List<ComponentInstance> list = new LinkedList<>();
+ ComponentInstance instance = new ComponentInstance();
+ instance.setUniqueId("uniqueId");
+ list.add(instance);
+ service.setComponentInstances(list);
+ either = nodeFilterValidator.validateComponentInstanceExist(service, "uniqueId");
+ assertTrue(either.isLeft());
+ }
+
+ @Test
+ void testValidateNodeFilterStaticIncorrectPropertyTypeProvided() {
+ final Service service = createService("booleanIncorrect");
+ final FilterConstraintDto filterConstraintDto = buildFilterConstraintDto(PROPERTY_NAME, FilterValueType.STATIC, ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY, "true");
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, filterConstraintDto);
+ assertTrue(either.isRight());
+ filterConstraintDto.setTargetType(PropertyFilterTargetType.CAPABILITY);
+ either = nodeFilterValidator.validateFilter(service, INNER_SERVICE, filterConstraintDto);
+ assertTrue(either.isRight());
+ }
+
+ @Test
+ void testValidateComponentFilter() {
+ Service service = createService("integer");
+ final var filterConstraint1 = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ createToscaGetFunction("test", PropertySource.INSTANCE, ToscaGetFunctionType.GET_PROPERTY, List.of("test2"))
+ );
+ Either<Boolean, ResponseFormat> actualValidationResult =
+ nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint1));
+ assertTrue(actualValidationResult.isRight());
+
+ final var filterConstraint2 = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of("Prop1"))
+ );
+ actualValidationResult =
+ nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint2));
+ assertTrue(actualValidationResult.isLeft());
+
+ final var staticFilter1 = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.STATIC,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ 1
+ );
+ actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter1));
+ assertTrue(actualValidationResult.isLeft());
+ assertTrue(actualValidationResult.left().value());
+
+ final var staticFilter2 = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.STATIC,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ "true"
+ );
+ actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter2));
+ assertTrue(actualValidationResult.isRight());
+
+ service = createService(ToscaPropertyType.BOOLEAN.getType());
+ final var staticFilter3 = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.STATIC,
+ ConstraintType.GREATER_THAN,
+ PropertyFilterTargetType.PROPERTY,
+ "3"
+ );
+ actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter3));
+ assertTrue(actualValidationResult.isRight());
+
+ final var staticFilter4 = buildFilterConstraintDto(
+ "test",
+ FilterValueType.STATIC,
+ ConstraintType.GREATER_THAN,
+ PropertyFilterTargetType.PROPERTY,
+ "3"
+ );
+ actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(staticFilter4));
+ assertTrue(actualValidationResult.isRight());
+ }
+
+ @Test
+ void testValidateNodeFilterStaticIncorrectOperatorProvidedBoolean() {
+ Service service = createService(ToscaPropertyType.BOOLEAN.getType());
+ final FilterConstraintDto filterConstraintDto = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.STATIC,
+ ConstraintType.GREATER_THAN,
+ PropertyFilterTargetType.PROPERTY,
+ "true"
+ );
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, filterConstraintDto.getPropertyName(),
+ filterConstraintDto.getOperator().getType())
+ ).thenReturn(expectedResponse);
+ final Either<Boolean, ResponseFormat> validationResult =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(filterConstraintDto));
+ assertTrue(validationResult.isRight());
+ assertEquals(expectedResponse, validationResult.right().value());
+ }
+
+ @Test
+ void testValidateNodeFilterStaticIncorrectValueProvidedBoolean() {
+ final Service service = createService(ToscaPropertyType.BOOLEAN.getType());
+ baseFilterConstraintDto.setValue("trues");
+
+ final ResponseFormat responseFormat = new ResponseFormat();
+ when(componentsUtils
+ .getResponseFormat(eq(ActionStatus.UNSUPPORTED_VALUE_PROVIDED), eq(ToscaPropertyType.BOOLEAN.getType()), eq(PROPERTY_NAME), any())
+ ).thenReturn(responseFormat);
+ final Either<Boolean, ResponseFormat> validationResult =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
+
+ assertTrue(validationResult.isRight());
+ assertEquals(responseFormat, validationResult.right().value());
+ }
+
+ @Test
+ void testValidateNodeFilterStaticIncorrectOperatorProvidedString() {
+ Service service = createService(ToscaPropertyType.STRING.getType());
+ baseFilterConstraintDto.setValue("true");
+ baseFilterConstraintDto.setOperator(ConstraintType.GREATER_THAN);
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
+
+ assertTrue(either.isLeft());
+ }
+
+ @Test
+ void testValidateNodeFilterIntegerValueSuccess() {
+ Service service = createService(ToscaPropertyType.INTEGER.getType());
+ baseFilterConstraintDto.setValue(1);
+ Either<Boolean, ResponseFormat> validationResult =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
+
+ assertTrue(validationResult.isLeft());
+ }
+
+ @Test
+ void testValidateNodeFilterIntegerValueFail() {
+ Service service = createService(ToscaPropertyType.INTEGER.getType());
+
+ baseFilterConstraintDto.setValue(1.0);
+
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, ToscaPropertyType.INTEGER.getType(),
+ baseFilterConstraintDto.getPropertyName(), "1.0")
+ ).thenReturn(expectedResponse);
+ Either<Boolean, ResponseFormat> validationResult =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
+
+ assertTrue(validationResult.isRight());
+ assertEquals(expectedResponse, validationResult.right().value());
+ }
+
+ @Test
+ void testValidateNodeFilterFloatValueSuccess() {
+ final Service service = createService(ToscaPropertyType.FLOAT.getType());
+ baseFilterConstraintDto.setValue(1.0);
+ final Either<Boolean, ResponseFormat> validationResult =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
+
+ assertTrue(validationResult.isLeft());
+ assertTrue(validationResult.left().value());
+ }
+
+ @Test
+ void testValidateNodeFilterFloatValueFail() {
+ Service service = createService(ToscaPropertyType.FLOAT.getType());
+
+ when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, "param1")).thenReturn(new ResponseFormat());
+
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
+
+ assertTrue(either.isRight());
+ }
+
+ @Test
+ void testValidateNodeFilterStringValueSuccess() {
+ Service service = createService(ToscaPropertyType.STRING.getType());
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
+
+ assertTrue(either.isLeft());
+ }
+
+ @Test
+ void testValidatePropertyConstraintBrotherSuccess() {
+ Service service = createService(ToscaPropertyType.STRING.getType());
+ final ToscaGetFunctionDataDefinition toscaGetFunction =
+ createToscaGetFunction(COMPONENT2_ID, PropertySource.INSTANCE, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ final var filterConstraintDto = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ toscaGetFunction
+ );
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
+
+ assertTrue(either.isLeft());
+ assertTrue(either.left().value());
+ }
+
+ @Test
+ void testValidatePropertyConstraintParentSuccess() {
+ final var service = createService(ToscaPropertyType.STRING.getType());
+ final ToscaGetFunctionDataDefinition toscaGetFunction =
+ createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ final var filterConstraintDto = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ toscaGetFunction
+ );
+ final Either<Boolean, ResponseFormat> validationResult =
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
+
+ assertTrue(validationResult.isLeft());
+ assertTrue(validationResult.left().value());
+ }
+
+ @Test
+ void testValidatePropertyConstraintBrotherPropertyTypeMismatch() {
+ final Service service = createService(ToscaPropertyType.STRING.getType());
+ service.getComponentInstancesProperties().get(COMPONENT2_ID).get(0).setType(ToscaPropertyType.INTEGER.getType());
+ final ToscaGetFunctionDataDefinition toscaGetFunction =
+ createToscaGetFunction(COMPONENT2_ID, PropertySource.INSTANCE, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ final var filterConstraintDto = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ toscaGetFunction
+ );
+
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_PROPERTY_TYPE_MISMATCH,
+ PROPERTY_NAME, ToscaPropertyType.INTEGER.getType(), PROPERTY_NAME, ToscaPropertyType.STRING.getType())
+ ).thenReturn(expectedResponse);
+
+ final Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
+
+ assertTrue(either.isRight());
+ assertEquals(expectedResponse, either.right().value());
+ }
+
+ @Test
+ void testValidatePropertyConstraintParentPropertyTypeMismatch() {
+ final Service service = createService(ToscaPropertyType.STRING.getType());
+ service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(ToscaPropertyType.INTEGER.getType());
+ final ToscaGetFunctionDataDefinition toscaGetFunction =
+ createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ final var filterConstraintDto = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ toscaGetFunction
+ );
+
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_PROPERTY_TYPE_MISMATCH,
+ PROPERTY_NAME, ToscaPropertyType.STRING.getType(), PROPERTY_NAME, ToscaPropertyType.INTEGER.getType())
+ ).thenReturn(expectedResponse);
+
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
+
+ assertTrue(either.isRight());
+ assertEquals(expectedResponse, either.right().value());
+ }
+
+ @Test
+ void testValidatePropertyConstraintParentPropertyNotFound() {
+ final Service service = createService(ToscaPropertyType.STRING.getType());
+ service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
+
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(eq(ActionStatus.FILTER_PROPERTY_NOT_FOUND), any(), any()))
+ .thenReturn(expectedResponse);
+
+ final ToscaGetFunctionDataDefinition toscaGetFunction =
+ createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ final var filterConstraintDto = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ toscaGetFunction
+ );
+ final Either<Boolean, ResponseFormat> validationResult =
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
+
+ assertTrue(validationResult.isRight());
+ assertEquals(expectedResponse, validationResult.right().value());
+ }
+
+ @Test
+ void testValidatePropertyConstraintBrotherPropertyNotFound() {
+ Service service = createService(ToscaPropertyType.STRING.getType());
+ service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
+ final ToscaGetFunctionDataDefinition toscaGetFunction =
+ createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ final var filterConstraintDto = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ toscaGetFunction
+ );
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.FILTER_PROPERTY_NOT_FOUND, "Target", PROPERTY_NAME))
+ .thenReturn(expectedResponse);
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
+
+ assertTrue(either.isRight());
+ assertEquals(expectedResponse, either.right().value());
+ }
+
+ protected static ToscaGetFunctionDataDefinition createToscaGetFunction(final String sourceName,
+ final PropertySource propertySource,
+ final ToscaGetFunctionType toscaGetFunctionType,
+ final List<String> propertyPathFromSource) {
+ final var toscaGetFunction = new ToscaGetFunctionDataDefinition();
+ toscaGetFunction.setFunctionType(toscaGetFunctionType);
+ toscaGetFunction.setPropertyPathFromSource(propertyPathFromSource);
+ toscaGetFunction.setSourceName(sourceName);
+ toscaGetFunction.setPropertySource(propertySource);
+ toscaGetFunction.setPropertyName(propertyPathFromSource.get(0));
+ return toscaGetFunction;
+ }
+
+ @Test
+ void testValidatePropertyConstraintParentPropertySchemaMismatch() {
+ final Service service = createService(ToscaPropertyType.LIST.getType(), ToscaPropertyType.STRING.getType());
+ service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(ToscaPropertyType.LIST.getType());
+ final var schemaProperty = new PropertyDataDefinition();
+ schemaProperty.setType(ToscaPropertyType.INTEGER.getType());
+ final var schemaDefinition = new SchemaDefinition();
+ schemaDefinition.setProperty(schemaProperty);
+ service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setSchema(schemaDefinition);
+
+ final ToscaGetFunctionDataDefinition toscaGetFunction =
+ createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ final var filterConstraintDto = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ toscaGetFunction
+ );
+
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_SCHEMA_MISMATCH, PROPERTY_NAME, ToscaPropertyType.INTEGER.getType(),
+ PROPERTY_NAME, ToscaPropertyType.STRING.getType())
+ ).thenReturn(expectedResponse);
+
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
+
+ assertTrue(either.isRight());
+ assertEquals(expectedResponse, either.right().value());
+ }
+
+ private Service createService(String type) {
+ return createService(type, null);
+ }
+
+ private Service createService(String type, String schemaType) {
+ Service service = new Service();
+ service.setName(PARENTSERVICE_ID);
+
+ PropertyDefinition propertyDefinition = new PropertyDefinition();
+ propertyDefinition.setName(PROPERTY_NAME);
+ propertyDefinition.setType(type);
+ if (schemaType != null){
+ SchemaDefinition schemaDefinition = new SchemaDefinition();
+ PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
+ schemaProperty.setType(schemaType);
+ schemaDefinition.setProperty(schemaProperty);
+ propertyDefinition.setSchema(schemaDefinition);
+ }
+ service.setProperties(Collections.singletonList(propertyDefinition));
+
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(COMPONENT1_ID);
+ componentInstance.setName(COMPONENT1_ID);
+
+ ComponentInstance componentInstance2 = new ComponentInstance();
+ componentInstance2.setUniqueId(COMPONENT2_ID);
+ componentInstance2.setName(COMPONENT2_ID);
+
+ service.setComponentInstances(Arrays.asList(componentInstance, componentInstance2));
+
+ ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
+ componentInstanceProperty.setName(PROPERTY_NAME);
+ componentInstanceProperty.setType(type);
+
+ ComponentInstanceProperty componentInstanceProperty2 = new ComponentInstanceProperty();
+ componentInstanceProperty2.setName(PROPERTY_NAME);
+ componentInstanceProperty2.setType(type);
+
+ Map<String, List<ComponentInstanceProperty>> componentInstancePropertyMap = new HashMap<>();
+ componentInstancePropertyMap.put(componentInstance.getUniqueId(),
+ Collections.singletonList(componentInstanceProperty));
+ componentInstancePropertyMap.put(componentInstance2.getUniqueId(),
+ Collections.singletonList(componentInstanceProperty2));
+ componentInstancePropertyMap.put(INNER_SERVICE, Collections.singletonList(componentInstanceProperty));
+
+ service.setComponentInstancesProperties(componentInstancePropertyMap);
+
+ return service;
+ }
+
+ private static FilterConstraintDto buildFilterConstraintDto(final String propertyName, final FilterValueType valueType,
+ final ConstraintType constraintType,
+ final PropertyFilterTargetType targetType, Object value) {
+ final var filterConstraintDto = new FilterConstraintDto();
+ filterConstraintDto.setPropertyName(propertyName);
+ filterConstraintDto.setValueType(valueType);
+ filterConstraintDto.setOperator(constraintType);
+ filterConstraintDto.setTargetType(targetType);
+ filterConstraintDto.setValue(value);
+ return filterConstraintDto;
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java
index 9864cf456d..a66b19d1b3 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java
@@ -19,10 +19,9 @@
package org.openecomp.sdc.be.datamodel;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
import static org.hibernate.validator.internal.util.CollectionHelper.asSet;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -47,8 +46,12 @@ import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition;
+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.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
@@ -336,15 +339,27 @@ public class UiComponentDataConverterTest {
SubstitutionFilterDataDefinition substitutionFilter = new SubstitutionFilterDataDefinition();
substitutionFilter.setID(SUBSTITUTION_FILTER_UID);
- final ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> expectedPropertyFilters = new ListDataDefinition<>();
- var filter1 = new RequirementSubstitutionFilterPropertyDataDefinition();
+ final ListDataDefinition<SubstitutionFilterPropertyDataDefinition> expectedPropertyFilters = new ListDataDefinition<>();
+ var filter1 = new SubstitutionFilterPropertyDataDefinition();
filter1.setName("filter1");
- filter1.setConstraints(Collections.singletonList("constraint1: {equal: testvalue1}\n"));
+ var propertyFilter1 = new PropertyFilterConstraintDataDefinition();
+ propertyFilter1.setPropertyName("constraint1");
+ propertyFilter1.setOperator(ConstraintType.EQUAL);
+ propertyFilter1.setValueType(FilterValueType.STATIC);
+ propertyFilter1.setTargetType(PropertyFilterTargetType.PROPERTY);
+ propertyFilter1.setValue("testvalue1");
+ filter1.setConstraints(List.of(propertyFilter1));
expectedPropertyFilters.add(filter1);
- var filter2 = new RequirementSubstitutionFilterPropertyDataDefinition();
+ var filter2 = new SubstitutionFilterPropertyDataDefinition();
filter2.setName("filter2");
- filter2.setConstraints(Collections.singletonList("constraint2: {equal: testvalue2}\n"));
+ var propertyFilter2 = new PropertyFilterConstraintDataDefinition();
+ propertyFilter2.setPropertyName("constraint2");
+ propertyFilter2.setOperator(ConstraintType.EQUAL);
+ propertyFilter2.setValueType(FilterValueType.STATIC);
+ propertyFilter2.setTargetType(PropertyFilterTargetType.PROPERTY);
+ propertyFilter2.setValue("testvalue2");
+ filter2.setConstraints(List.of(propertyFilter2));
expectedPropertyFilters.add(filter2);
substitutionFilter.setProperties(expectedPropertyFilters);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ConstraintConvertorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertorTest.java
index 109af5562a..75eb48b86c 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ConstraintConvertorTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertorTest.java
@@ -13,33 +13,34 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.openecomp.sdc.be.tosca.model;
-import org.junit.Test;
-import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
-import org.openecomp.sdc.be.ui.model.UIConstraint;
+package org.openecomp.sdc.be.datamodel.utils;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import java.util.Map;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType;
+import org.openecomp.sdc.be.ui.model.UIConstraint;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-public class ConstraintConvertorTest {
+class ConstraintConvertorTest {
@Test
- public void convertStatic(){
+ void convertStatic(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = constraintConvertor.convert("mem_size: {equal: some static}\n");
assertNotNull(uiConstraint);
- assertEquals(uiConstraint.getConstraintOperator(),"equal");
- assertEquals(uiConstraint.getValue(),"some static");
- assertEquals(uiConstraint.getServicePropertyName().trim(),"mem_size");
+ assertEquals("equal",uiConstraint.getConstraintOperator());
+ assertEquals("some static",uiConstraint.getValue());
+ assertEquals("mem_size",uiConstraint.getServicePropertyName().trim());
}
@Test
- public void convertFromStatic(){
+ void convertFromStatic(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.STATIC_CONSTRAINT, "some static");
String constraint = constraintConvertor.convert(uiConstraint);
@@ -48,19 +49,19 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertSelfProperty(){
+ void convertSelfProperty(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = constraintConvertor.convert("mem_size:\n {equal: { get_property: [SELF, size] }}");
assertNotNull(uiConstraint);
- assertEquals(uiConstraint.getConstraintOperator(),"equal");
- assertEquals(uiConstraint.getValue(),"size");
- assertEquals(uiConstraint.getServicePropertyName().trim(),"mem_size");
- assertEquals(uiConstraint.getSourceName().trim(),"SELF");
- assertEquals(uiConstraint.getSourceType(), ConstraintConvertor.PROPERTY_CONSTRAINT);
+ assertEquals("equal",uiConstraint.getConstraintOperator());
+ assertEquals(uiConstraint.getValue(), Map.of(ToscaFunctionType.GET_PROPERTY.getName(), List.of("SELF", "size")));
+ assertEquals("mem_size",uiConstraint.getServicePropertyName().trim());
+ assertEquals("SELF",uiConstraint.getSourceName().trim());
+ assertEquals(uiConstraint.getSourceType(), ToscaFunctionType.GET_PROPERTY.getName());
}
@Test
- public void convertFromSelfProperty(){
+ void convertFromSelfProperty(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.PROPERTY_CONSTRAINT, "SELF" ,"some static");
String constraint = constraintConvertor.convert(uiConstraint);
@@ -69,19 +70,19 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertCIProperty(){
+ void convertCIProperty(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = constraintConvertor.convert("mem_size:\n" + " equal: { get_property: [A, size]}");
assertNotNull(uiConstraint);
- assertEquals(uiConstraint.getConstraintOperator(),"equal");
- assertEquals(uiConstraint.getValue(),"size");
- assertEquals(uiConstraint.getServicePropertyName().trim(),"mem_size");
- assertEquals(uiConstraint.getSourceName().trim(),"A");
+ assertEquals("equal",uiConstraint.getConstraintOperator());
+ assertEquals(uiConstraint.getValue(),Map.of(ToscaFunctionType.GET_PROPERTY.getName(), List.of("A", "size")));
+ assertEquals("mem_size",uiConstraint.getServicePropertyName().trim());
+ assertEquals("A",uiConstraint.getSourceName().trim());
}
@Test
- public void convertFromCIProperty(){
+ void convertFromCIProperty(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.PROPERTY_CONSTRAINT, "A" ,"size");
String constraint = constraintConvertor.convert(uiConstraint);
@@ -90,14 +91,14 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertServiceTemplateInput(){
+ void convertServiceTemplateInput(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = constraintConvertor.convert("mem_size: {equal: {get_input: InputName}}\n");
assertNotNull(uiConstraint);
}
@Test
- public void convertFromServiceTemplateInput(){
+ void convertFromServiceTemplateInput(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.SERVICE_INPUT_CONSTRAINT, "InputName");
String constraint = constraintConvertor.convert(uiConstraint);
@@ -106,17 +107,17 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertGreaterThanStatic(){
+ void convertGreaterThanStatic(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = constraintConvertor.convert("mem_size: {greater_than: 2}\n");
assertNotNull(uiConstraint);
- assertEquals(uiConstraint.getConstraintOperator(),"greater_than");
- assertEquals(uiConstraint.getValue(),2);
- assertEquals(uiConstraint.getServicePropertyName().trim(),"mem_size");
+ assertEquals("greater_than",uiConstraint.getConstraintOperator());
+ assertEquals(2,uiConstraint.getValue());
+ assertEquals("mem_size",uiConstraint.getServicePropertyName().trim());
}
@Test
- public void convertFromGreaterThanStatic(){
+ void convertFromGreaterThanStatic(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = new UIConstraint("mem_size", "greater_than" , ConstraintConvertor.STATIC_CONSTRAINT, 2);
String constraint = constraintConvertor.convert(uiConstraint);
@@ -125,14 +126,14 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertLessThanServiceProperty(){
+ void convertLessThanServiceProperty(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = constraintConvertor.convert("mem_size: {less_then: {get_input: InputName}}");
assertNotNull(uiConstraint);
}
@Test
- public void convertFromLessThanServiceProperty(){
+ void convertFromLessThanServiceProperty(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = new UIConstraint("mem_size", "less_then" , ConstraintConvertor.SERVICE_INPUT_CONSTRAINT, "InputName");
String constraint = constraintConvertor.convert(uiConstraint);
@@ -141,7 +142,7 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertFromEqualStaticMap(){
+ void convertFromEqualStaticMap(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.STATIC_CONSTRAINT, "{x: xx,"+
" y: yy}\n");
@@ -151,7 +152,7 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertStringToMap(){
+ void convertStringToMap(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = constraintConvertor.convert("mem_size:\n" + " equal: {x: xx, y: yy}\n");
assertNotNull(uiConstraint);
@@ -159,7 +160,7 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertFromEqualStaticList(){
+ void convertFromEqualStaticList(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.STATIC_CONSTRAINT, "[x, y]\n");
String constraint = constraintConvertor.convert(uiConstraint);
@@ -168,7 +169,7 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertStringToList(){
+ void convertStringToList(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = constraintConvertor.convert("mem_size:\n" + " equal: [x, y]\n");
assertNotNull(uiConstraint);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java
index 68ceaca0a6..7948f84f96 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java
@@ -16,13 +16,18 @@
package org.openecomp.sdc.be.nodeFilter;
-import java.util.Arrays;
-import org.junit.Assert;
-import org.junit.Before;
+import java.util.List;
+import org.junit.jupiter.api.BeforeEach;
import org.openecomp.sdc.be.config.ConfigurationManager;
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.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.datatypes.tosca.ToscaGetFunctionType;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Service;
@@ -32,47 +37,60 @@ import org.openecomp.sdc.common.impl.FSConfigurationSource;
public class BaseServiceFilterUtilsTest {
protected Service service;
- protected RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition;
- protected RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition2;
+ protected PropertyFilterDataDefinition propertyFilterDataDefinition;
+ protected PropertyFilterDataDefinition propertyFilterDataDefinition2;
protected static final String CI_NAME = "AAAAAA";
protected static final String A_PROP_NAME = "A_PROP";
protected static final String SIZE_PROP = "size";
- protected static final String ORIG_COMP_INSTANCE_ID = "54355645457457";
- @Before
- public void initService() {
- try {
- new ConfigurationManager(new FSConfigurationSource(
- ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
- service = new Service();
- ComponentInstance componentInstance = new ComponentInstance();
- componentInstance.setUniqueId(CI_NAME);
- componentInstance.setName(CI_NAME);
- service.setComponentInstances(Arrays.asList(componentInstance));
- componentInstance.setDirectives(ConfigurationManager.getConfigurationManager().getConfiguration()
- .getDirectives());
- CINodeFilterDataDefinition serviceFilter = new CINodeFilterDataDefinition();
- componentInstance.setNodeFilter(serviceFilter);
- requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition();
- requirementNodeFilterPropertyDataDefinition.setName("Name1");
- requirementNodeFilterPropertyDataDefinition
- .setConstraints(Arrays.asList("mem_size:\n" + " equal: { get_property : [" + CI_NAME + ", size]}\n"));
- requirementNodeFilterPropertyDataDefinition2 = new RequirementNodeFilterPropertyDataDefinition();
- requirementNodeFilterPropertyDataDefinition2.setName("Name2");
- requirementNodeFilterPropertyDataDefinition2
- .setConstraints(Arrays.asList("mem_size:\n {equal: { get_property : [SELF, "+A_PROP_NAME+"]}}\n"));
+ @BeforeEach
+ void initService() {
+ new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
+ service = new Service();
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(CI_NAME);
+ componentInstance.setName(CI_NAME);
+ service.setComponentInstances(List.of(componentInstance));
+ componentInstance.setDirectives(ConfigurationManager.getConfigurationManager().getConfiguration()
+ .getDirectives());
+ CINodeFilterDataDefinition serviceFilter = new CINodeFilterDataDefinition();
+ componentInstance.setNodeFilter(serviceFilter);
+ propertyFilterDataDefinition = new PropertyFilterDataDefinition();
+ propertyFilterDataDefinition.setName("Name1");
+ final var propertyFilterConstraint1 = new PropertyFilterConstraintDataDefinition();
+ propertyFilterConstraint1.setPropertyName("mem_size");
+ propertyFilterConstraint1.setOperator(ConstraintType.EQUAL);
+ propertyFilterConstraint1.setValue(createToscaGetFunction(CI_NAME, ToscaGetFunctionType.GET_PROPERTY, List.of("size")));
+ propertyFilterConstraint1.setValueType(FilterValueType.GET_PROPERTY);
+ propertyFilterConstraint1.setTargetType(PropertyFilterTargetType.PROPERTY);
+ propertyFilterDataDefinition.setConstraints(List.of(propertyFilterConstraint1));
+ propertyFilterDataDefinition2 = new PropertyFilterDataDefinition();
+ propertyFilterDataDefinition2.setName("Name2");
+ final var propertyFilterConstraint2 = new PropertyFilterConstraintDataDefinition();
+ propertyFilterConstraint2.setPropertyName("mem_size");
+ propertyFilterConstraint2.setOperator(ConstraintType.EQUAL);
+ propertyFilterConstraint2.setValue(createToscaGetFunction("SELF", ToscaGetFunctionType.GET_PROPERTY, List.of(A_PROP_NAME)));
+ propertyFilterConstraint2.setValueType(FilterValueType.GET_PROPERTY);
+ propertyFilterConstraint2.setTargetType(PropertyFilterTargetType.PROPERTY);
+ propertyFilterDataDefinition2.setConstraints(List.of(propertyFilterConstraint2));
- ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> listDataDefinition =
- new ListDataDefinition<>(Arrays.asList(
- requirementNodeFilterPropertyDataDefinition,
- requirementNodeFilterPropertyDataDefinition2));
- serviceFilter.setProperties(listDataDefinition);
- PropertyDefinition property = new PropertyDefinition();
- property.setName(A_PROP_NAME);
- service.setProperties(Arrays.asList(property));
- } catch (Exception e) {
- Assert.fail(e.getMessage());
- }
+ ListDataDefinition<PropertyFilterDataDefinition> listDataDefinition =
+ new ListDataDefinition<>(List.of(propertyFilterDataDefinition, propertyFilterDataDefinition2));
+ serviceFilter.setProperties(listDataDefinition);
+ PropertyDefinition property = new PropertyDefinition();
+ property.setName(A_PROP_NAME);
+ service.setProperties(List.of(property));
+ }
+
+ protected static ToscaGetFunctionDataDefinition createToscaGetFunction(final String sourceName,
+ final ToscaGetFunctionType toscaGetFunctionType,
+ final List<String> propertyPathFromSource) {
+ final var toscaGetFunction = new ToscaGetFunctionDataDefinition();
+ toscaGetFunction.setFunctionType(toscaGetFunctionType);
+ toscaGetFunction.setPropertyPathFromSource(propertyPathFromSource);
+ toscaGetFunction.setSourceName(sourceName);
+ toscaGetFunction.setPropertyName(propertyPathFromSource.get(0));
+ return toscaGetFunction;
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterRenameCiTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterRenameCiTest.java
index 8e94b94e61..d18f6039f2 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterRenameCiTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterRenameCiTest.java
@@ -16,31 +16,28 @@
package org.openecomp.sdc.be.nodeFilter;
-import org.junit.Test;
-import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
-import org.openecomp.sdc.be.impl.ServiceFilterUtils;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.List;
import java.util.Map;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
+import org.openecomp.sdc.be.impl.ServiceFilterUtils;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-public class ServiceFilterRenameCiTest extends BaseServiceFilterUtilsTest {
+class ServiceFilterRenameCiTest extends BaseServiceFilterUtilsTest {
protected static final String CI_NEW_NAME = "BBBBB";
@Test
- public void renameCI() {
+ void renameCI() {
Map<String, CINodeFilterDataDefinition> renamedNodeFilters = getRenamedNodeFilters(CI_NAME, CI_NEW_NAME);
assertNotNull(renamedNodeFilters);
- final List<String> constraints =
+ final List<PropertyFilterConstraintDataDefinition> constraints =
renamedNodeFilters.get(CI_NAME).getProperties().getListToscaDataDefinition().iterator().next()
.getConstraints();
- assertEquals(1,constraints.size());
- final String constraint = constraints.iterator().next();
- assertTrue(constraint.contains(CI_NEW_NAME));
+ assertEquals(1, constraints.size());
}
private Map<String, CINodeFilterDataDefinition> getRenamedNodeFilters(String oldName, String newName) {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsCIChangeTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsCIChangeTest.java
index 57b95e2fbe..374e8209ed 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsCIChangeTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsCIChangeTest.java
@@ -16,13 +16,25 @@
package org.openecomp.sdc.be.nodeFilter;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import fj.data.Either;
-import org.junit.Test;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.List;
+import java.util.Set;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+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.datatypes.tosca.ToscaGetFunctionType;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServiceFilterUtils;
import org.openecomp.sdc.be.model.ComponentInstance;
@@ -31,43 +43,38 @@ import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Set;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-public class ServiceFilterUtilsCIChangeTest extends BaseServiceFilterUtilsTest {
-
+class ServiceFilterUtilsCIChangeTest extends BaseServiceFilterUtilsTest {
@Test
- public void checkComponentInstanceIsFound() {
+ void checkComponentInstanceIsFound() {
Set<String> nodesFiltersToBeDeleted = getNodeFiltersToBeDeleted(CI_NAME);
assertNotNull(nodesFiltersToBeDeleted);
assertTrue(nodesFiltersToBeDeleted.contains(CI_NAME));
}
private Set<String> getNodeFiltersToBeDeleted(String inCiName) {
- requirementNodeFilterPropertyDataDefinition
- .setConstraints(Arrays.asList("mem_size:\n" + " equal:\n" + " get_property: ["+CI_NAME+", some static]\n"));
- ComponentInstance ci = new ComponentInstance();
- ci.setName(inCiName);
- return ServiceFilterUtils.getNodesFiltersToBeDeleted(service, ci);
+ final var propertyFilterConstraint = new PropertyFilterConstraintDataDefinition();
+ propertyFilterConstraint.setPropertyName("mem_size");
+ propertyFilterConstraint.setOperator(ConstraintType.EQUAL);
+ propertyFilterConstraint.setValue(createToscaGetFunction(CI_NAME, ToscaGetFunctionType.GET_PROPERTY, List.of("some static")));
+ propertyFilterConstraint.setValueType(FilterValueType.GET_PROPERTY);
+ propertyFilterConstraint.setTargetType(PropertyFilterTargetType.PROPERTY);
+ propertyFilterDataDefinition
+ .setConstraints(List.of(propertyFilterConstraint));
+ final var componentInstance = new ComponentInstance();
+ componentInstance.setName(inCiName);
+ return ServiceFilterUtils.getNodesFiltersToBeDeleted(service, componentInstance);
}
@Test
- public void checkComponentInstanceIsNotFound() {
+ void checkComponentInstanceIsNotFound() {
Set<String> nodesFiltersToBeDeleted = getNodeFiltersToBeDeleted(CI_NAME + " aaa bbb");
assertNotNull(nodesFiltersToBeDeleted);
assertTrue(nodesFiltersToBeDeleted.isEmpty());
- assertFalse(nodesFiltersToBeDeleted.contains(CI_NAME));
}
@Test
- public void testServiceConstraintPairSerialization() throws IOException {
+ void testServiceConstraintPairSerialization() throws IOException {
UIConstraint uiConstraint =new UIConstraint();
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsPropertyRemovedTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsPropertyRemovedTest.java
index 0b40359d60..47f462bb15 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsPropertyRemovedTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsPropertyRemovedTest.java
@@ -16,23 +16,24 @@
package org.openecomp.sdc.be.nodeFilter;
-import org.junit.Test;
-import org.openecomp.sdc.be.impl.ServiceFilterUtils;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.impl.ServiceFilterUtils;
-public class ServiceFilterUtilsPropertyRemovedTest extends BaseServiceFilterUtilsTest {
+class ServiceFilterUtilsPropertyRemovedTest extends BaseServiceFilterUtilsTest {
@Test
- public void checkPropertyIsFound() {
+ void checkPropertyIsFound() {
assertTrue(ServiceFilterUtils.isNodeFilterAffectedByPropertyRemoval(service, CI_NAME, SIZE_PROP));
}
@Test
- public void checkPropertyIsNotFound() {
+ void checkPropertyIsNotFound() {
assertFalse(ServiceFilterUtils.isNodeFilterAffectedByPropertyRemoval(service, CI_NAME, A_PROP_NAME + "XXXX"));
}
}
+
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsServiceInputTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsServiceInputTest.java
index e17da93b0e..0d473518cd 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsServiceInputTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsServiceInputTest.java
@@ -16,42 +16,52 @@
package org.openecomp.sdc.be.nodeFilter;
-import org.junit.Test;
-import org.openecomp.sdc.be.impl.ServiceFilterUtils;
-import org.openecomp.sdc.be.model.InputDefinition;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.util.Arrays;
+import java.util.List;
import java.util.Set;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
+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.datatypes.enums.PropertySource;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
+import org.openecomp.sdc.be.impl.ServiceFilterUtils;
+import org.openecomp.sdc.be.model.InputDefinition;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-public class ServiceFilterUtilsServiceInputTest extends BaseServiceFilterUtilsTest {
+class ServiceFilterUtilsServiceInputTest extends BaseServiceFilterUtilsTest {
private static final String CONSTRAINT_NAME = "InputName";
-
@Test
- public void checkInputStreamIsFound() {
+ void checkInputStreamIsFound() {
Set<String> nodesFiltersToBeDeleted = getNodeFiltersToBeDeleted(CONSTRAINT_NAME);
assertNotNull(nodesFiltersToBeDeleted);
assertTrue(nodesFiltersToBeDeleted.contains(CI_NAME));
}
private Set<String> getNodeFiltersToBeDeleted(String constraintName) {
- requirementNodeFilterPropertyDataDefinition
- .setConstraints(Arrays.asList("mem_size:\n equal: {get_input: " + CONSTRAINT_NAME + "}\n"));
+ final var propertyFilterConstraint = new PropertyFilterConstraintDataDefinition();
+ propertyFilterConstraint.setPropertyName("mem_size");
+ propertyFilterConstraint.setOperator(ConstraintType.EQUAL);
+
+ propertyFilterConstraint.setValue(
+ createToscaGetFunction(PropertySource.SELF.getName(), ToscaGetFunctionType.GET_INPUT, List.of(CONSTRAINT_NAME))
+ );
+ propertyFilterConstraint.setValueType(FilterValueType.GET_INPUT);
+ propertyFilterConstraint.setTargetType(PropertyFilterTargetType.PROPERTY);
+ propertyFilterDataDefinition.setConstraints(List.of(propertyFilterConstraint));
InputDefinition inputDefinition = new InputDefinition();
inputDefinition.setName(constraintName);
return ServiceFilterUtils.getNodesFiltersToBeDeleted(service, inputDefinition);
}
@Test
- public void checkInputStreamIsNOtFound() {
+ public void checkInputStreamIsNotFound() {
Set<String> nodesFiltersToBeDeleted = getNodeFiltersToBeDeleted(CONSTRAINT_NAME + " aaa bbb");
assertNotNull(nodesFiltersToBeDeleted);
assertTrue(nodesFiltersToBeDeleted.isEmpty());
- assertFalse(nodesFiltersToBeDeleted.contains(CI_NAME));
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java
index 548a046229..49252109cd 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java
@@ -20,13 +20,12 @@
package org.openecomp.sdc.be.servlets;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -35,8 +34,8 @@ import static org.openecomp.sdc.common.api.Constants.USER_ID_HEADER;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import java.util.Arrays;
import java.util.LinkedList;
+import java.util.List;
import java.util.Optional;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
@@ -49,7 +48,6 @@ import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
-import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
@@ -57,7 +55,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
@@ -65,7 +62,6 @@ import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentNodeFilterBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
-import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.config.SpringConfig;
@@ -73,14 +69,16 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
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.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
+import org.openecomp.sdc.be.ui.mapper.FilterConstraintMapper;
import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
@@ -111,6 +109,7 @@ class ComponentNodeFilterServletTest extends JerseyTest {
private static final String V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER = "/v1/catalog/%s/%s/componentInstance/%s/%s/nodeFilter";
private final UIConstraint uiConstraint = new UIConstraint("resourceType", "equal", "static", "static", "resourceTypeValue");
private final String constraint = new ConstraintConvertor().convert(uiConstraint);
+ private final FilterConstraintDto filterConstraintDto = new FilterConstraintMapper().mapFrom(uiConstraint);
private final String inputJson = buildConstraintDataJson(uiConstraint);
private final User user = new User("", "", USER_ID, "", Role.ADMIN.name(), null);
@Mock
@@ -176,7 +175,7 @@ class ComponentNodeFilterServletTest extends JerseyTest {
}
@Test
- void addNodeFilterPropertiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
+ void addNodeFilterPropertiesSuccessTest() throws BusinessLogicException {
initComponentData();
final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER;
final String path = String.format(pathFormat, componentType, componentId, componentInstance,
@@ -194,7 +193,7 @@ class ComponentNodeFilterServletTest extends JerseyTest {
assertThat(propertyValue).isEqualToIgnoringCase(uiConstraint.getValue().toString());
doReturn(Optional.of(uiConstraint)).when(componentsUtils)
- .parseToConstraint(anyString(), any(User.class), ArgumentMatchers.any(ComponentTypeEnum.class));
+ .parseToConstraint(anyString(), any(User.class), any(ComponentTypeEnum.class));
assertNotNull(constraint);
assertNotNull(ciNodeFilterDataDefinition);
@@ -202,8 +201,7 @@ class ComponentNodeFilterServletTest extends JerseyTest {
assertThat("resourceType: {equal: resourceTypeValue}\n").isEqualToIgnoringCase(constraint);
doReturn(Optional.of(ciNodeFilterDataDefinition)).when(componentNodeFilterBusinessLogic)
- .addNodeFilter(componentId, componentInstance, NodeFilterConstraintAction.ADD,
- uiConstraint.getServicePropertyName(), constraint, true, ComponentTypeEnum.RESOURCE,
+ .addNodeFilter(componentId, componentInstance, filterConstraintDto, true, ComponentTypeEnum.RESOURCE,
NodeFilterConstraintType.PROPERTIES, "");
final Response response = target()
@@ -213,9 +211,9 @@ class ComponentNodeFilterServletTest extends JerseyTest {
.post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
verify(componentNodeFilterBusinessLogic, times(1))
- .addNodeFilter(anyString(), anyString(), ArgumentMatchers.any(NodeFilterConstraintAction.class), anyString(),
- anyString(), anyBoolean(), ArgumentMatchers.any(ComponentTypeEnum.class),
- ArgumentMatchers.any(NodeFilterConstraintType.class), anyString());
+ .addNodeFilter(anyString(), anyString(), any(FilterConstraintDto.class), anyBoolean(), any(ComponentTypeEnum.class),
+ any(NodeFilterConstraintType.class), anyString()
+ );
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
@@ -224,8 +222,7 @@ class ComponentNodeFilterServletTest extends JerseyTest {
@Test
void addNodeFilterCapabilitiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
initComponentData();
- final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER;
- final String path = String.format(pathFormat, componentType, componentId, componentInstance,
+ final String path = String.format(V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER, componentType, componentId, componentInstance,
NodeFilterConstraintType.CAPABILITIES_PARAM_NAME);
final UIConstraint uiConstraint1 = new UIConstraint(uiConstraint.getServicePropertyName(), uiConstraint.getConstraintOperator(),
uiConstraint.getSourceType(), uiConstraint.getSourceName(), uiConstraint.getValue());
@@ -234,27 +231,24 @@ class ComponentNodeFilterServletTest extends JerseyTest {
when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
doReturn(componentsUtils).when(servletUtils).getComponentsUtils();
uiConstraint1.setCapabilityName(capabilityName);
-
- when(componentsUtils.parseToConstraint(anyString(), any(User.class), ArgumentMatchers.any(ComponentTypeEnum.class)))
- .thenReturn(Optional.of(uiConstraint1));
+ final String requestPayload = buildConstraintDataJson(uiConstraint1);
+ when(componentsUtils.parseToConstraint(requestPayload, user, ComponentTypeEnum.RESOURCE)).thenReturn(Optional.of(uiConstraint1));
assertThat(ciNodeFilterDataDefinition.getProperties().getListToscaDataDefinition()).hasSize(1);
+ final FilterConstraintDto filterConstraintDto1 = new FilterConstraintMapper().mapFrom(uiConstraint1);
when(componentNodeFilterBusinessLogic
- .addNodeFilter(componentId, componentInstance, NodeFilterConstraintAction.ADD,
- uiConstraint1.getServicePropertyName(), constraint, true, ComponentTypeEnum.RESOURCE,
- NodeFilterConstraintType.CAPABILITIES, capabilityName))
- .thenReturn(Optional.of(ciNodeFilterDataDefinition));
-
+ .addNodeFilter(componentId, componentInstance, filterConstraintDto1, true, ComponentTypeEnum.RESOURCE,
+ NodeFilterConstraintType.CAPABILITIES, capabilityName)
+ ).thenReturn(Optional.of(ciNodeFilterDataDefinition));
final Response response = target()
.path(path)
.request(MediaType.APPLICATION_JSON)
.header(USER_ID_HEADER, USER_ID)
- .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
+ .post(Entity.entity(requestPayload, MediaType.APPLICATION_JSON));
verify(componentNodeFilterBusinessLogic, times(1))
- .addNodeFilter(anyString(), anyString(), ArgumentMatchers.any(NodeFilterConstraintAction.class), anyString(),
- anyString(), anyBoolean(), ArgumentMatchers.any(ComponentTypeEnum.class),
- ArgumentMatchers.any(NodeFilterConstraintType.class), anyString());
+ .addNodeFilter(componentId, componentInstance, filterConstraintDto1, true, ComponentTypeEnum.RESOURCE,
+ NodeFilterConstraintType.CAPABILITIES, capabilityName);
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
@@ -352,7 +346,7 @@ class ComponentNodeFilterServletTest extends JerseyTest {
when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
- when(componentsUtils.parseToConstraint(anyString(), any(User.class), ArgumentMatchers.any(ComponentTypeEnum.class)))
+ when(componentsUtils.parseToConstraint(anyString(), any(User.class), any(ComponentTypeEnum.class)))
.thenReturn(Optional.of(uiConstraint));
doReturn(componentsUtils).when(servletUtils).getComponentsUtils();
when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
@@ -370,8 +364,8 @@ class ComponentNodeFilterServletTest extends JerseyTest {
.put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
verify(componentNodeFilterBusinessLogic, times(1))
- .updateNodeFilter(anyString(), anyString(), ArgumentMatchers.any(UIConstraint.class),
- ArgumentMatchers.any(ComponentTypeEnum.class), ArgumentMatchers.any(NodeFilterConstraintType.class),
+ .updateNodeFilter(anyString(), anyString(), any(UIConstraint.class),
+ any(ComponentTypeEnum.class), any(NodeFilterConstraintType.class),
anyInt());
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
@@ -447,9 +441,8 @@ class ComponentNodeFilterServletTest extends JerseyTest {
when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
- when(componentNodeFilterBusinessLogic.deleteNodeFilter(componentId, componentInstance,
- NodeFilterConstraintAction.DELETE, null, 0, true, ComponentTypeEnum.RESOURCE,
- NodeFilterConstraintType.PROPERTIES))
+ when(componentNodeFilterBusinessLogic
+ .deleteNodeFilter(componentId, componentInstance, 0, true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES))
.thenReturn(Optional.of(ciNodeFilterDataDefinition));
final Response response = target()
@@ -460,9 +453,7 @@ class ComponentNodeFilterServletTest extends JerseyTest {
.delete(Response.class);
verify(componentNodeFilterBusinessLogic, times(1))
- .deleteNodeFilter(anyString(), anyString(), ArgumentMatchers.any(NodeFilterConstraintAction.class),
- nullable(String.class), anyInt(), anyBoolean(), ArgumentMatchers.any(ComponentTypeEnum.class),
- ArgumentMatchers.any(NodeFilterConstraintType.class));
+ .deleteNodeFilter(anyString(), anyString(), anyInt(), anyBoolean(), any(ComponentTypeEnum.class), any(NodeFilterConstraintType.class));
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
@@ -503,14 +494,14 @@ class ComponentNodeFilterServletTest extends JerseyTest {
.property("contextConfig", context);
}
- private void initComponentData() throws JsonProcessingException {
- final RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition =
- new RequirementNodeFilterPropertyDataDefinition();
- requirementNodeFilterPropertyDataDefinition.setName(uiConstraint.getServicePropertyName());
- requirementNodeFilterPropertyDataDefinition.setConstraints(new LinkedList<>(Arrays.asList(constraint)));
+ private void initComponentData() {
+ final PropertyFilterDataDefinition propertyFilterDataDefinition =
+ new PropertyFilterDataDefinition();
+ propertyFilterDataDefinition.setName(uiConstraint.getServicePropertyName());
+ propertyFilterDataDefinition.setConstraints(new LinkedList<>(List.of(new FilterConstraintMapper().mapTo(filterConstraintDto))));
- final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> propertyDataDefinitionList =
- new ListDataDefinition<>(new LinkedList<>(Arrays.asList(requirementNodeFilterPropertyDataDefinition)));
+ final ListDataDefinition<PropertyFilterDataDefinition> propertyDataDefinitionList =
+ new ListDataDefinition<>(new LinkedList<>(List.of(propertyFilterDataDefinition)));
final RequirementNodeFilterCapabilityDataDefinition requirementNodeFilterCapabilityDataDefinition =
new RequirementNodeFilterCapabilityDataDefinition();
@@ -518,7 +509,7 @@ class ComponentNodeFilterServletTest extends JerseyTest {
requirementNodeFilterCapabilityDataDefinition.setProperties(propertyDataDefinitionList);
final ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> capabilityDataDefinitionList =
- new ListDataDefinition<>(new LinkedList<>(Arrays.asList(requirementNodeFilterCapabilityDataDefinition)));
+ new ListDataDefinition<>(new LinkedList<>(List.of(requirementNodeFilterCapabilityDataDefinition)));
ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
ciNodeFilterDataDefinition.setProperties(propertyDataDefinitionList);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServletTest.java
index bcc0f2eadb..9bd7244e04 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServletTest.java
@@ -22,11 +22,11 @@ package org.openecomp.sdc.be.servlets;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.nullable;
-import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
@@ -36,9 +36,8 @@ import static org.openecomp.sdc.common.api.Constants.USER_ID_HEADER;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import java.util.Arrays;
import java.util.Collections;
-import java.util.LinkedList;
+import java.util.List;
import java.util.Optional;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
@@ -46,7 +45,6 @@ import javax.servlet.http.HttpSession;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-
import org.eclipse.jetty.http.HttpStatus;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.server.ResourceConfig;
@@ -62,24 +60,24 @@ import org.openecomp.sdc.be.components.impl.ComponentSubstitutionFilterBusinessL
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.components.validation.UserValidations;
-import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.config.SpringConfig;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
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.ComponentTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
+import org.openecomp.sdc.be.ui.mapper.FilterConstraintMapper;
import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.exception.ResponseFormat;
@@ -112,13 +110,11 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
private static ComponentSubstitutionFilterBusinessLogic componentSubstitutionFilterBusinessLogic;
private static ResponseFormat responseFormat;
private static UserValidations userValidations;
- private static ConfigurationManager configurationManager;
private SubstitutionFilterDataDefinition substitutionFilterDataDefinition;
- private RequirementSubstitutionFilterPropertyDataDefinition requirementSubstitutionFilterPropertyDataDefinition;
private UIConstraint uiConstraint;
- private String constraint;
private String inputJson;
private User user;
+ private FilterConstraintDto filterConstraintDto;
@BeforeAll
public static void initClass() {
@@ -135,7 +131,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
when(servletUtils.getComponentsUtils()).thenReturn(componentsUtils);
String appConfigDir = "src/test/resources/config/catalog-be";
ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
- configurationManager = new ConfigurationManager(configurationSource);
+ ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
org.openecomp.sdc.be.config.Configuration configuration = new org.openecomp.sdc.be.config.Configuration();
configuration.setJanusGraphInMemoryGraph(true);
configurationManager.setConfiguration(configuration);
@@ -155,7 +151,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
}
@Test
- public void addSubstitutionFilterTest() throws Exception {
+ void addSubstitutionFilterTest() throws Exception {
final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
final String path = String.format(pathFormat, componentType, componentId, constraintType);
@@ -165,21 +161,19 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
assertNotNull(uiConstraint);
- assertThat(servicePropertyName).isEqualToIgnoringCase(uiConstraint.getServicePropertyName());
- assertThat(constraintOperator).isEqualToIgnoringCase(uiConstraint.getConstraintOperator());
- assertThat(sourceType).isEqualToIgnoringCase(uiConstraint.getSourceType());
- assertThat(sourceName).isEqualToIgnoringCase(uiConstraint.getSourceName());
- assertThat(propertyValue).isEqualToIgnoringCase(uiConstraint.getValue().toString());
+ assertThat(uiConstraint.getServicePropertyName()).isEqualToIgnoringCase(servicePropertyName);
+ assertThat(uiConstraint.getConstraintOperator()).isEqualToIgnoringCase(constraintOperator);
+ assertThat(uiConstraint.getSourceType()).isEqualToIgnoringCase(sourceType);
+ assertThat(uiConstraint.getSourceName()).isEqualToIgnoringCase(sourceName);
+ assertThat(uiConstraint.getValue().toString()).isEqualToIgnoringCase(propertyValue);
when(componentsUtils.parseToConstraint(anyString(), any(User.class), any(ComponentTypeEnum.class)))
.thenReturn(Optional.of(uiConstraint));
- assertNotNull(constraint);
assertNotNull(substitutionFilterDataDefinition);
assertThat(substitutionFilterDataDefinition.getProperties().getListToscaDataDefinition()).hasSize(1);
- assertThat("controller_actor: {equal: constraintValue}\n").isEqualToIgnoringCase(constraint);
- when(componentSubstitutionFilterBusinessLogic.addSubstitutionFilter(componentId, uiConstraint.getServicePropertyName(), constraint,
- true, ComponentTypeEnum.SERVICE)).thenReturn(Optional.of(substitutionFilterDataDefinition));
+ when(componentSubstitutionFilterBusinessLogic.addSubstitutionFilter(componentId, filterConstraintDto, true, ComponentTypeEnum.SERVICE))
+ .thenReturn(Optional.of(substitutionFilterDataDefinition));
final Response response = target()
.path(path)
@@ -190,12 +184,11 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
verify(componentSubstitutionFilterBusinessLogic, times(1))
- .addSubstitutionFilter(componentId, uiConstraint.getServicePropertyName(), constraint,
- true, ComponentTypeEnum.SERVICE);
+ .addSubstitutionFilter(componentId, filterConstraintDto, true, ComponentTypeEnum.SERVICE);
}
@Test
- public void addSubstitutionFilterFailConstraintParseTest() {
+ void addSubstitutionFilterFailConstraintParseTest() {
final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
final String path = String.format(pathFormat, componentType, componentId, constraintType);
@@ -216,7 +209,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
}
@Test
- public void addSubstitutionFilterFailTest() {
+ void addSubstitutionFilterFailTest() {
final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
final String path = String.format(pathFormat, componentType, componentId, constraintType);
@@ -237,7 +230,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
}
@Test
- public void updateSubstitutionFilterTest() throws BusinessLogicException {
+ void updateSubstitutionFilterTest() throws BusinessLogicException {
final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
final String path = String.format(pathFormat, componentType, componentId, constraintType);
@@ -250,7 +243,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
any(User.class))).thenReturn(Collections.singletonList(uiConstraint));
when(componentSubstitutionFilterBusinessLogic.updateSubstitutionFilter(componentId.toLowerCase(),
- Collections.singletonList(constraint), true, ComponentTypeEnum.SERVICE))
+ List.of(filterConstraintDto), true, ComponentTypeEnum.SERVICE))
.thenReturn(Optional.ofNullable(substitutionFilterDataDefinition));
final Response response = target()
@@ -266,7 +259,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
}
@Test
- public void updateSubstitutionFilterFailConstraintParseTest() {
+ void updateSubstitutionFilterFailConstraintParseTest() {
final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
final String path = String.format(pathFormat, componentType, componentId, constraintType);
@@ -287,7 +280,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
}
@Test
- public void updateSubstitutionFilterFailTest() {
+ void updateSubstitutionFilterFailTest() {
final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
final String path = String.format(pathFormat, componentType, componentId, constraintType);
@@ -308,7 +301,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
}
@Test
- public void deleteSubstitutionFilterConstraintTest() throws BusinessLogicException {
+ void deleteSubstitutionFilterConstraintTest() throws BusinessLogicException {
final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s/0";
final String path = String.format(pathFormat, componentType, componentId, constraintType);
@@ -334,7 +327,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
}
@Test
- public void deleteSubstitutionFilterConstraintFailTest() {
+ void deleteSubstitutionFilterConstraintFailTest() {
final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s/0";
final String path = String.format(pathFormat, componentType, componentId, constraintType);
@@ -390,16 +383,16 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
private void initComponentData() throws JsonProcessingException {
uiConstraint = new UIConstraint(servicePropertyName, constraintOperator, sourceType, sourceName, propertyValue);
- constraint = new ConstraintConvertor().convert(uiConstraint);
+ final FilterConstraintMapper filterConstraintMapper = new FilterConstraintMapper();
+ filterConstraintDto = filterConstraintMapper.mapFrom(uiConstraint);
inputJson = buildConstraintDataJson(uiConstraint);
- requirementSubstitutionFilterPropertyDataDefinition = new RequirementSubstitutionFilterPropertyDataDefinition();
- requirementSubstitutionFilterPropertyDataDefinition.setName(uiConstraint.getServicePropertyName());
- requirementSubstitutionFilterPropertyDataDefinition.setConstraints(new LinkedList<>(Arrays.asList(constraint)));
+ SubstitutionFilterPropertyDataDefinition substitutionFilterPropertyDataDefinition = new SubstitutionFilterPropertyDataDefinition();
+ substitutionFilterPropertyDataDefinition.setName(uiConstraint.getServicePropertyName());
+ substitutionFilterPropertyDataDefinition.setConstraints(List.of(filterConstraintMapper.mapTo(filterConstraintDto)));
- final ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> listDataDefinition =
- new ListDataDefinition<>(
- new LinkedList<>(Arrays.asList(requirementSubstitutionFilterPropertyDataDefinition)));
+ final ListDataDefinition<SubstitutionFilterPropertyDataDefinition> listDataDefinition =
+ new ListDataDefinition<>(List.of(substitutionFilterPropertyDataDefinition));
substitutionFilterDataDefinition = new SubstitutionFilterDataDefinition();
substitutionFilterDataDefinition.setProperties(listDataDefinition);
diff --git a/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml
index 293bd49632..81e302f8bd 100644
--- a/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml
+++ b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml
@@ -111,6 +111,12 @@ errors:
message: "Error: Invalid userId '%1'.",
messageId: "SVC4008"
}
+ #---------SVC4009-----------------------------
+ USER_DEFINED: {
+ code: 400,
+ message: "Error: User Defined '%1'.",
+ messageId: "SVC4009"
+ }
#---------SVC4049------------------------------
# %1 - service/resource
COMPONENT_MISSING_CONTACT: {
@@ -1430,10 +1436,10 @@ errors:
message: "Error: artifact %1 is defined in CSAR %2 manifest but is not provided",
messageId: "SVC4618"
}
-#---------SVC4619------------------------------
-# %1 - artifact name
-# %2 - artifact type
-# %3 - existing artifact type
+ #---------SVC4619------------------------------
+ # %1 - artifact name
+ # %2 - artifact type
+ # %3 - existing artifact type
ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR: {
code: 400,
message: "Error: artifact %1 in type %2 already exists in type %3.",
@@ -1797,9 +1803,11 @@ errors:
messageId: "SVC4669"
}
#---------SVC4670------------------------------
+ # %1 - artifactname
+ # %2 - validname
ARTIFACT_NAME_INVALID: {
code: 400,
- message: "Error: Artifact name is invalid.",
+ message: "Error: Artifact name '%1' is invalid. Only the following characters are allowed in the Artifact Name: '%2'.",
messageId: "SVC4670"
}
#---------SVC4671------------------------------
@@ -1909,6 +1917,22 @@ errors:
message: "Error: Invalid policy name %1 received.",
messageId: "SVC4684"
}
+ #---------SVC4801------------------------------
+ # %1 - policy type
+ POLICY_TYPE_IS_INVALID: {
+ code: 400,
+ message: "Error: Invalid content. Policy type %1 does not exist",
+ messageId: "SVC4801"
+ }
+
+ #---------SVC4802------------------------------
+ # %1 - policy name
+ POLICY_MISSING_POLICY_TYPE: {
+ code: 400,
+ message: "Error: Invalid content. Type name is not defined for policy %1",
+ messageId: "SVC4802"
+ }
+
#---------SVC4685------------------------------
# %1 - policy name
POLICY_NAME_ALREADY_EXIST: {
@@ -1988,7 +2012,7 @@ errors:
#---------SVC4695-----------------------------
# %1 - Interface Operation Name
INTERFACE_OPERATION_NAME_ALREADY_IN_USE: {
- code: 400,
+ code: 409,
message: "Error: Interface Operation name '%1' already in use, Your current changes will not be saved.",
messageId: "SVC4695"
}
@@ -1996,20 +2020,20 @@ errors:
# %1 - Interface Operation Name
INTERFACE_OPERATION_NAME_INVALID: {
code: 400,
- message: "Error: Interface Operation name '%1' is Invalid, Operation name should not contain special character, space, numbers and should not be greater than 200 characters.",
+ message: "Error: Interface Operation name '%1' is Invalid, Operation name should not contain special character, space and should not be greater than 200 characters.",
messageId: "SVC4696"
}
#---------SVC4697-----------------------------
INTERFACE_OPERATION_NAME_MANDATORY: {
- code: 404,
+ code: 400,
message: "Error: Interface Operation name is mandatory, Operation name can't be empty.",
messageId: "SVC4697"
}
#---------SVC4698-----------------------------
- # %1 - Interface Operation description
- INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH: {
+ # %1 - Interface type
+ INTERFACE_OPERATION_INVALID_FOR_LOCAL_TYPE: {
code: 400,
- message: "Error: Interface Operation description '%1' is invalid, maximum 200 characters allowed.",
+ message: "Error: Invalid input, only one operation is allowed in local interface type '%1'.",
messageId: "SVC4698"
}
#---------SVC4699-----------------------------
@@ -2021,20 +2045,20 @@ errors:
}
#---------SVC4700-----------------------------
INTERFACE_OPERATION_INPUT_NAME_MANDATORY: {
- code: 404,
+ code: 400,
message: "Error: Interface operation input parameter name should not be empty.",
messageId: "SVC4700"
}
#---------SVC4701-----------------------------
- # %1 - resource Id
+ # %1 - component Id
INTERFACE_OPERATION_NOT_FOUND: {
code: 404,
- message: "Error: Interface operation not found in the resource '%1'.",
+ message: "Error: Interface operation not found in the component '%1'.",
messageId: "SVC4701"
}
#---------SVC4702-----------------------------
INTERFACE_OPERATION_NOT_DELETED: {
- code: 404,
+ code: 400,
message: "Error: Failed to delete interface operation.",
messageId: "SVC4702"
}
@@ -2107,25 +2131,32 @@ errors:
message: "Error: CSAR packaging failed for %1 %2.",
messageId: "SVC4706"
}
- #---------SVC4704-----------------------------
- # %1 - Interface Operation input property name
+ #---------SVC4708-----------------------------
+ # %1 - Interface Operation input property name, component type
INTERFACE_OPERATION_INPUT_PROPERTY_NOT_FOUND_IN_COMPONENT: {
code: 404,
- message: "Error: Interface operation input parameter property '%1' not found in component input properties.",
- messageId: "SVC4704"
+ message: "Error: Interface operation input parameter property '%1' not found in '%2' input properties, capability properties or outputs of other operations.",
+ messageId: "SVC4708"
}
- #---------SVC4705-----------------------------
+ #---------SVC4709-----------------------------
# %1 - Interface Operation output parameter name
INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE: {
code: 400,
message: "Error: Interface Operation output parameter name '%1' already in use, Your current changes will not be saved.",
- messageId: "SVC4705"
+ messageId: "SVC4708"
}
- #---------SVC4706-----------------------------
+ #---------SVC4710-----------------------------
INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY: {
- code: 404,
+ code: 400,
message: "Error: Interface operation output parameter name should not be empty.",
- messageId: "SVC4706"
+ messageId: "SVC4710"
+ }
+ #---------SVC4711-----------------------------
+ # %1 - interface Id
+ INTERFACE_NOT_FOUND_IN_COMPONENT: {
+ code: 404,
+ message: "Error: Interface not found in the component '%1'.",
+ messageId: "SVC4711"
}
#---------SVC4709-----------------------------
INVALID_PROPERTY_CONSTRAINTS: {
@@ -2237,34 +2268,177 @@ errors:
message: "Error: Missing value for the mandatory %1 property" ,
messageId: "SVC4721"
}
+ #---------SVC4712-----------------------------
+ INTERFACE_LIFECYCLE_TYPES_NOT_FOUND: {
+ code: 404,
+ message: "Error: Interface Lifecycle types not found.",
+ messageId: "SVC4712"
+ }
+ #---------SVC4713-----------------------------
+ # %1 - Interface Operation Name
+ INTERFACE_OPERATION_INVALID_FOR_GLOBAL_TYPE: {
+ code: 400,
+ message: "Error: Invalid input, only pre-defined operation names are allowed in global interface type '%1'",
+ messageId: "SVC4713"
+ }
+
+ #---------SVC4714-----------------------------
+ NODE_FILTER_NOT_FOUND: {
+ code: 400,
+ message: "Error: Node Filter was not found",
+ messageId: "SVC4714"
+ }
+ #---------SVC4715----------------------------
+ UNSUPPORTED_VALUE_PROVIDED: {
+ code: 400,
+ message: "Error: Supported value type is %1 for %2 property. Provided Value: %3",
+ messageId: "SVC4715"
+ }
+ #---------SVC4716----------------------------
+ # %1 - Property Name
+ SELECTED_PROPERTY_NOT_PRESENT: {
+ code: 400,
+ message: "Error: %1 property does not exists in Service anymore.",
+ messageId: "SVC4716"
+ }
+
+ #---------SVC4184----------------------------
+ # %1 - Source type
+ # %2 - Property Type
+ # %3 - Property Name
+ FILTER_PROPERTY_NOT_FOUND:
+ code: 400
+ message: "%1 %2 %3 does not exist."
+ messageId: "SVC4184"
+
+ #---------SVC4718----------------------------
+ # %1 - Property Name
+ # %2 - Operator Name
+ UNSUPPORTED_OPERATOR_PROVIDED: {
+ code: 400,
+ message: "Error: %1 property does not support %2 operator.",
+ messageId: "SVC4718"
+ }
+
+ #---------SVC4719----------------------------
+ CONSTRAINT_FORMAT_INCORRECT: {
+ code: 400,
+ message: "Error: Constraint provided does not contains expected values.",
+ messageId: "SVC4719"
+ }
+
+ #---------SVC4182----------------------------
+ # %1 - Property Name
+ # %2 - Operator Type
+ SOURCE_TARGET_PROPERTY_TYPE_MISMATCH: {
+ code: 400,
+ message: "Error: Property '%1' type '%2' does not match with property '%3' type '%4'.",
+ messageId: "SVC4182"
+ }
+
+ #---------SVC4721----------------------------
+ # %1 - Property Type
+ # %2 - Operator Type
+ UNSUPPORTED_PROPERTY_TYPE: {
+ code: 400,
+ message: "Error: Property type %1 provided against %2 is not supported for static value.",
+ messageId: "SVC4721"
+ }
+
#---------SVC4722------------------------------
+ # %1 Directive value set
+ DIRECTIVES_INVALID_VALUE: {
+ code: 404,
+ message: "Error: Invalid directive value : '%1' .",
+ messageId: "SVC4722"
+ }
+ #---------SVC4723-----------------------------
+ # %1 - Interface Operation output name
+ INTERFACE_OPERATION_MAPPED_OUTPUT_MODIFIED: {
+ code: 400,
+ message: "Error: Cannot update or delete interface operation output(s) '%1' mapped to an operation input",
+ messageId: "SVC4723"
+ }
+ #---------SVC4724-----------------------------
+ # %1 - Interface Operation output name
+ INTERFACE_OPERATION_DELETE_WITH_MAPPED_OUTPUT: {
+ code: 400,
+ message: "Error: Cannot delete interface operation with output(s) '%1' mapped to another operation input",
+ messageId: "SVC4724"
+ }
+ #---------SVC4725-----------------------------
+ INVALID_CONSUMPTION_TYPE: {
+ code: 400,
+ message: "Error: Given value is different than input type. Needs to be %1",
+ messageId: "SVC4725"
+ }
+ #---------SVC4726-----------------------------
+ INVALID_PROPERTY_VALUES: {
+ code: 400,
+ message: "Error: Invalid property values provided:\n %1",
+ messageId: "SVC4726"
+ }
+ #---------SVC4727------------------------------
+ INVALID_PROPERTY_NAME: {
+ code: 400,
+ message: "Error: Property name contains invalid characters. It should have only letters, numbers and underscores.",
+ messageId: "SVC4727"
+ }
+
+ #---------SVC4728------------------------------
+ FAILED_TO_CREATE_OR_UPDATE_CAPABILITY_PROPERTIES: {
+ code: 500,
+ message: "Error: Failed to create or update capabilities properties",
+ messageId: "SVC4728"
+ }
+
+ #---------SVC4729------------------------------
+ # %1 - resource Id
+ CAPABILITY_PROPERTIES_NOT_FOUND: {
+ code: 400,
+ message: "Error: Capability properties not found in the resource '%1'.",
+ messageId: "SVC4729"
+ }
+ #---------SVC4730------------------------------
# %1 - property name
PROPERTY_EXCEEDS_LIMIT: {
code: 400,
message: "Error: Invalid Content. %1 exceeds limit.",
messageId: "SVC4722"
}
- #---------SVC4723------------------------------
+ #---------SVC4731------------------------------
INVALID_PROPERY: {
# %1 - property name
code: 400,
message: 'Error: Invalid Content. %1 has invalid format.',
messageId: "SVC4723"
}
- #---------SVC4801------------------------------
- # %1 - policy type
- POLICY_TYPE_IS_INVALID: {
+ #---------SVC4734------------------------------
+ # %1 - list of validation errors
+ INVALID_PM_DICTIONARY_FILE: {
code: 400,
- message: "Error: Invalid content. Policy type %1 does not exist",
- messageId: "SVC4801"
+ message: 'Error: Invalid PM Dictionary File. %1',
+ messageId: "SVC4734"
}
-
- #---------SVC4802------------------------------
- # %1 - policy name
- POLICY_MISSING_POLICY_TYPE: {
+ #-----------SVC4735---------------------------
+ #%1 - input name
+ INPUT_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Input with '%1' name already exists.",
+ messageId: "SVC4735"
+ }
+ #---------SVC4736------------------------------
+ INVALID_INPUT_NAME: {
code: 400,
- message: "Error: Invalid content. Type name is not defined for policy %1",
- messageId: "SVC4802"
+ message: "Error: Input name contains invalid characters. It should have only letters, numbers and underscores.",
+ messageId: "SVC4736"
+ }
+ #---------SVC4139------------------------------
+ # %1 - The action that is not supported
+ NOT_SUPPORTED: {
+ code: 400,
+ message: '%1 is not yet supported',
+ messageId: "SVC4139"
}
#---------SVC4140------------------------------
# %1 - Component uid
@@ -2294,31 +2468,172 @@ errors:
message: "An unexpected error occurred while updating the capability '%1'.",
messageId: "SVC4143"
}
+
+ #---------SVC4144------------------------------
+ # %1 - "Model name"
+ MODEL_ALREADY_EXISTS: {
+ code: 409,
+ message: "Error: Model name '%1' already exists.",
+ messageId: "SVC4144"
+ }
+
+ #---------SVC4145------------------------------
+ # %1 - "Model name"
+ INVALID_MODEL: {
+ code: 400,
+ message: "Invalid model '%1'.",
+ messageId: "SVC4145"
+ }
+
+ #---------SVC4146------------------------------
+ MODEL_IMPORTS_IS_EMPTY: {
+ code: 400,
+ message: "Given model imports zip is empty.",
+ messageId: "SVC4146"
+ }
+
+ #---------SVC4147------------------------------
+ COULD_NOT_READ_MODEL_IMPORTS: {
+ code: 400,
+ message: "Could not read imports zip.",
+ messageId: "SVC4147"
+ }
+
+ #---------SVC4148------------------------------
+ # %1 - "Model name"
+ MODEL_NOT_FOUND: {
+ code: 404,
+ message: "Error: Model name '%1' not found. Please, make sure the model is created.",
+ messageId: "SVC4148"
+ }
+
+ #---------SVC4149------------------------------
+ MODEL_NAME_CANNOT_BE_EMPTY: {
+ code: 409,
+ message: "Error: Model name cannot be empty.",
+ messageId: "SVC4149"
+ }
+
+ #-----------SVC4150---------------------------
+ # %1 - "Component name"
+ # %2 - "Model name"
+ COMPONENT_WITH_MODEL_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Component %1 with Model %2 already exist.",
+ messageId: "SVC4150"
+ }
+ #-----------SVC4151---------------------------
+ # %1 - "Component name"
+ # %2 - "Vendor release"
+ # %3 - "Model name"
+ COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS_IN_MODEL: {
+ code: 409,
+ message: "Error: Component '%1' with Vendor Release '%2' already exists in Model '%3'.",
+ messageId: "SVC4151"
+ }
+ #-----------SVC4152---------------------------
+ # %1 - "Component name"
+ # %2 - "Vendor release"
+ COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS: {
+ code: 409,
+ message: "Error: Component '%1' with Vendor Release '%2' already exists.",
+ messageId: "SVC4152"
+ }
+
+ #-----------SVC4153---------------------------
+ # %1 - "Model name"
+ DATA_TYPES_NOT_LOADED: {
+ code: 500,
+ message: "Could not fetch data types from data base with model %1",
+ messageId: "SVC4153"
+ }
+
#-----------SVC4154---------------------------
+ # %1 - "Model name"
+ UNKNOWN_MODEL_TYPE: {
+ code: 400,
+ message: "Error: Model type %1 not known in the system",
+ messageId: "SVC4154"
+ }
+
+ #-----------SVC4154---------------------------
+ CSAR_TOSCA_IMPORTS_ERROR: {
+ code: 500,
+ message: "Error: An error has occurred while including the default TOSCA imports in the CSAR",
+ messageId: "SVC4154"
+ }
+
+ #-----------SVC4155---------------------------
# %1 - "VSP id"
# %2 - "VSP version id"
VSP_FIND_ERROR: {
code: 500,
message: "An error has occurred while retrieving the Vendor Software Product of id '%1', version id '%2'",
- messageId: "SVC4154"
+ messageId: "SVC4155"
}
- #-----------SVC4155---------------------------
+ #-----------SVC4156---------------------------
# %1 - "VSP id"
# %2 - "VSP version id"
VSP_NOT_FOUND: {
code: 404,
message: "Could not find Vendor Software Product of id '%1', version id '%2'",
- messageId: "SVC4155"
+ messageId: "SVC4156"
}
- #-----------SVC4156---------------------------
+ #-----------SVC4157---------------------------
# %1 - "The model name"
# %2 - "List of allowed models"
VSP_MODEL_NOT_ALLOWED: {
code: 400,
message: "The Model '%1' is not allowed for the imported Vendor Software Product. Allowed Models: '%2'",
- messageId: "SVC4156"
+ messageId: "SVC4157"
+ }
+
+ #---------SVC4158-----------------------------
+ # %1 - Valid artifact label name
+ INVALID_ARTIFACT_LABEL_NAME: {
+ code: 400,
+ message: "Invalid label name. Only the following characters are allowed in label name: '%1'",
+ messageId: "SVC4158"
+ }
+
+ #---------SVC4159-----------------------------
+ # %1 - The model name
+ COULD_NOT_DELETE_MODEL: {
+ code: 500,
+ message: "Could not delete the model '%1'.",
+ messageId: "SVC4159"
+ }
+
+ #---------SVC4160-----------------------------
+ # %1 - The model name
+ COULD_NOT_DELETE_MODEL_ELEMENTS: {
+ code: 500,
+ message: "Could not delete the model '%1' elements.",
+ messageId: "SVC4160"
+ }
+ #---------SVC4161-----------------------------
+ INVALID_NODE_TYPES_YAML: {
+ code: 400,
+ message: "Invalid node_types TOSCA yaml",
+ messageId: "SVC4161"
+ }
+
+ #---------SVC4162-----------------------------
+ # %1 - The janusgraph status
+ FAILED_CREATE_ARTIFACTS_TYPES: {
+ code: 500,
+ message: "Failed to create artifact types with status '%1'.",
+ messageId: "SVC4162"
+ }
+
+ #---------SVC4163-----------------------------
+ # %1 - The janusgraph status
+ ARTIFACT_TYPE_ALREADY_EXIST: {
+ code: 409,
+ message: "Artifact type '%1' already exist.",
+ messageId: "SVC4163"
}
#---------SVC4692-----------------------------
@@ -2336,6 +2651,16 @@ errors:
message: "Component is in use by '%1'",
messageId: "SVC4693"
}
+
+ #---------SVC4164-----------------------------
+ # %1 - componentType
+ # %2 - component name
+ CANNOT_DELETE_SYSTEM_DEPLOYED_RESOURCES: {
+ code: 409,
+ message: "System deployed '%1' cannot be deleted '%2'",
+ messageId: "SVC4164"
+ }
+
#---------SVC4165-----------------------------
# %1 - input origin
TOSCA_GET_FUNCTION_INPUTS_ONLY_SELF_ERROR: {
@@ -2393,6 +2718,14 @@ errors:
messageId: "SVC4170"
}
+ #---------SVC4171-----------------------------
+ # %1 - Instance name
+ TOSCA_GET_FUNCTION_INSTANCE_NOT_FOUND: {
+ code: 404,
+ message: "The instance '%1' was not found.",
+ messageId: "SVC4171"
+ }
+
#-----------SVC4172---------------------------
#%1 - TOSCA function attribute
TOSCA_FUNCTION_MISSING_ATTRIBUTE: {
@@ -2401,3 +2734,82 @@ errors:
messageId: "SVC4172"
}
+ #-----------SVC4173---------------------------
+ RELATIONSHIP_TEMPLATE_NOT_FOUND: {
+ code: 404,
+ message: "Relationship_templates entry not found in TOSCA CSAR.",
+ messageId: "SVC4173"
+ }
+
+ #-----------SVC4174---------------------------
+ RELATIONSHIP_TEMPLATE_DEFINITION_NOT_FOUND: {
+ code: 404,
+ message: "Relationship_templates definition not found in TOSCA CSAR.",
+ messageId: "SVC4174"
+ }
+
+ #-----------SVC4175---------------------------
+ TOSCA_FUNCTION_EXPECTED_ERROR: {
+ code: 400,
+ message: "Expecting a Tosca Function value.",
+ messageId: "SVC4175"
+ }
+
+ #-----------SVC4176---------------------------
+ FILTER_CONSTRAINT_MISSING: {
+ code: 400,
+ message: "The filter constraint was not provided.",
+ messageId: "SVC4176"
+ }
+
+ #-----------SVC4177---------------------------
+ #%1 - The missing field
+ FILTER_CONSTRAINT_MISSING_FIELD: {
+ code: 400,
+ message: "Required field '%1' is missing in the filter constraint.",
+ messageId: "SVC4177"
+ }
+
+ #%1 - the component id
+ SUBSTITUTION_FILTER_NOT_FOUND: {
+ code: 404,
+ message: 'Substitution filter not found in the component "%1"',
+ messageId: "SVC4178"
+ }
+
+ # %1 - Component name
+ COMPONENT_DOES_NOT_HAVE_INPUTS: {
+ code: 400,
+ message: "Component '%1' does not have inputs.",
+ messageId: "SVC4179"
+ }
+
+ # %1 - Input name
+ # %2 - Component name
+ COMPONENT_INPUT_NOT_FOUND: {
+ code: 400,
+ message: "Input '%1' does not exist in '%2'.",
+ messageId: "SVC4180"
+ }
+
+ # %1 - Target property name
+ # %2 - Source property name
+ SOURCE_TARGET_SCHEMA_MISMATCH: {
+ code: 400,
+ message: "Target property '%1' schema '%2' does not match with source property '%3' schema '%4'.",
+ messageId: "SVC4181"
+ }
+
+ # %1 - Property name
+ # %2 - Component name
+ COMPONENT_PROPERTY_NOT_FOUND:
+ code: 400
+ message: "Property '%1' does not exist in '%2'."
+ messageId: "SVC4183"
+
+ # %1 - The component type
+ # %2 - The expected component types
+ INVALID_COMPONENT_TYPE:
+ code: 400
+ message: "Invalid component type '%1'. Expected types are: %2"
+ messageId: "SVC4185"