aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2022-03-10 12:19:18 +0000
committerAndr� Schmid <andre.schmid@est.tech>2022-03-14 15:23:07 +0000
commit302c525546650b71ad699903d98090f8cb23f068 (patch)
tree0284bef058f201425d98cdd8987e38a9269f5ce9 /catalog-be/src/main
parent5816f717507a2edc5fdc17cfee579358f2949961 (diff)
Fix cannot set node filter cap using get_property
Change-Id: I92fd4016b19e03e22622cf6e476f17b49e3d6a47 Issue-ID: SDC-3904 Signed-off-by: MichaelMorris <michael.morris@est.tech>
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java15
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java32
2 files changed, 35 insertions, 12 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 729538c640..c1669d18f6 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
@@ -164,7 +164,7 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
throws BusinessLogicException {
final Component component = getComponent(componentId);
CINodeFilterDataDefinition nodeFilterDataDefinition = validateAndReturnNodeFilterDefinition(componentInstanceId, action, constraint,
- component, nodeFilterConstraintType);
+ component, nodeFilterConstraintType, capabilityName);
boolean wasLocked = false;
try {
if (shouldLock) {
@@ -204,7 +204,7 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
throws BusinessLogicException {
final Component component = getComponent(componentId);
CINodeFilterDataDefinition nodeFilterDataDefinition = validateAndReturnNodeFilterDefinition(componentInstanceId, action, constraint,
- component, nodeFilterConstraintType);
+ component, nodeFilterConstraintType, "");
boolean wasLocked = false;
try {
if (shouldLock) {
@@ -291,9 +291,10 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
private CINodeFilterDataDefinition validateAndReturnNodeFilterDefinition(final String componentInstanceId,
final NodeFilterConstraintAction action, final String constraint,
final Component component,
- final NodeFilterConstraintType nodeFilterConstraintType)
+ final NodeFilterConstraintType nodeFilterConstraintType,
+ final String capabilityName)
throws BusinessLogicException {
- validateNodeFilter(component, componentInstanceId, action, constraint, nodeFilterConstraintType);
+ 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));
@@ -302,9 +303,9 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
}
private void validateNodeFilter(final Component component, final String componentInstanceId, final NodeFilterConstraintAction action,
- final String constraint, final NodeFilterConstraintType nodeFilterConstraintType) throws BusinessLogicException {
+ 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);
+ .validateFilter(component, componentInstanceId, Collections.singletonList(constraint), action, nodeFilterConstraintType, capabilityName);
if (response.isRight()) {
throw new BusinessLogicException(
componentsUtils.getResponseFormat(ActionStatus.NODE_FILTER_NOT_FOUND, response.right().value().getFormattedMessage()));
@@ -323,7 +324,7 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
}
return addNodeFilter(componentId.toLowerCase(), componentInstanceId, NodeFilterConstraintAction.ADD, uiConstraint.getServicePropertyName(),
new ConstraintConvertor().convert(uiConstraint), true, componentTypeEnum, nodeFilterConstraintType,
- StringUtils.isEmpty(uiConstraint.getCapabilityName()) ? "" : uiConstraint.getCapabilityName());
+ uiConstraint.getCapabilityName());
}
public StorageOperationStatus associateNodeFilterToComponentInstance(final String componentId,
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 db5de58129..c1eaf60ad0 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
@@ -90,14 +90,15 @@ public class NodeFilterValidator {
public Either<Boolean, ResponseFormat> validateFilter(final Component parentComponent, final String componentInstanceId,
final List<String> uiConstraints, final NodeFilterConstraintAction action,
- final NodeFilterConstraintType nodeFilterConstraintType) {
+ 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);
+ componentInstanceId, constraint, capabilityName);
if (booleanResponseFormatEither.isRight()) {
return booleanResponseFormatEither;
}
@@ -141,7 +142,7 @@ public class NodeFilterValidator {
}
private Either<Boolean, ResponseFormat> validatePropertyConstraint(final Component parentComponent, final String componentInstanceId,
- final UIConstraint uiConstraint) {
+ final UIConstraint uiConstraint, final String capabilityName) {
String source = SOURCE;
final Optional<ComponentInstance> optionalComponentInstance;
final List<PropertyDefinition> propertyDefinitions = parentComponent.getProperties();
@@ -161,8 +162,8 @@ public class NodeFilterValidator {
if (CollectionUtils.isNotEmpty(sourcePropertyDefinition)) {
final Optional<? extends PropertyDefinition> sourceSelectedProperty = sourcePropertyDefinition.stream()
.filter(property -> uiConstraint.getValue().equals(property.getName())).findFirst();
- final Optional<? extends PropertyDefinition> targetComponentInstanceProperty = parentComponent.getComponentInstancesProperties()
- .get(componentInstanceId).stream().filter(property -> uiConstraint.getServicePropertyName().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);
@@ -171,6 +172,27 @@ public class NodeFilterValidator {
final String missingProperty = source.equals(SOURCE) ? uiConstraint.getValue().toString() : uiConstraint.getServicePropertyName();
return Either.right(componentsUtils.getResponseFormat(ActionStatus.MAPPED_PROPERTY_NOT_FOUND, source, missingProperty));
}
+
+ private Optional<ComponentInstanceProperty> getProperty(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();
+ } else {
+ final Optional<ComponentInstance> componentInstanceOptional = parentComponent.getComponentInstances().stream()
+ .filter(componentInstance -> componentInstance.getUniqueId().equals(componentInstanceId)).findAny();
+ if (componentInstanceOptional.isPresent()) {
+ for (final List<CapabilityDefinition> listOfCaps : componentInstanceOptional.get().getCapabilities().values()) {
+ final Optional<CapabilityDefinition> capDef = listOfCaps.stream().filter(cap -> cap.getName().equals(capabilityName)).findAny();
+ if (capDef.isPresent()) {
+ return capDef.get().getProperties().stream().filter(property -> propertyName.equals(property.getName())).findFirst();
+ }
+ }
+ }
+ }
+ return Optional.empty();
+ }
private Either<Boolean, ResponseFormat> validateInputConstraint(final Component parentComponent, final String componentInstanceId,
final UIConstraint uiConstraint) {