From b6e7850484ba61df259e38fd6b59e94c2a7de5b6 Mon Sep 17 00:00:00 2001 From: shrikantawachar Date: Mon, 17 Dec 2018 12:26:43 +0530 Subject: API for get all interface lifecycle types API for get all interface lifecycle types Change-Id: I64471c98ff9626ac53562a075a34f506c2e263ab Issue-ID: SDC-1999 Signed-off-by: shrikantawachar --- .../sdc/be/components/impl/BaseBusinessLogic.java | 8 ++++ .../impl/InterfaceOperationBusinessLogic.java | 13 ++++++ .../sdc/be/servlets/TypesFetchServlet.java | 51 ++++++++++++++++++++++ 3 files changed, 72 insertions(+) (limited to 'catalog-be/src/main/java/org') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java index 453564e2f8..02e64334f9 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java @@ -45,6 +45,7 @@ import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.operations.StorageException; import org.openecomp.sdc.be.model.operations.api.*; import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter; +import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation; import org.openecomp.sdc.be.model.operations.impl.PolicyTypeOperation; import org.openecomp.sdc.be.model.operations.impl.PropertyOperation; import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils; @@ -129,6 +130,9 @@ public abstract class BaseBusinessLogic { @Autowired protected InterfaceOperationBusinessLogic interfaceOperationBusinessLogic; + @Autowired + protected InterfaceLifecycleOperation interfaceLifecycleOperation; + @javax.annotation.Resource private UserValidations userValidations; @@ -171,6 +175,10 @@ public abstract class BaseBusinessLogic { } + public void setInterfaceLifecycleOperation(InterfaceLifecycleOperation interfaceLifecycleOperation) { + this.interfaceLifecycleOperation = interfaceLifecycleOperation; + } + User validateUserNotEmpty(User user, String ecompErrorContext) { return userValidations.validateUserNotEmpty(user, ecompErrorContext); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java index fed2cac518..a0efddbdda 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java @@ -41,6 +41,7 @@ import java.util.Collections; import java.util.Map; import java.util.Optional; import java.util.UUID; +import java.util.stream.Collectors; @Component("interfaceOperationBusinessLogic") public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { @@ -324,4 +325,16 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { } return Either.left( interfaceDefinition); } + + public Either, ResponseFormat> getAllInterfaceLifecycleTypes() { + + Either, StorageOperationStatus> interfaceLifecycleTypes = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(); + if(interfaceLifecycleTypes.isRight()) { + return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_LIFECYCLE_TYPES_NOT_FOUND)); + } + interfaceLifecycleTypes.left().value().values().stream().forEach( + id -> id.setOperations(id.getOperations().keySet().stream().collect(Collectors.toMap(key -> key.replaceFirst(id.getUniqueId()+".",""), i -> id.getOperations().get(i))))); + + return Either.left(interfaceLifecycleTypes.left().value()); + } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java index 8bb93a7d3d..ddb405779d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java @@ -26,11 +26,13 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic; import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.model.DataTypeDefinition; +import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.datastructure.Wrapper; @@ -109,4 +111,53 @@ public class TypesFetchServlet extends AbstractValidationsServlet { return webApplicationContext.getBean(PropertyBusinessLogic.class); } + @GET + @Path("interfaceLifecycleTypes") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Get interface lifecycle types", httpMethod = "GET", notes = "Returns interface lifecycle types", response = Response.class) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Interface lifecycle types"), + @ApiResponse(code = 403, message = "Restricted operation"), + @ApiResponse(code = 400, message = "Invalid content / Missing content"), + @ApiResponse(code = 404, message = "Interface lifecycle types not found") + }) + public Response getInterfaceLifecycleTypes(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { + + Wrapper responseWrapper = new Wrapper<>(); + Wrapper userWrapper = new Wrapper<>(); + ServletContext context = request.getSession().getServletContext(); + + try { + validateUserExist(responseWrapper, userWrapper, userId); + + if (responseWrapper.isEmpty()) { + String url = request.getMethod() + " " + request.getRequestURI(); + log.info("Start handle request of {} | modifier id is {}", url, userId); + + InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context); + Either, ResponseFormat> allInterfaceLifecycleTypes = + businessLogic.getAllInterfaceLifecycleTypes(); + + if (allInterfaceLifecycleTypes.isRight()) { + log.info("Failed to get all interface lifecycle types. Reason - {}", + allInterfaceLifecycleTypes.right().value()); + Response errorResponse = buildErrorResponse(allInterfaceLifecycleTypes.right().value()); + responseWrapper.setInnerElement(errorResponse); + + } else { + String interfaceLifecycleTypeJson = gson.toJson(allInterfaceLifecycleTypes.left().value()); + Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), interfaceLifecycleTypeJson); + responseWrapper.setInnerElement(okResponse); + + } + } + + return responseWrapper.getInnerElement(); + } catch (Exception e) { + log.debug("get all interface lifecycle types failed with exception", e); + ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR); + return buildErrorResponse(responseFormat); + } + } } -- cgit 1.2.3-korg