diff options
author | aribeiro <anderson.ribeiro@est.tech> | 2020-08-24 17:09:20 +0100 |
---|---|---|
committer | Sébastien Determe <sebastien.determe@intl.att.com> | 2020-09-07 07:11:49 +0000 |
commit | c70b7081d70edf93aefae514dc688d8dc1835db2 (patch) | |
tree | 70f4c24e46e0b9593df169c655de71ea1a808eec /catalog-be/src/main/java | |
parent | 0c61108fca142e7e6a9d59453e3b14f2b402e89d (diff) |
Add node_filter capabilities
Issue-ID: SDC-3263
Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
Change-Id: I2965c8b0b9331b035ba5f9cc7f58d9ea3af26402
Diffstat (limited to 'catalog-be/src/main/java')
2 files changed, 59 insertions, 14 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 de6836d993..ac5af15d6e 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 @@ -32,8 +32,11 @@ 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.CINodeFilterDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; +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.User; @@ -166,15 +169,14 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic { return Optional.ofNullable(result.left().value()); } - - public Optional<CINodeFilterDataDefinition> addNodeFilter(final String componentId, final String componentInstanceId, final NodeFilterConstraintAction action, final String propertyName, final String constraint, final boolean shouldLock, - final ComponentTypeEnum componentTypeEnum) + final ComponentTypeEnum componentTypeEnum, + final NodeFilterConstraintType nodeFilterConstraintType) throws BusinessLogicException { final Component component = getComponent(componentId); @@ -186,13 +188,13 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic { lockComponent(component.getUniqueId(), component,"Add Node Filter on Component"); wasLocked = true; } - final RequirementNodeFilterPropertyDataDefinition newProperty = + final RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition(); - newProperty.setName(propertyName); - newProperty.setConstraints(Collections.singletonList(constraint)); - final Either<CINodeFilterDataDefinition, StorageOperationStatus> result = nodeFilterOperation - .addNewProperty(componentId, componentInstanceId, nodeFilterDataDefinition, newProperty); - + requirementNodeFilterPropertyDataDefinition.setName(propertyName); + requirementNodeFilterPropertyDataDefinition.setConstraints(Collections.singletonList(constraint)); + final Either<CINodeFilterDataDefinition, StorageOperationStatus> result = addNewNodeFilter(componentId, + componentInstanceId, propertyName, nodeFilterConstraintType, nodeFilterDataDefinition, + requirementNodeFilterPropertyDataDefinition); if (result.isRight()) { janusGraphDao.rollback(); throw new BusinessLogicException(componentsUtils.getResponseFormatByResource(componentsUtils @@ -322,6 +324,30 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic { return Optional.ofNullable(nodeFilterDataDefinition); } + private Either<CINodeFilterDataDefinition, StorageOperationStatus> addNewNodeFilter( + final String componentId, + final String componentInstanceId, + final String propertyName, + final NodeFilterConstraintType nodeFilterConstraintType, + final CINodeFilterDataDefinition nodeFilterDataDefinition, + final RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition) { + + if (NodeFilterConstraintType.PROPERTIES.equals(nodeFilterConstraintType)) { + return nodeFilterOperation.addNewProperty(componentId, componentInstanceId, nodeFilterDataDefinition, + requirementNodeFilterPropertyDataDefinition); + } + final RequirementNodeFilterCapabilityDataDefinition requirementNodeFilterCapabilityDataDefinition = + new RequirementNodeFilterCapabilityDataDefinition(); + requirementNodeFilterCapabilityDataDefinition.setName(propertyName); + final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> + propertyDataDefinitionListDataDefinition = new ListDataDefinition<>(); + propertyDataDefinitionListDataDefinition.getListToscaDataDefinition().addAll( + Collections.singleton(requirementNodeFilterPropertyDataDefinition)); + requirementNodeFilterCapabilityDataDefinition.setProperties(propertyDataDefinitionListDataDefinition); + return nodeFilterOperation.addNewCapabilities(componentId, componentInstanceId, nodeFilterDataDefinition, + requirementNodeFilterCapabilityDataDefinition); + } + private void unlockComponent(final String componentUniqueId, final ComponentTypeEnum componentType) { graphLockOperation.unlockComponent(componentUniqueId, componentType.getNodeType()); @@ -398,4 +424,4 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic { .getResponseFormat(ActionStatus.NODE_FILTER_NOT_FOUND, response.right().value().getFormattedMessage())); } } -}
\ No newline at end of file +} 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 aa9b931057..a682dc9bed 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 @@ -53,6 +53,7 @@ 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; @@ -64,7 +65,7 @@ import org.openecomp.sdc.common.api.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Path("/v1/catalog/{componentType}/{componentId}/resourceInstances/{componentInstanceId}/nodeFilter") +@Path("/v1/catalog/{componentType}/{componentId}/resourceInstances/{componentInstanceId}/nodeFilter/{constraintType}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Singleton @@ -104,7 +105,6 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Path("/") @Operation(description = "Add Component Filter Constraint", method = "POST", summary = "Add Component Filter Constraint", responses = { @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))), @@ -120,6 +120,10 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet { schema = @Schema(allowableValues = { ComponentTypeEnum.RESOURCE_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) { @@ -138,9 +142,17 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet { final UIConstraint uiConstraint = convertResponse.get(); final String constraint = new ConstraintConvertor().convert(uiConstraint); + 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 .addNodeFilter(componentId.toLowerCase(), componentInstanceId, NodeFilterConstraintAction.ADD, - uiConstraint.getServicePropertyName(), constraint, true, componentTypeEnum); + uiConstraint.getServicePropertyName(), constraint, true, componentTypeEnum, + nodeFilterConstraintType.get()); if (!actionResponse.isPresent()) { LOGGER.error(FAILED_TO_CREATE_NODE_FILTER); @@ -160,7 +172,6 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet { @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Path("/") @Operation(description = "Update Component Filter Constraint", method = "PUT", summary = "Update Component Filter Constraint", responses = { @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))), @@ -176,6 +187,10 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet { schema = @Schema(allowableValues = { ComponentTypeEnum.RESOURCE_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()); @@ -230,6 +245,10 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet { schema = @Schema(allowableValues = { ComponentTypeEnum.RESOURCE_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()); |