aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java
diff options
context:
space:
mode:
authorSindhuri.A <arcot.sindhuri@huawei.com>2018-10-17 13:25:27 +0530
committerTal Gitelman <tal.gitelman@att.com>2018-11-03 13:54:27 +0000
commit4eb4059162269fea685136572257a48345873ec7 (patch)
treeca8b99cbf45376b52ef2614ca0c52a5755873cfc /catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java
parentc5f4d83f7841a6937346da80a35b608e6624d54b (diff)
Batch delete keyboard shorcut on canvas
Keyboard Shortcut for batch delete (multiple select nodes and delete) on Composition page canvas Issue-ID: SDC-1734 Change-Id: I7de5d95a1ca6ea27cdd257b20bfdc1ed9b0ce102 Signed-off-by: Sindhuri.A <arcot.sindhuri@huawei.com>
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java131
1 files changed, 130 insertions, 1 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java
index 3195727a68..042303e2c3 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java
@@ -1244,9 +1244,138 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet {
return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
copyComponentInstance.left().value());
} catch (Exception e) {
- log.error("Failed to convert json to Map { }, error: { }", data, e);
+ log.error("Failed to convert json to Map { }", data, e);
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.USER_DEFINED,
"Failed to get the copied component instance information"));
}
}
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/batchDeleteResourceInstances/")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Batch Delete ResourceInstances", httpMethod = "POST")
+ @ApiResponses(value = {
+ @ApiResponse(code = 203, message = "ResourceInstances deleted"),
+ @ApiResponse(code = 403, message = "Restricted Operation"),
+ @ApiResponse(code = 400, message = "Invalid Content / Missing Content")
+ })
+ public Response batchDeleteResourceInstances(
+ @ApiParam(value = "valid values: resources / services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + "," +
+ ComponentTypeEnum.PRODUCT_PARAM_NAME)
+ @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId,
+ @Context final HttpServletRequest request,
+ @ApiParam(value = "Component Instance Id List", required = true) final String componentInstanceIdLisStr) {
+ ServletContext context = request.getSession().getServletContext();
+ try {
+ if (componentInstanceIdLisStr == null || componentInstanceIdLisStr.isEmpty()) {
+ log.error("Empty JSON List was sent",componentInstanceIdLisStr);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+
+ ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
+ if (componentInstanceLogic == null) {
+ log.error("Unsupported component type {}", containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ Either<List<String>, ResponseFormat> convertResponse = convertToStringList(componentInstanceIdLisStr);
+
+ if (convertResponse.isRight()) {
+ BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - batchDeleteResourceInstances");
+ log.error("Failed to convert received data to BE format.");
+ return buildErrorResponse(convertResponse.right().value());
+ }
+
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ List<String> componentInstanceIdList = convertResponse.left().value();
+ log.debug("batchDeleteResourceInstances componentInstanceIdList is {}", componentInstanceIdList);
+ Map<String, List<String>> deleteErrorMap = componentInstanceLogic.batchDeleteComponentInstance(containerComponentType,
+ componentId, componentInstanceIdList, userId);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), deleteErrorMap);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Batch Delete ResourceInstances");
+ log.error("batch delete resource instances with exception" , e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ }
+
+ @PUT
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/batchDissociate")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Batch Dissociate RI from RI", httpMethod = "PUT", notes = "Returns deleted RelationShip Info", response = Response.class)
+ @ApiResponses(value = {
+ @ApiResponse(code = 201, message = "Relationship deleted"),
+ @ApiResponse(code = 403, message = "Missing Information"),
+ @ApiResponse(code = 400, message = "Invalid Content / Missing Content")
+ })
+ public Response batchDissociateRIFromRI(
+ @ApiParam(value = "allowed values are resources/services/products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + "," + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true)
+ @PathParam("containerComponentType") final String containerComponentType,
+ @ApiParam(value = "unique id of the container component")
+ @PathParam("componentId") final String componentId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @ApiParam(value = "RelationshipInfo", required = true) String data,
+ @Context final HttpServletRequest request) {
+ ServletContext context = request.getSession().getServletContext();
+
+ try {
+ if (data == null || data.length() == 0) {
+ log.info("Empty JSON list was sent");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
+
+ if (componentInstanceLogic == null) {
+ log.debug("Unsupported component type {}", containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ Either<List<RequirementCapabilityRelDef>, ResponseFormat> regInfoWs = convertToRequirementCapabilityRelDefList(data);
+
+ if (regInfoWs.isRight()) {
+ BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - batch dissociateRIFromRI");
+ log.debug("Failed to convert received data to BE format");
+ return buildErrorResponse(regInfoWs.right().value());
+ }
+
+ List<RequirementCapabilityRelDef> requirementDefList = regInfoWs.left().value();
+ List<RequirementCapabilityRelDef> delOkResult = componentInstanceLogic.batchDissociateRIFromRI(
+ componentId, userId, requirementDefList, componentTypeEnum);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), delOkResult);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Batch Dissociate Resource Instance");
+ log.debug("batch dissociate resource instance from service failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ private Either<List<String>, ResponseFormat> convertToStringList(String datalist) {
+ Either<String[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(datalist, new User(), String[].class, null, null);
+
+ if (convertStatus.isRight()) {
+ return Either.right(convertStatus.right().value());
+ }
+
+ return Either.left(Arrays.asList(convertStatus.left().value()));
+ }
+
+ private Either<List<RequirementCapabilityRelDef>, ResponseFormat> convertToRequirementCapabilityRelDefList(String data) {
+ Either<RequirementCapabilityRelDef[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(data, new User(), RequirementCapabilityRelDef[].class, null, null);
+
+ if (convertStatus.isRight()) {
+ return Either.right(convertStatus.right().value());
+ }
+
+ return Either.left(Arrays.asList(convertStatus.left().value()));
+ }
+
}