aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2020-08-28 11:50:52 +0100
committerSébastien Determe <sebastien.determe@intl.att.com>2020-09-07 07:11:49 +0000
commit798f858d18403a31a4d464b07bb1a9a74666c9c7 (patch)
tree9b5e2a6e59dbb803fb0bdcafd3fff6ae08c412f2
parentc572ed8873bee57ad925fb231464efbca98a8007 (diff)
Update node_filter capabilities
Issue-ID: SDC-3265 Signed-off-by: aribeiro <anderson.ribeiro@est.tech> Change-Id: Ib2dbd299ff5fc336258bf29a303210eacfd984cf
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java50
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServlet.java8
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java6
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java9
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java20
5 files changed, 74 insertions, 19 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 962407ca92..1b9054e187 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
@@ -31,6 +31,7 @@ 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.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.RequirementNodeFilterCapabilityDataDefinition;
@@ -269,7 +270,8 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
final String componentInstanceId,
final List<String> constraints,
final boolean shouldLock,
- final ComponentTypeEnum componentTypeEnum)
+ final ComponentTypeEnum componentTypeEnum,
+ final NodeFilterConstraintType nodeFilterConstraintType)
throws BusinessLogicException {
final Component component = getComponent(componentId);
@@ -296,10 +298,9 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
lockComponent(component.getUniqueId(), component,"Update Node Filter on Component");
wasLocked = true;
}
- final List<RequirementNodeFilterPropertyDataDefinition> properties = constraints.stream()
- .map(this::getRequirementNodeFilterPropertyDataDefinition).collect(Collectors.toList());
- final Either<CINodeFilterDataDefinition, StorageOperationStatus> result = nodeFilterOperation
- .updateProperties(componentId, componentInstanceId, nodeFilterDataDefinition, properties);
+ final Either<CINodeFilterDataDefinition, StorageOperationStatus> result =
+ updateNodeFilterConstraint(componentId, componentInstanceId, constraints, nodeFilterConstraintType,
+ nodeFilterDataDefinition);
if (result.isRight()) {
janusGraphDao.rollback();
@@ -326,6 +327,22 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
return Optional.ofNullable(nodeFilterDataDefinition);
}
+ private Either<CINodeFilterDataDefinition, StorageOperationStatus> updateNodeFilterConstraint(
+ final String componentId, final String componentInstanceId, final List<String> constraints,
+ final NodeFilterConstraintType nodeFilterConstraintType, final CINodeFilterDataDefinition nodeFilterDataDefinition) {
+
+ if (NodeFilterConstraintType.PROPERTIES.equals(nodeFilterConstraintType)) {
+ final List<RequirementNodeFilterPropertyDataDefinition> properties = constraints.stream()
+ .map(this::getRequirementNodeFilterPropertyDataDefinition).collect(Collectors.toList());
+ return nodeFilterOperation.updateProperties(componentId, componentInstanceId,
+ nodeFilterDataDefinition, properties);
+ }
+ final List<RequirementNodeFilterCapabilityDataDefinition> capabilities = constraints.stream()
+ .map(this::getRequirementNodeFilterCapabilityDataDefinition).collect(Collectors.toList());
+ return nodeFilterOperation.updateCapabilities(componentId, componentInstanceId,
+ nodeFilterDataDefinition, capabilities);
+ }
+
private Either<CINodeFilterDataDefinition, StorageOperationStatus> addNewNodeFilter(
final String componentId,
final String componentInstanceId,
@@ -350,6 +367,7 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
requirementNodeFilterCapabilityDataDefinition);
}
+
private void unlockComponent(final String componentUniqueId,
final ComponentTypeEnum componentType) {
graphLockOperation.unlockComponent(componentUniqueId, componentType.getNodeType());
@@ -395,9 +413,25 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
private RequirementNodeFilterPropertyDataDefinition getRequirementNodeFilterPropertyDataDefinition(
final String constraint) {
- final RequirementNodeFilterPropertyDataDefinition pdd = new RequirementNodeFilterPropertyDataDefinition();
- pdd.setConstraints(Arrays.asList(constraint));
- return pdd;
+ final RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition =
+ new RequirementNodeFilterPropertyDataDefinition();
+ requirementNodeFilterPropertyDataDefinition.setConstraints(Arrays.asList(constraint));
+ return requirementNodeFilterPropertyDataDefinition;
+ }
+
+ private RequirementNodeFilterCapabilityDataDefinition getRequirementNodeFilterCapabilityDataDefinition(
+ final String constraint) {
+
+ final RequirementNodeFilterCapabilityDataDefinition requirementNodeFilterCapabilityDataDefinition =
+ new RequirementNodeFilterCapabilityDataDefinition();
+ final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> propertyDataDefinitionList =
+ new ListDataDefinition<>();
+ propertyDataDefinitionList.getListToscaDataDefinition().addAll(
+ Collections.singleton(getRequirementNodeFilterPropertyDataDefinition(constraint)));
+ requirementNodeFilterCapabilityDataDefinition.setName(new ConstraintConvertor().convert(constraint)
+ .getServicePropertyName());
+ requirementNodeFilterCapabilityDataDefinition.setProperties(propertyDataDefinitionList);
+ return requirementNodeFilterCapabilityDataDefinition;
}
private CINodeFilterDataDefinition validateAndReturnNodeFilterDefinition(final String componentInstanceId,
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 5146d5e5b5..2291d8e984 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
@@ -207,9 +207,15 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet {
"Failed to parse constraint data", constraintData));
}
final List<String> constraints = new ConstraintConvertor().convertToList(uiConstraints);
+ final Optional<NodeFilterConstraintType> nodeFilterConstraintType =
+ NodeFilterConstraintType.parse(constraintType);
+ if (!nodeFilterConstraintType.isPresent()) {
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT_PARAM,
+ "Invalid value for NodeFilterConstraintType enum %s", constraintType));
+ }
final Optional<CINodeFilterDataDefinition> actionResponse = componentNodeFilterBusinessLogic
.updateNodeFilter(componentId.toLowerCase(), componentInstanceId, constraints,
- true, componentTypeEnum);
+ true, componentTypeEnum, nodeFilterConstraintType.get());
if (!actionResponse.isPresent()) {
LOGGER.error(FAILED_TO_UPDATE_NODE_FILTER);
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 a475943735..7c81807777 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
@@ -470,7 +470,8 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
final List<String> constraints = requirementNodeFilterPropertyDataDefinition.getConstraints();
assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
- .updateNodeFilter(componentId, componentInstanceId, constraints, true, ComponentTypeEnum.RESOURCE));
+ .updateNodeFilter(componentId, componentInstanceId, constraints, true, ComponentTypeEnum.RESOURCE,
+ NodeFilterConstraintType.PROPERTIES));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(nodeFilterValidator, times(1)).validateFilter(resource, componentInstanceId,
@@ -485,7 +486,8 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
constraints, NodeFilterConstraintAction.UPDATE)).thenReturn(Either.left(true));
assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
- .updateNodeFilter(componentId, componentInstanceId, constraints, true, ComponentTypeEnum.RESOURCE));
+ .updateNodeFilter(componentId, componentInstanceId, constraints, true, ComponentTypeEnum.RESOURCE,
+ NodeFilterConstraintType.PROPERTIES));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(nodeFilterValidator, times(1)).validateFilter(resource, componentInstanceId,
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 31cb1ac4e4..947a702db0 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
@@ -328,7 +328,8 @@ public class ComponentNodeFilterServletTest extends JerseyTest {
when(componentNodeFilterBusinessLogic
.updateNodeFilter(componentId, componentInstance, Collections.singletonList(constraint),
- true, ComponentTypeEnum.RESOURCE)).thenReturn(Optional.of(ciNodeFilterDataDefinition));
+ true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES))
+ .thenReturn(Optional.of(ciNodeFilterDataDefinition));
final Response response = target()
.path(path)
.request(MediaType.APPLICATION_JSON)
@@ -337,7 +338,7 @@ public class ComponentNodeFilterServletTest extends JerseyTest {
verify(componentNodeFilterBusinessLogic, times(1))
.updateNodeFilter(anyString(), anyString(), anyList(), anyBoolean(),
- ArgumentMatchers.any(ComponentTypeEnum.class));
+ ArgumentMatchers.any(ComponentTypeEnum.class), ArgumentMatchers.any(NodeFilterConstraintType.class));
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
}
@@ -359,7 +360,7 @@ public class ComponentNodeFilterServletTest extends JerseyTest {
when(componentNodeFilterBusinessLogic
.updateNodeFilter(componentId, componentInstance, Collections.singletonList(constraint),
- true, ComponentTypeEnum.RESOURCE))
+ true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES))
.thenReturn(Optional.empty());
final Response response = target()
.path(path)
@@ -369,7 +370,7 @@ public class ComponentNodeFilterServletTest extends JerseyTest {
verify(componentNodeFilterBusinessLogic, times(1))
.updateNodeFilter(anyString(), anyString(), anyList(), anyBoolean(),
- ArgumentMatchers.any(ComponentTypeEnum.class));
+ ArgumentMatchers.any(ComponentTypeEnum.class), ArgumentMatchers.any(NodeFilterConstraintType.class));
assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
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 1bad8b097f..050709d6d5 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
@@ -143,16 +143,29 @@ public class NodeFilterOperation extends BaseOperation {
}
public Either<CINodeFilterDataDefinition, StorageOperationStatus> updateProperties(
- final String serviceId, final String componentInstanceId,
+ final String componentId, final String componentInstanceId,
final CINodeFilterDataDefinition nodeFilterDataDefinition,
final List<RequirementNodeFilterPropertyDataDefinition> requirementNodeFilterPropertyDataDefinition) {
- ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> properties =
+ final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> properties =
nodeFilterDataDefinition.getProperties();
properties.getListToscaDataDefinition().clear();
properties.getListToscaDataDefinition().addAll(requirementNodeFilterPropertyDataDefinition);
nodeFilterDataDefinition.setProperties(properties);
- return addOrUpdateNodeFilter(true, serviceId, componentInstanceId, nodeFilterDataDefinition);
+ return addOrUpdateNodeFilter(true, componentId, componentInstanceId, nodeFilterDataDefinition);
+ }
+
+ public Either<CINodeFilterDataDefinition, StorageOperationStatus> updateCapabilities(
+ final String componentId, final String componentInstanceId,
+ final CINodeFilterDataDefinition nodeFilterDataDefinition,
+ final List<RequirementNodeFilterCapabilityDataDefinition> requirementNodeFilterCapabilityDataDefinitions) {
+
+ final ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> capabilities =
+ nodeFilterDataDefinition.getCapabilities();
+ capabilities.getListToscaDataDefinition().clear();
+ capabilities.getListToscaDataDefinition().addAll(requirementNodeFilterCapabilityDataDefinitions);
+ nodeFilterDataDefinition.setCapabilities(capabilities);
+ return addOrUpdateNodeFilter(true, componentId, componentInstanceId, nodeFilterDataDefinition);
}
public Either<CINodeFilterDataDefinition, StorageOperationStatus> updateNodeFilter(final String serviceId,
@@ -201,7 +214,6 @@ public class NodeFilterOperation extends BaseOperation {
VertexTypeEnum.NODE_FILTER_TEMPLATE, toscaDataList, JsonPresentationFields.UNIQUE_ID);
}
}
-
}