diff options
author | 2022-09-08 18:55:08 +0100 | |
---|---|---|
committer | 2022-09-19 08:38:43 +0000 | |
commit | 0d38a72c022fa93dba0bf052f893e51fb73d3552 (patch) | |
tree | 25f49242e6c6666c39e32abae66e4950fe4e18ed /catalog-model/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-model/src/main/java')
-rw-r--r-- | catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java index 3dc2a73466..f1de061c9f 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java @@ -84,13 +84,9 @@ public class NodeFilterOperation extends BaseOperation { final int propertyIndex, final NodeFilterConstraintType nodeFilterConstraintType) { if (NodeFilterConstraintType.PROPERTIES.equals(nodeFilterConstraintType)) { - final ListDataDefinition<PropertyFilterDataDefinition> properties = nodeFilterDataDefinition.getProperties(); - properties.getListToscaDataDefinition().remove(propertyIndex); - nodeFilterDataDefinition.setProperties(properties); + nodeFilterDataDefinition.getProperties().getListToscaDataDefinition().remove(propertyIndex); } else if (NodeFilterConstraintType.CAPABILITIES.equals(nodeFilterConstraintType)) { - final ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> capabilities = nodeFilterDataDefinition.getCapabilities(); - capabilities.getListToscaDataDefinition().remove(propertyIndex); - nodeFilterDataDefinition.setCapabilities(capabilities); + removeCapabilityNodeFilterByIndex(nodeFilterDataDefinition, propertyIndex); } return addOrUpdateNodeFilter(true, serviceId, componentInstanceId, nodeFilterDataDefinition); } @@ -116,11 +112,11 @@ public class NodeFilterOperation extends BaseOperation { capabilities = new ListDataDefinition<>(); nodeFilterDataDefinition.setCapabilities(capabilities); } - + final Optional<RequirementNodeFilterCapabilityDataDefinition> existingCap = capabilities .getListToscaDataDefinition().stream() .filter(def -> def.getName().equals(requirementNodeFilterCapabilityDataDefinition.getName())).findAny(); - + if (existingCap.isPresent()) { final ListDataDefinition<PropertyFilterDataDefinition> newProperties = requirementNodeFilterCapabilityDataDefinition.getProperties(); final ListDataDefinition<PropertyFilterDataDefinition> existingProperties = existingCap.get().getProperties(); @@ -144,6 +140,29 @@ public class NodeFilterOperation extends BaseOperation { return addOrUpdateNodeFilter(false, componentId, componentInstanceId, nodeFilterDataDefinition); } + private void removeCapabilityNodeFilterByIndex(final CINodeFilterDataDefinition nodeFilterDataDefinition, final int filterToRemoveIndex) { + int currentFilterCountdown = filterToRemoveIndex; + final List<RequirementNodeFilterCapabilityDataDefinition> filtersByCapability = + nodeFilterDataDefinition.getCapabilities().getListToscaDataDefinition(); + for (final RequirementNodeFilterCapabilityDataDefinition capabilityFilterGroup : filtersByCapability) { + final List<PropertyFilterDataDefinition> capabilityFilters = capabilityFilterGroup.getProperties().getListToscaDataDefinition(); + if (isFilterInCapabilityGroup(currentFilterCountdown, capabilityFilters)) { + capabilityFilters.remove(currentFilterCountdown); + break; + } else { + currentFilterCountdown = getRemainingFilterCount(currentFilterCountdown, capabilityFilters); + } + } + } + + private boolean isFilterInCapabilityGroup(int currentFilterCount, List<PropertyFilterDataDefinition> capabilityFilters) { + return capabilityFilters.size() > currentFilterCount; + } + + private int getRemainingFilterCount(int currentFilterCount, final List<PropertyFilterDataDefinition> capabilityFilters) { + return currentFilterCount - capabilityFilters.size(); + } + private Either<CINodeFilterDataDefinition, StorageOperationStatus> addOrUpdateNodeFilter(final boolean isUpdateAction, final String componentId, final String componentInstanceId, final CINodeFilterDataDefinition ciNodeFilterDataDefinition) { |