diff options
author | andre.schmid <andre.schmid@est.tech> | 2022-09-08 18:55:08 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2022-09-19 08:38:43 +0000 |
commit | 0d38a72c022fa93dba0bf052f893e51fb73d3552 (patch) | |
tree | 25f49242e6c6666c39e32abae66e4950fe4e18ed /catalog-be/src/main/java | |
parent | 2fe3d879319a34e9802d0bc172fa11fefe771df3 (diff) |
Support TOSCA functions in Node Capability Filters
Adds support to use TOSCA functions as value in the node capability
filters.
Removes the current capability filter component to reuse, with a few
changes, the node property filters component.
Fixes problems with the edition and deletion of node capability
filters.
Change-Id: Ic91242d6cbc24e2ce0f60b84c63e104575bef8a9
Issue-ID: SDC-4173
Signed-off-by: André Schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be/src/main/java')
5 files changed, 42 insertions, 26 deletions
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 ff65d84416..457f43865f 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 @@ -52,7 +52,6 @@ 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; import org.openecomp.sdc.exception.ResponseFormat; @@ -156,8 +155,7 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic { public Optional<CINodeFilterDataDefinition> addNodeFilter(final String componentId, final String componentInstanceId, final FilterConstraintDto filterConstraint, final boolean shouldLock, final ComponentTypeEnum componentTypeEnum, - final NodeFilterConstraintType nodeFilterConstraintType, - final String capabilityName) throws BusinessLogicException { + final NodeFilterConstraintType nodeFilterConstraintType) throws BusinessLogicException { final Component component = getComponent(componentId); validateNodeFilter(component, componentInstanceId, filterConstraint); CINodeFilterDataDefinition nodeFilterDataDefinition = getComponentInstanceNodeFilterOrThrow(componentInstanceId, component); @@ -171,7 +169,7 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic { filterPropertyDataDefinition.setName(filterConstraint.getPropertyName()); filterPropertyDataDefinition.setConstraints(List.of(new FilterConstraintMapper().mapTo(filterConstraint))); final Either<CINodeFilterDataDefinition, StorageOperationStatus> result = addNodeFilter(componentId, componentInstanceId, - nodeFilterConstraintType, nodeFilterDataDefinition, filterPropertyDataDefinition, capabilityName); + nodeFilterConstraintType, nodeFilterDataDefinition, filterPropertyDataDefinition, filterConstraint.getCapabilityName()); if (result.isRight()) { throw new BusinessLogicException(componentsUtils.getResponseFormatByResource( componentsUtils.convertFromStorageResponse(result.right().value()), component.getSystemName() @@ -290,7 +288,7 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic { } public Optional<CINodeFilterDataDefinition> updateNodeFilter(final String componentId, final String componentInstanceId, - final UIConstraint uiConstraint, final ComponentTypeEnum componentTypeEnum, + final FilterConstraintDto filterConstraintDto, final ComponentTypeEnum componentTypeEnum, final NodeFilterConstraintType nodeFilterConstraintType, final int index) throws BusinessLogicException { final Optional<CINodeFilterDataDefinition> deleteActionResponse = @@ -299,8 +297,8 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic { throw new BusinessLogicException( componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR, "Failed to delete node filter capabilities")); } - return addNodeFilter(componentId.toLowerCase(), componentInstanceId, new FilterConstraintMapper().mapFrom(uiConstraint), true, - componentTypeEnum, nodeFilterConstraintType, uiConstraint.getCapabilityName()); + return addNodeFilter(componentId.toLowerCase(), componentInstanceId, filterConstraintDto, true, + componentTypeEnum, nodeFilterConstraintType); } public StorageOperationStatus associateNodeFilterToComponentInstance(final String componentId, 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 f34091de0f..9cdf07c15f 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 @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import org.onap.sdc.tosca.services.YamlUtil; import org.openecomp.sdc.be.model.UploadNodeFilterCapabilitiesInfo; import org.openecomp.sdc.be.model.UploadNodeFilterInfo; @@ -59,16 +58,13 @@ public class NodeFilterUploadCreator { final Map.Entry<String, Object> entry = map.entrySet().iterator().next(); 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)); + retVal.add(new UploadNodeFilterPropertyInfo(entry.getKey(), List.of(valueToProperty(map)))); } else if (propertyConstraintClauses instanceof List) { - final List<String> propertyFilterConstraintList = ((List<Object>) propertyConstraintClauses).stream() + ((List<Object>) propertyConstraintClauses).stream() .map(propertyConstraintClause -> Map.of(entry.getKey(), propertyConstraintClause)) .map(this::valueToProperty) - .collect(Collectors.toList()); - - retVal.add(new UploadNodeFilterPropertyInfo(entry.getKey(), propertyFilterConstraintList)); + .map(filterConstraint -> new UploadNodeFilterPropertyInfo(entry.getKey(), List.of(filterConstraint))) + .forEach(retVal::add); } } return retVal; 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 5ac9bcd2de..6f0472df61 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 @@ -60,15 +60,16 @@ public class CINodeFilterUtils { private RequirementNodeFilterCapabilityDataDefinition convertCapability(UploadNodeFilterCapabilitiesInfo capability) { RequirementNodeFilterCapabilityDataDefinition retVal = new RequirementNodeFilterCapabilityDataDefinition(); retVal.setName(capability.getName()); - List<PropertyFilterDataDefinition> props = capability.getProperties().stream().map(this::buildProperty) + List<PropertyFilterDataDefinition> propertyFilterList = capability.getProperties().stream() + .map(filterPropertyInfo -> buildProperty(capability.getName(), filterPropertyInfo)) .collect(Collectors.toList()); ListDataDefinition<PropertyFilterDataDefinition> propsList = new ListDataDefinition<>(); - propsList.getListToscaDataDefinition().addAll(props); + propsList.getListToscaDataDefinition().addAll(propertyFilterList); retVal.setProperties(propsList); return retVal; } - private PropertyFilterDataDefinition buildProperty(final UploadNodeFilterPropertyInfo uploadNodeFilterPropertyInfo) { + private PropertyFilterDataDefinition buildProperty(final String capabilityName, final UploadNodeFilterPropertyInfo uploadNodeFilterPropertyInfo) { final var propertyFilter = new PropertyFilterDataDefinition(); propertyFilter.setName(uploadNodeFilterPropertyInfo.getName()); final List<String> propertyConstraints = uploadNodeFilterPropertyInfo.getValues(); @@ -76,6 +77,7 @@ public class CINodeFilterUtils { propertyFilter.setConstraints( propertyConstraints.stream() .map(PropertyFilterConstraintDataDefinitionHelper::convertLegacyConstraint) + .peek(propertyFilterConstraintDataDefinition -> propertyFilterConstraintDataDefinition.setCapabilityName(capabilityName)) .collect(Collectors.toList()) ); } 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 12b58ded4a..b7b2452189 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 @@ -21,6 +21,7 @@ package org.openecomp.sdc.be.components.validation; import com.google.gson.Gson; import fj.data.Either; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Optional; @@ -31,6 +32,7 @@ import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition; +import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType; import org.openecomp.sdc.be.datatypes.enums.PropertySource; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.CapabilityDefinition; @@ -290,11 +292,31 @@ public class NodeFilterValidator { findSubProperty(propertyPathFromSource.subList(1, propertyPathFromSource.size()), sourceSelectedProperty.get().getType(), allDataTypesEither.left().value()); } - final Optional<? extends PropertyDefinition> targetComponentInstanceProperty = - parentComponent.getComponentInstancesProperties() - .get(componentInstanceId).stream() + final Optional<? extends PropertyDefinition> targetComponentInstanceProperty; + if (PropertyFilterTargetType.CAPABILITY.equals(filterConstraint.getTargetType())) { + final CapabilityDefinition capability = parentComponent.getComponentInstances().stream() + .filter(componentInstance -> componentInstance.getUniqueId().equals(componentInstanceId)) + .map(componentInstance -> componentInstance.getCapabilities().values()) + .flatMap(Collection::stream) + .flatMap(Collection::stream) + .filter(capabilityDefinition -> capabilityDefinition.getName().equals(filterConstraint.getCapabilityName())) + .findFirst().orElse(null); + if (capability == null) { + return Either.right( + componentsUtils.getResponseFormat(ActionStatus.CAPABILITY_NOT_FOUND_IN_COMPONENT, + filterConstraint.getCapabilityName(), parentComponent.getComponentType().getValue(), parentComponent.getName()) + ); + } + targetComponentInstanceProperty = capability.getProperties().stream() .filter(property -> filterConstraint.getPropertyName().equals(property.getName())) .findFirst(); + } else { + 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) { 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 80c806f9c3..d69a7d367c 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 @@ -42,7 +42,6 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.ComponentNodeFilterBusinessLogic; import org.openecomp.sdc.be.components.impl.ResourceImportManager; @@ -140,8 +139,7 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet { final FilterConstraintDto filterConstraintDto = new FilterConstraintMapper().mapFrom(uiConstraint); final Optional<CINodeFilterDataDefinition> actionResponse = componentNodeFilterBusinessLogic .addNodeFilter(componentId.toLowerCase(), componentInstanceId, - filterConstraintDto, true, componentTypeEnum, nodeFilterConstraintType.get(), - StringUtils.isEmpty(uiConstraint.getCapabilityName()) ? "" : uiConstraint.getCapabilityName()); + filterConstraintDto, true, componentTypeEnum, nodeFilterConstraintType.get()); if (actionResponse.isEmpty()) { LOGGER.error(FAILED_TO_CREATE_NODE_FILTER); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); @@ -201,8 +199,8 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet { } final NodeFilterConstraintType nodeFilterConstraintType = nodeFilterConstraintTypeOptional.get(); final Optional<CINodeFilterDataDefinition> actionResponse = componentNodeFilterBusinessLogic - .updateNodeFilter(componentId.toLowerCase(), componentInstanceId, uiConstraint, componentTypeEnum, nodeFilterConstraintType, - index); + .updateNodeFilter(componentId.toLowerCase(), componentInstanceId, new FilterConstraintMapper().mapFrom(uiConstraint), + componentTypeEnum, nodeFilterConstraintType, index); if (actionResponse.isEmpty()) { LOGGER.error(FAILED_TO_UPDATE_NODE_FILTER); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); |