From b35c78cbd83ed73bdc83b445435818e370ac4a41 Mon Sep 17 00:00:00 2001 From: Piotr Darosz Date: Wed, 10 Jul 2019 13:14:39 +0200 Subject: catalog-be servlets refactoring Add constructor injection to servlets inside catalog-be project Change-Id: I46c85f932cbcc275ce82ce64ec1978ffec98ea9b Issue-ID: SDC-2442 Signed-off-by: Piotr Darosz --- .../impl/ComponentBusinessLogicProvider.java | 3 + .../servlet/DistributionCatalogServlet.java | 30 +++-- .../distribution/servlet/DistributionServlet.java | 35 ++--- .../servlet/ArtifactExternalServlet.java | 76 ++++++----- .../be/externalapi/servlet/AssetsDataServlet.java | 60 ++++++--- .../externalapi/servlet/CrudExternalServlet.java | 40 ++++-- .../externalapi/servlet/ExternalRefsServlet.java | 14 +- .../servlet/ServiceActivationServlet.java | 23 +++- .../be/servlets/AbstractValidationsServlet.java | 33 ++--- .../be/servlets/AdditionalInformationServlet.java | 36 ++---- .../openecomp/sdc/be/servlets/ArchiveEndpoint.java | 2 + .../openecomp/sdc/be/servlets/ArtifactServlet.java | 38 +++--- .../sdc/be/servlets/AttributeServlet.java | 15 +++ .../sdc/be/servlets/AutomatedUpgradeEndpoint.java | 14 +- .../sdc/be/servlets/BeGenericServlet.java | 141 ++------------------ .../sdc/be/servlets/BeMonitoringServlet.java | 31 +++-- .../sdc/be/servlets/CapabilityServlet.java | 34 +++-- .../sdc/be/servlets/ComponentInstanceServlet.java | 144 ++++++++++----------- .../sdc/be/servlets/ComponentPropertyServlet.java | 43 +++--- .../sdc/be/servlets/ComponentServlet.java | 35 ++--- .../openecomp/sdc/be/servlets/ConsumerServlet.java | 29 +++-- .../sdc/be/servlets/CsarBuildServlet.java | 15 +++ .../be/servlets/DistributionServiceServlet.java | 32 ++--- .../openecomp/sdc/be/servlets/ElementServlet.java | 86 ++++++------ .../be/servlets/GenericArtifactBrowserServlet.java | 25 +++- .../openecomp/sdc/be/servlets/GroupEndpoint.java | 2 + .../openecomp/sdc/be/servlets/GroupServlet.java | 37 +++--- .../openecomp/sdc/be/servlets/InputsServlet.java | 59 ++++----- .../sdc/be/servlets/InterfaceOperationServlet.java | 37 ++++-- .../sdc/be/servlets/LifecycleServlet.java | 22 +++- .../openecomp/sdc/be/servlets/PolicyServlet.java | 15 ++- .../openecomp/sdc/be/servlets/ProductServlet.java | 40 +++--- .../sdc/be/servlets/RequirementServlet.java | 34 +++-- .../sdc/be/servlets/RequirementsServlet.java | 11 ++ .../servlets/ResourceArtifactDownloadServlet.java | 30 ++--- .../sdc/be/servlets/ResourceUploadServlet.java | 26 ++-- .../sdc/be/servlets/ResourcesServlet.java | 63 +++++---- .../sdc/be/servlets/ServiceConsumptionServlet.java | 27 +++- .../sdc/be/servlets/ServiceFilterServlet.java | 28 +++- .../be/servlets/ServiceForwardingPathServlet.java | 32 +++-- .../openecomp/sdc/be/servlets/ServiceServlet.java | 103 ++++++++------- .../openecomp/sdc/be/servlets/ToscaDaoServlet.java | 44 +++---- .../sdc/be/servlets/TypesFetchServlet.java | 54 +++++--- .../sdc/be/servlets/TypesUploadServlet.java | 20 ++- .../sdc/be/servlets/UserAdminServlet.java | 47 +++---- .../servlet/DistributionServletTest.java | 37 ++++-- .../externalapi/servlet/AssetsDataServletTest.java | 24 +++- .../servlet/ExternalRefServletTest.java | 3 +- .../servlets/AbstractValidationsServletTest.java | 19 ++- .../servlets/AdditionalInformationServletTest.java | 14 +- .../sdc/be/servlets/ArchiveEndpointTest.java | 2 +- .../sdc/be/servlets/ArtifactServletTest.java | 13 +- .../sdc/be/servlets/AttributeServletTest.java | 17 ++- .../be/servlets/AutomatedUpgradeEndpointTest.java | 9 +- .../be/servlets/ComponentInstanceServletTest.java | 19 +++ .../be/servlets/ComponentPropertyServletTest.java | 14 -- .../sdc/be/servlets/ComponentServletTest.java | 11 +- .../sdc/be/servlets/ConsumerServletTest.java | 11 +- .../sdc/be/servlets/CsarBuildServletTest.java | 18 ++- .../servlets/DistributionServiceServletTest.java | 12 +- .../sdc/be/servlets/ElementServletTest.java | 15 ++- .../sdc/be/servlets/GroupServletTest.java | 19 ++- .../sdc/be/servlets/InputsServletTest.java | 132 +++++++++++-------- .../sdc/be/servlets/LifecycleServletTest.java | 13 +- .../sdc/be/servlets/PolicyServletTest.java | 3 +- .../sdc/be/servlets/ProductServletTest.java | 13 +- .../sdc/be/servlets/RequirementsServletTest.java | 12 +- .../ResourceArtifactDownloadServletTest.java | 16 ++- .../sdc/be/servlets/ResourceServletTest.java | 30 +++-- .../sdc/be/servlets/ResourcesServletTest.java | 19 ++- .../sdc/be/servlets/ServiceServletTest.java | 17 ++- .../sdc/be/servlets/TypesFetchServletTest.java | 22 +++- .../sdc/be/servlets/TypesUploadServletTest.java | 10 +- 73 files changed, 1390 insertions(+), 919 deletions(-) (limited to 'catalog-be/src') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogicProvider.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogicProvider.java index 8255de63d6..2c516cce57 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogicProvider.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogicProvider.java @@ -27,6 +27,8 @@ import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.springframework.stereotype.Component; +import javax.inject.Inject; + @Component public class ComponentBusinessLogicProvider { @@ -34,6 +36,7 @@ public class ComponentBusinessLogicProvider { private final ServiceBusinessLogic serviceBusinessLogic; private final ProductBusinessLogic productBusinessLogic; + @Inject public ComponentBusinessLogicProvider(ResourceBusinessLogic resourceBusinessLogic, ServiceBusinessLogic serviceBusinessLogic, ProductBusinessLogic productBusinessLogic) { this.resourceBusinessLogic = resourceBusinessLogic; this.serviceBusinessLogic = serviceBusinessLogic; diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionCatalogServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionCatalogServlet.java index ed1bc3eeb8..0da23ede9c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionCatalogServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionCatalogServlet.java @@ -24,10 +24,14 @@ import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData; import org.openecomp.sdc.be.servlets.BeGenericServlet; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; @@ -43,6 +47,7 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.HashMap; import java.util.Map; +import org.springframework.beans.factory.annotation.Autowired; /** * This Servlet serves external users to download artifacts. @@ -60,6 +65,16 @@ public class DistributionCatalogServlet extends BeGenericServlet { private static final String DOWNLOAD_ARTIFACT_FAILED_WITH_EXCEPTION = "download artifact failed with exception"; private static final String MISSING_X_ECOMP_INSTANCE_ID_HEADER = "Missing X-ECOMP-InstanceID header"; private static final Logger log = Logger.getLogger(DistributionCatalogServlet.class); + private final ArtifactsBusinessLogic artifactsBusinessLogic; + + @Autowired + public DistributionCatalogServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, + ArtifactsBusinessLogic artifactsBusinessLogic) { + super(userBusinessLogic, componentsUtils); + this.artifactsBusinessLogic = artifactsBusinessLogic; + } + @Context private HttpServletRequest request; @@ -111,9 +126,8 @@ public class DistributionCatalogServlet extends BeGenericServlet { } try { - ServletContext context = request.getSession().getServletContext(); - ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); - Either downloadRsrcArtifactEither = artifactsLogic.downloadServiceArtifactByNames(serviceName, serviceVersion, artifactName); + Either downloadRsrcArtifactEither = artifactsBusinessLogic + .downloadServiceArtifactByNames(serviceName, serviceVersion, artifactName); if (downloadRsrcArtifactEither.isRight()) { ResponseFormat responseFormat = downloadRsrcArtifactEither.right().value(); getComponentsUtils().auditDistributionDownload(responseFormat, new DistributionData(instanceIdHeader, requestURI)); @@ -188,9 +202,8 @@ public class DistributionCatalogServlet extends BeGenericServlet { } try { - ServletContext context = request.getSession().getServletContext(); - ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); - Either downloadRsrcArtifactEither = artifactsLogic.downloadRsrcArtifactByNames(serviceName, serviceVersion, resourceName, resourceVersion, artifactName); + Either downloadRsrcArtifactEither = artifactsBusinessLogic + .downloadRsrcArtifactByNames(serviceName, serviceVersion, resourceName, resourceVersion, artifactName); if (downloadRsrcArtifactEither.isRight()) { ResponseFormat responseFormat = downloadRsrcArtifactEither.right().value(); getComponentsUtils().auditDistributionDownload(responseFormat, new DistributionData(instanceIdHeader, requestURI)); @@ -263,9 +276,8 @@ public class DistributionCatalogServlet extends BeGenericServlet { } try { - ServletContext context = request.getSession().getServletContext(); - ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); - Either downloadRsrcArtifactEither = artifactsLogic.downloadRsrcInstArtifactByNames(serviceName, serviceVersion, resourceInstanceName, artifactName); + Either downloadRsrcArtifactEither = artifactsBusinessLogic + .downloadRsrcInstArtifactByNames(serviceName, serviceVersion, resourceInstanceName, artifactName); if (downloadRsrcArtifactEither.isRight()) { ResponseFormat responseFormat = downloadRsrcArtifactEither.right().value(); getComponentsUtils().auditDistributionDownload(responseFormat, new DistributionData(instanceIdHeader, requestURI)); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionServlet.java index f15babd5b9..c660b3b07e 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionServlet.java @@ -23,6 +23,9 @@ package org.openecomp.sdc.be.distribution.servlet; import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; +import javax.inject.Inject; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.distribution.AuditHandler; @@ -31,21 +34,19 @@ import org.openecomp.sdc.be.distribution.api.client.RegistrationRequest; import org.openecomp.sdc.be.distribution.api.client.ServerListResponse; import org.openecomp.sdc.be.distribution.api.client.TopicRegistrationResponse; import org.openecomp.sdc.be.distribution.api.client.TopicUnregistrationResponse; -import org.openecomp.sdc.be.impl.WebAppContextWrapper; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.servlets.BeGenericServlet; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.ArtifactTypeEnum; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.datastructure.Wrapper; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.common.util.HttpUtil; import org.openecomp.sdc.exception.ResponseFormat; -import org.springframework.web.context.WebApplicationContext; -import javax.annotation.Resource; import javax.inject.Singleton; -import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.*; import javax.ws.rs.core.Context; @@ -67,11 +68,17 @@ public class DistributionServlet extends BeGenericServlet { private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}"; private static final Logger log = Logger.getLogger(DistributionServlet.class); - @Resource - private DistributionBusinessLogic distributionLogic; + private final DistributionBusinessLogic distributionLogic; @Context private HttpServletRequest request; + @Inject + public DistributionServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, DistributionBusinessLogic distributionLogic) { + super(userBusinessLogic, componentsUtils); + this.distributionLogic = distributionLogic; + } + /** * * @param requestId @@ -102,7 +109,6 @@ public class DistributionServlet extends BeGenericServlet { @ApiParam(value = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept, @ApiParam(value = "The username and password", required = true)@HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization) { - init(request); String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); Response response = null; @@ -178,7 +184,6 @@ public class DistributionServlet extends BeGenericServlet { @ApiParam( hidden = true) String requestJson) { String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); - init(request); Wrapper responseWrapper = new Wrapper<>(); Wrapper registrationRequestWrapper = new Wrapper<>(); @@ -228,7 +233,6 @@ public class DistributionServlet extends BeGenericServlet { @ApiParam(value = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId, @ApiParam(value = "The username and password", required = true)@HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization, @ApiParam(value = "The username and password", required = true)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept) { - init(request); String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); Response response = null; @@ -286,7 +290,6 @@ public class DistributionServlet extends BeGenericServlet { String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); - init(request); Wrapper responseWrapper = new Wrapper<>(); Wrapper unRegistrationRequestWrapper = new Wrapper<>(); @@ -324,12 +327,6 @@ public class DistributionServlet extends BeGenericServlet { } - private void init(HttpServletRequest request) { - if (distributionLogic == null) { - distributionLogic = getDistributionBL(request.getSession().getServletContext()); - } - } - private void validateHeaders(Wrapper responseWrapper, HttpServletRequest request, AuditingActionEnum auditingAction) { if (request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER) == null) { Response missingHeaderResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID)); @@ -367,12 +364,6 @@ public class DistributionServlet extends BeGenericServlet { } - private DistributionBusinessLogic getDistributionBL(ServletContext context) { - WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); - WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); - return webApplicationContext.getBean(DistributionBusinessLogic.class); - } - private AuditHandler buildAuditHandler(HttpServletRequest request, RegistrationRequest registrationRequest) { return new AuditHandler(getComponentsUtils(), request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), registrationRequest); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java index f63b83d969..bed28f5712 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java @@ -36,18 +36,25 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import javax.inject.Inject; import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic; import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData; import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo; import org.openecomp.sdc.be.servlets.AbstractValidationsServlet; import org.openecomp.sdc.be.servlets.RepresentationUtils; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.datastructure.Wrapper; import org.openecomp.sdc.common.util.GeneralUtility; @@ -87,10 +94,23 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { @Context private HttpServletRequest request; + private final ArtifactsBusinessLogic artifactsBusinessLogic; + private static final Logger log = LoggerFactory.getLogger(ArtifactExternalServlet.class); private static String startLog = "Start handle request of "; + @Inject + public ArtifactExternalServlet(UserBusinessLogic userBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager, + ArtifactsBusinessLogic artifactsBusinessLogic) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); + this.artifactsBusinessLogic = artifactsBusinessLogic; + } + + @POST @Path("/{assetType}/{uuid}/interfaces/{interfaceUUID}/operations/{operationUUID}/artifacts/{artifactUUID}") @Produces(MediaType.APPLICATION_JSON) @@ -145,12 +165,10 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { } try { if (responseWrapper.isEmpty()) { - ServletContext context = request.getSession().getServletContext(); - ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); - Either uploadArtifactEither = artifactsLogic + Either uploadArtifactEither = artifactsBusinessLogic .updateArtifactOnInterfaceOperationByResourceUUID(data, request, ComponentTypeEnum .findByParamName(assetType), uuid, interfaceUUID, operationUUID, artifactUUID, - resourceCommonInfo, artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE)); + resourceCommonInfo, artifactsBusinessLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE)); if (uploadArtifactEither.isRight()) { log.debug(FAILED_TO_UPDATE_ARTIFACT); responseFormat = uploadArtifactEither.right().value(); @@ -247,10 +265,9 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { ArtifactDefinition artifactDefinition = null; try { if (responseWrapper.isEmpty()) { - ServletContext context = request.getSession().getServletContext(); - ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); - Either uploadArtifactEither = artifactsLogic.uploadArtifactToComponentByUUID(data, request, componentType, uuid, - resourceCommonInfo, artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.CREATE)); + Either uploadArtifactEither = artifactsBusinessLogic + .uploadArtifactToComponentByUUID(data, request, componentType, uuid, + resourceCommonInfo, artifactsBusinessLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.CREATE)); if (uploadArtifactEither.isRight()) { log.debug("failed to upload artifact"); responseWrapper.setInnerElement(uploadArtifactEither.right().value()); @@ -349,10 +366,9 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { } try { if (responseWrapper.isEmpty()) { - ServletContext context = request.getSession().getServletContext(); - ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); - Either uploadArtifactEither = artifactsLogic.uploadArtifactToRiByUUID(data, request, componentType, uuid, resourceInstanceName, - artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.CREATE)); + Either uploadArtifactEither = artifactsBusinessLogic + .uploadArtifactToRiByUUID(data, request, componentType, uuid, resourceInstanceName, + artifactsBusinessLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.CREATE)); if (uploadArtifactEither.isRight()) { log.debug("failed to upload artifact"); responseFormat = uploadArtifactEither.right().value(); @@ -453,10 +469,9 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { ArtifactDefinition artifactDefinition = null; try { if (responseWrapper.isEmpty()) { - ServletContext context = request.getSession().getServletContext(); - ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); - Either uploadArtifactEither = artifactsLogic.updateArtifactOnComponentByUUID(data, request, componentType, uuid, artifactUUID, - resourceCommonInfo, artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE)); + Either uploadArtifactEither = artifactsBusinessLogic + .updateArtifactOnComponentByUUID(data, request, componentType, uuid, artifactUUID, + resourceCommonInfo, artifactsBusinessLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE)); if (uploadArtifactEither.isRight()) { log.debug(FAILED_TO_UPDATE_ARTIFACT); responseFormat = uploadArtifactEither.right().value(); @@ -553,10 +568,9 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { ArtifactDefinition artifactDefinition = null; try { if (responseWrapper.isEmpty()) { - ServletContext context = request.getSession().getServletContext(); - ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); - Either uploadArtifactEither = artifactsLogic.updateArtifactOnRiByUUID(data, request, componentType, uuid, resourceInstanceName, artifactUUID, - artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE)); + Either uploadArtifactEither = artifactsBusinessLogic + .updateArtifactOnRiByUUID(data, request, componentType, uuid, resourceInstanceName, artifactUUID, + artifactsBusinessLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE)); if (uploadArtifactEither.isRight()) { log.debug(FAILED_TO_UPDATE_ARTIFACT); responseFormat = uploadArtifactEither.right().value(); @@ -647,10 +661,8 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { } try { if (responseWrapper.isEmpty()) { - ServletContext context = request.getSession().getServletContext(); - ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); - Either uploadArtifactEither = artifactsLogic.deleteArtifactOnComponentByUUID(request, componentType, uuid, artifactUUID, - resourceCommonInfo, artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.DELETE)); + Either uploadArtifactEither = artifactsBusinessLogic.deleteArtifactOnComponentByUUID(request, componentType, uuid, artifactUUID, + resourceCommonInfo, artifactsBusinessLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.DELETE)); if (uploadArtifactEither.isRight()) { log.debug("failed to delete artifact"); responseFormat = uploadArtifactEither.right().value(); @@ -742,10 +754,8 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { ArtifactDefinition artifactDefinition = null; try { if (responseWrapper.isEmpty()) { - ServletContext context = request.getSession().getServletContext(); - ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); - Either uploadArtifactEither = artifactsLogic.deleteArtifactOnRiByUUID(request, componentType, uuid, resourceInstanceName, artifactUUID, - artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.DELETE)); + Either uploadArtifactEither = artifactsBusinessLogic.deleteArtifactOnRiByUUID(request, componentType, uuid, resourceInstanceName, artifactUUID, + artifactsBusinessLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.DELETE)); if (uploadArtifactEither.isRight()) { log.debug("failed to delete artifact"); responseFormat = uploadArtifactEither.right().value(); @@ -825,9 +835,8 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentTypeValue); try { if (responseWrapper.isEmpty()) { - ServletContext context = request.getSession().getServletContext(); - ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); - Either downloadComponentArtifactEither = artifactsLogic.downloadComponentArtifactByUUIDs(componentType, uuid, artifactUUID, resourceCommonInfo); + Either downloadComponentArtifactEither = artifactsBusinessLogic + .downloadComponentArtifactByUUIDs(componentType, uuid, artifactUUID, resourceCommonInfo); if (downloadComponentArtifactEither.isRight()) { responseFormat = downloadComponentArtifactEither.right().value(); responseWrapper.setInnerElement(buildErrorResponse(responseFormat)); @@ -902,9 +911,8 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { } try { if (responseWrapper.isEmpty()) { - ServletContext context = request.getSession().getServletContext(); - ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); - Either downloadResourceArtifactEither = artifactsLogic.downloadResourceInstanceArtifactByUUIDs(componentType, uuid, resourceInstanceName, artifactUUID); + Either downloadResourceArtifactEither = artifactsBusinessLogic + .downloadResourceInstanceArtifactByUUIDs(componentType, uuid, resourceInstanceName, artifactUUID); if (downloadResourceArtifactEither.isRight()) { responseFormat = downloadResourceArtifactEither.right().value(); responseWrapper.setInnerElement(buildErrorResponse(responseFormat)); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java index 01306126ff..ebc0e62404 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java @@ -22,10 +22,24 @@ package org.openecomp.sdc.be.externalapi.servlet; import com.jcabi.aspects.Loggable; import fj.data.Either; -import io.swagger.annotations.*; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic; +import org.openecomp.sdc.be.components.impl.ComponentBusinessLogicProvider; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.ElementBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; @@ -33,21 +47,22 @@ import org.openecomp.sdc.be.datatypes.enums.FilterKeyEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.ecomp.converters.AssetMetadataConverter; import org.openecomp.sdc.be.externalapi.servlet.representation.AssetMetadata; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData; import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo; import org.openecomp.sdc.be.servlets.AbstractValidationsServlet; import org.openecomp.sdc.be.servlets.RepresentationUtils; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.common.util.GeneralUtility; import org.openecomp.sdc.exception.ResponseFormat; import javax.inject.Singleton; -import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.*; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -75,6 +90,23 @@ public class AssetsDataServlet extends AbstractValidationsServlet { private HttpServletRequest request; private static final Logger log = Logger.getLogger(AssetsDataServlet.class); + private final ElementBusinessLogic elementBusinessLogic; + private final AssetMetadataConverter assetMetadataConverter; + private final ComponentBusinessLogicProvider componentBusinessLogicProvider; + + @Inject + public AssetsDataServlet(UserBusinessLogic userBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager, + ElementBusinessLogic elementBusinessLogic, + AssetMetadataConverter assetMetadataConverter, + ComponentBusinessLogicProvider componentBusinessLogicProvider) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); + this.elementBusinessLogic = elementBusinessLogic; + this.assetMetadataConverter = assetMetadataConverter; + this.componentBusinessLogicProvider = componentBusinessLogicProvider; + } /** * @@ -133,10 +165,6 @@ public class AssetsDataServlet extends AbstractValidationsServlet { } try { - ServletContext context = request.getSession().getServletContext(); - ElementBusinessLogic elementLogic = getElementBL(context); - - AssetMetadataConverter assetMetadataUtils = getAssetUtils(context); Map filters = new EnumMap<>(FilterKeyEnum.class); if (category != null) { @@ -159,7 +187,7 @@ public class AssetsDataServlet extends AbstractValidationsServlet { filters.put(FilterKeyEnum.RESOURCE_TYPE, resourceTypeEnum.name()); } - Either, ResponseFormat> assetTypeData = elementLogic.getFilteredCatalogComponents(assetType, filters, query); + Either, ResponseFormat> assetTypeData = elementBusinessLogic.getFilteredCatalogComponents(assetType, filters, query); if (assetTypeData.isRight()) { log.debug("getAssetList: Asset Fetching Failed"); @@ -168,7 +196,8 @@ public class AssetsDataServlet extends AbstractValidationsServlet { return buildErrorResponse(responseFormat); } else { log.debug("getAssetList: Asset Fetching Success"); - Either, ResponseFormat> resMetadata = assetMetadataUtils.convertToAssetMetadata(assetTypeData.left().value(), requestURI, false); + Either, ResponseFormat> resMetadata = assetMetadataConverter + .convertToAssetMetadata(assetTypeData.left().value(), requestURI, false); if (resMetadata.isRight()) { log.debug("getAssetList: Asset conversion Failed"); responseFormat = resMetadata.right().value(); @@ -239,11 +268,8 @@ public class AssetsDataServlet extends AbstractValidationsServlet { } try { - ServletContext context = request.getSession().getServletContext(); - ElementBusinessLogic elementLogic = getElementBL(context); - AssetMetadataConverter assetMetadataUtils = getAssetUtils(context); - - Either, ResponseFormat> assetTypeData = elementLogic.getCatalogComponentsByUuidAndAssetType(assetType, uuid); + Either, ResponseFormat> assetTypeData = + elementBusinessLogic.getCatalogComponentsByUuidAndAssetType(assetType, uuid); if (assetTypeData.isRight()) { log.debug("getAssetList: Asset Fetching Failed"); @@ -255,7 +281,8 @@ public class AssetsDataServlet extends AbstractValidationsServlet { } resourceCommonInfo.setResourceName(assetTypeData.left().value().iterator().next().getName()); log.debug("getAssetList: Asset Fetching Success"); - Either, ResponseFormat> resMetadata = assetMetadataUtils.convertToAssetMetadata(assetTypeData.left().value(), requestURI, true); + Either, ResponseFormat> resMetadata = assetMetadataConverter + .convertToAssetMetadata(assetTypeData.left().value(), requestURI, true); if (resMetadata.isRight()) { log.debug("getAssetList: Asset conversion Failed"); responseFormat = resMetadata.right().value(); @@ -313,7 +340,6 @@ public class AssetsDataServlet extends AbstractValidationsServlet { log.debug("Start handle request of {} {}", request.getMethod(), url); Response response = null; ResponseFormat responseFormat = null; - ServletContext context = request.getSession().getServletContext(); ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType); AuditingActionEnum auditingActionEnum = AuditingActionEnum.GET_TOSCA_MODEL; @@ -329,7 +355,7 @@ public class AssetsDataServlet extends AbstractValidationsServlet { } try { - ComponentBusinessLogic componentBL = getComponentBL(componentType, context); + ComponentBusinessLogic componentBL = componentBusinessLogicProvider.getInstance(componentType); Either, ResponseFormat> csarArtifact = componentBL.getToscaModelByComponentUuid(componentType, uuid, resourceCommonInfo); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java index 29ebc14f9c..26b91a3625 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java @@ -24,13 +24,17 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; +import javax.inject.Inject; import org.apache.commons.lang3.StringUtils; import org.elasticsearch.common.Strings; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.ElementBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoBase; @@ -44,6 +48,8 @@ import org.openecomp.sdc.be.datatypes.enums.FilterKeyEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.ecomp.converters.AssetMetadataConverter; import org.openecomp.sdc.be.externalapi.servlet.representation.AssetMetadata; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.LifeCycleTransitionEnum; import org.openecomp.sdc.be.model.Resource; @@ -55,6 +61,7 @@ import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData; import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo; import org.openecomp.sdc.be.servlets.AbstractValidationsServlet; import org.openecomp.sdc.be.servlets.RepresentationUtils; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.be.utils.CommonBeUtils; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.datastructure.Wrapper; @@ -85,6 +92,26 @@ public class CrudExternalServlet extends AbstractValidationsServlet { private HttpServletRequest request; private static final Logger log = Logger.getLogger(CrudExternalServlet.class); + private final ElementBusinessLogic elementBusinessLogic; + private final AssetMetadataConverter assetMetadataUtils; + private final LifecycleBusinessLogic lifecycleBusinessLogic; + private final ResourceBusinessLogic resourceBusinessLogic; + + @Inject + public CrudExternalServlet(UserBusinessLogic userBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager, + ElementBusinessLogic elementBusinessLogic, + AssetMetadataConverter assetMetadataUtils, + LifecycleBusinessLogic lifecycleBusinessLogic, + ResourceBusinessLogic resourceBusinessLogic) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); + this.elementBusinessLogic = elementBusinessLogic; + this.assetMetadataUtils = assetMetadataUtils; + this.lifecycleBusinessLogic = lifecycleBusinessLogic; + this.resourceBusinessLogic = resourceBusinessLogic; + } /** * Creates a new Resource @@ -144,7 +171,6 @@ public class CrudExternalServlet extends AbstractValidationsServlet { ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(ComponentTypeEnum.RESOURCE.getValue()); ServletContext context = request.getSession().getServletContext(); - ResourceBusinessLogic resourceBL = getResourceBL(context); try { // Validate X-ECOMP-InstanceID Header if (responseWrapper.isEmpty()) { @@ -203,7 +229,7 @@ public class CrudExternalServlet extends AbstractValidationsServlet { } // Create the resource in the dataModel if (responseWrapper.isEmpty()) { - resource = resourceBL.createResource(resource, null, + resource = resourceBusinessLogic.createResource(resource, null, modifier, null, null); return buildCreatedResourceResponse(resource, context, responseWrapper); } else { @@ -272,7 +298,6 @@ public class CrudExternalServlet extends AbstractValidationsServlet { //get the business logic ServletContext context = request.getSession().getServletContext(); - LifecycleBusinessLogic businessLogic = getLifecycleBL(context); Wrapper responseWrapper = runValidations(assetType); ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType); @@ -297,7 +322,7 @@ public class CrudExternalServlet extends AbstractValidationsServlet { modifier = eitherGetUser.left().value(); //get the component id from the uuid - Either latestVersion = businessLogic.getLatestComponentByUuid(componentType, uuid); + Either latestVersion = lifecycleBusinessLogic.getLatestComponentByUuid(componentType, uuid); if (latestVersion.isRight()) { ResponseFormat responseFormat = latestVersion.right().value(); responseWrapper.setInnerElement(responseFormat); @@ -332,7 +357,8 @@ public class CrudExternalServlet extends AbstractValidationsServlet { } //execute business logic - Either actionResponse = businessLogic.changeComponentState(componentType, componentId, modifier, transitionEnum, changeInfo, false, true); + Either actionResponse = lifecycleBusinessLogic + .changeComponentState(componentType, componentId, modifier, transitionEnum, changeInfo, false, true); if (actionResponse.isRight()) { log.info("failed to change resource state"); ResponseFormat responseFormat = actionResponse.right().value(); @@ -369,7 +395,6 @@ public class CrudExternalServlet extends AbstractValidationsServlet { Wrapper responseWrapper) throws IOException { ResponseFormat responseFormat; Response response; - AssetMetadataConverter assetMetadataUtils = getAssetUtils(context); Either resMetadata = assetMetadataUtils .convertToSingleAssetMetadata(resource, request.getRequestURL().toString(), true); @@ -405,9 +430,8 @@ public class CrudExternalServlet extends AbstractValidationsServlet { ActionStatus.COMPONENT_MISSING_SUBCATEGORY)); } if (responseWrapper.isEmpty()) { - ElementBusinessLogic elementLogic = getElementBL(context); // get All Categories - Either, ActionStatus> allResourceCategories = elementLogic + Either, ActionStatus> allResourceCategories = elementBusinessLogic .getAllResourceCategories(); // Error fetching categories if (allResourceCategories.isRight()) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefsServlet.java index 1bdd859af7..ce1f3b297e 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefsServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefsServlet.java @@ -21,12 +21,16 @@ package org.openecomp.sdc.be.externalapi.servlet; import fj.data.Either; +import javax.inject.Inject; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.ExternalRefsBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.dto.ExternalRefDTO; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.servlets.BeGenericServlet; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.datastructure.Wrapper; import org.openecomp.sdc.common.log.wrappers.Logger; import org.springframework.stereotype.Controller; @@ -42,12 +46,14 @@ import java.util.Map; public class ExternalRefsServlet extends BeGenericServlet { private static final Logger log = Logger.getLogger(ExternalRefsServlet.class); - private final ComponentsUtils componentsUtils; private final ExternalRefsBusinessLogic businessLogic; - public ExternalRefsServlet(ExternalRefsBusinessLogic businessLogic, ComponentsUtils componentsUtils){ - this.businessLogic = businessLogic; - this.componentsUtils = componentsUtils; + @Inject + public ExternalRefsServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, + ExternalRefsBusinessLogic externalRefsBusinessLogic) { + super(userBusinessLogic, componentsUtils); + this.businessLogic = externalRefsBusinessLogic; } @GET diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ServiceActivationServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ServiceActivationServlet.java index 25ae6fb4b9..6f00168a77 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ServiceActivationServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ServiceActivationServlet.java @@ -24,16 +24,23 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; +import javax.inject.Inject; import org.apache.commons.lang3.StringUtils; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.externalapi.servlet.representation.ServiceDistributionReqInfo; import org.openecomp.sdc.be.externalapi.servlet.representation.ServiceDistributionRespInfo; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData; import org.openecomp.sdc.be.servlets.AbstractValidationsServlet; import org.openecomp.sdc.be.servlets.RepresentationUtils; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.datastructure.Wrapper; import org.openecomp.sdc.common.log.wrappers.Logger; @@ -61,6 +68,18 @@ public class ServiceActivationServlet extends AbstractValidationsServlet { private HttpServletRequest request; private static final Logger log = Logger.getLogger(ServiceActivationServlet.class); + private final ServiceBusinessLogic serviceBusinessLogic; + + @Inject + public ServiceActivationServlet(UserBusinessLogic userBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager, + ServiceBusinessLogic serviceBusinessLogic) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); + this.serviceBusinessLogic = serviceBusinessLogic; + } + /** * Activates a service on a specific environment @@ -107,7 +126,6 @@ public class ServiceActivationServlet extends AbstractValidationsServlet { String url = request.getMethod() + " " + requestURI; log.debug("Start handle request of {}", url); - ServletContext context = request.getSession().getServletContext(); User modifier = new User(); try { @@ -118,9 +136,8 @@ public class ServiceActivationServlet extends AbstractValidationsServlet { modifier.setUserId(userId); log.debug("modifier id is {}", userId); - ServiceBusinessLogic businessLogic = getServiceBL(context); ServiceDistributionReqInfo reqMetadata = convertJsonToActivationMetadata(data); - Either distResponse = businessLogic.activateServiceOnTenantEnvironment(serviceUUID, opEnvId, modifier, reqMetadata); + Either distResponse = serviceBusinessLogic.activateServiceOnTenantEnvironment(serviceUUID, opEnvId, modifier, reqMetadata); if (distResponse.isRight()) { log.debug("failed to activate service distribution"); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java index 54c6c9cd59..e00889646a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java @@ -47,6 +47,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.CsarValidationUtils; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.impl.ImportUtils; import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum; import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaElementTypeEnum; @@ -58,7 +59,6 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.impl.ServletUtils; -import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.UploadResourceInfo; @@ -67,6 +67,7 @@ import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.servlets.ResourceUploadServlet.ResourceAuthorityTypeEnum; import org.openecomp.sdc.be.user.IUserBusinessLogic; import org.openecomp.sdc.be.user.Role; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.be.utils.TypeUtils; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.api.UploadArtifactInfo; @@ -76,7 +77,6 @@ import org.openecomp.sdc.common.util.GeneralUtility; import org.openecomp.sdc.common.util.YamlToObjectConverter; import org.openecomp.sdc.common.util.ZipUtil; import org.openecomp.sdc.exception.ResponseFormat; -import org.springframework.web.context.WebApplicationContext; import org.yaml.snakeyaml.Yaml; public abstract class AbstractValidationsServlet extends BeGenericServlet { @@ -87,25 +87,20 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet { private static final List TOSCA_YML_CSAR_VALID_SUFFIX = Arrays.asList(".yml", ".yaml", ".csar"); protected ServletUtils servletUtils; - protected ResourceImportManager resourceImportManager; + protected final ComponentInstanceBusinessLogic componentInstanceBusinessLogic; - protected ComponentsUtils componentsUtils; - protected void init() { - initSpringFromContext(); + public AbstractValidationsServlet(UserBusinessLogic userBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, ComponentsUtils componentsUtils, + ServletUtils servletUtils, ResourceImportManager resourceImportManager) { + super(userBusinessLogic, componentsUtils); + this.servletUtils = servletUtils; + this.resourceImportManager = resourceImportManager; + this.componentInstanceBusinessLogic = componentInstanceBL; } - private synchronized void initSpringFromContext() { - if (servletUtils == null) { - ServletContext context = servletRequest.getSession().getServletContext(); - WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context - .getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); - WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); - servletUtils = webApplicationContext.getBean(ServletUtils.class); - resourceImportManager = webApplicationContext.getBean(ResourceImportManager.class); - componentsUtils = webApplicationContext.getBean(ComponentsUtils.class); - } + protected void init() { } protected void validateResourceDoesNotExist(Wrapper responseWrapper, User user, String resourceName) { @@ -297,7 +292,6 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet { } public ServletUtils getServletUtils() { - initSpringFromContext(); return servletUtils; } @@ -790,12 +784,11 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet { protected void validateComponentInstanceBusinessLogic(HttpServletRequest request, String containerComponentType, Wrapper blWrapper, Wrapper errorWrapper) { ServletContext context = request.getSession().getServletContext(); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug("Unsupported component type {}", containerComponentType); errorWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } else { - blWrapper.setInnerElement(componentInstanceLogic); + blWrapper.setInnerElement(componentInstanceBusinessLogic); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AdditionalInformationServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AdditionalInformationServlet.java index f8b83742d7..2583797598 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AdditionalInformationServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AdditionalInformationServlet.java @@ -23,17 +23,20 @@ package org.openecomp.sdc.be.servlets; import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; +import javax.inject.Inject; import org.openecomp.sdc.be.components.impl.AdditionalInformationBusinessLogic; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterInfo; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; -import org.openecomp.sdc.be.impl.WebAppContextWrapper; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.AdditionalInformationDefinition; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; -import org.springframework.web.context.WebApplicationContext; import javax.inject.Singleton; import javax.servlet.ServletContext; @@ -50,6 +53,15 @@ import javax.ws.rs.core.Response; public class AdditionalInformationServlet extends BeGenericServlet { private static final Logger log = Logger.getLogger(AdditionalInformationServlet.class); + private final AdditionalInformationBusinessLogic businessLogic; + + @Inject + public AdditionalInformationServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, + AdditionalInformationBusinessLogic businessLogic) { + super(userBusinessLogic, componentsUtils); + this.businessLogic = businessLogic; + } /** * @@ -297,9 +309,6 @@ public class AdditionalInformationServlet extends BeGenericServlet { // convert json to AdditionalInfoParameterInfo AdditionalInfoParameterInfo additionalInfoParameterInfo = gson.fromJson(data, AdditionalInfoParameterInfo.class); - // create the new property - AdditionalInformationBusinessLogic businessLogic = getBL(context); - Either either = businessLogic.createAdditionalInformation(nodeType, uniqueId, additionalInfoParameterInfo, userId); if (either.isRight()) { @@ -347,9 +356,6 @@ public class AdditionalInformationServlet extends BeGenericServlet { // convert json to AdditionalInfoParameterInfo AdditionalInfoParameterInfo additionalInfoParameterInfo = gson.fromJson(data, AdditionalInfoParameterInfo.class); - // create the new property - AdditionalInformationBusinessLogic businessLogic = getBL(context); - additionalInfoParameterInfo.setUniqueId(labelId); Either either = businessLogic.updateAdditionalInformation(nodeType, uniqueId, additionalInfoParameterInfo, userId); @@ -397,8 +403,6 @@ public class AdditionalInformationServlet extends BeGenericServlet { try { - AdditionalInformationBusinessLogic businessLogic = getBL(context); - AdditionalInfoParameterInfo additionalInfoParameterInfo = new AdditionalInfoParameterInfo(); additionalInfoParameterInfo.setUniqueId(labelId); @@ -446,9 +450,6 @@ public class AdditionalInformationServlet extends BeGenericServlet { try { - // create the new property - AdditionalInformationBusinessLogic businessLogic = getBL(context); - AdditionalInfoParameterInfo additionalInfoParameterInfo = new AdditionalInfoParameterInfo(); additionalInfoParameterInfo.setUniqueId(labelId); @@ -495,9 +496,6 @@ public class AdditionalInformationServlet extends BeGenericServlet { log.debug("modifier id is {}", userId); try { - - AdditionalInformationBusinessLogic businessLogic = getBL(context); - Either either = businessLogic.getAllAdditionalInformation(nodeType, uniqueId, userId); if (either.isRight()) { ResponseFormat responseFormat = either.right().value(); @@ -521,10 +519,4 @@ public class AdditionalInformationServlet extends BeGenericServlet { } - private AdditionalInformationBusinessLogic getBL(ServletContext context) { - WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); - WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); - return webApplicationContext.getBean(AdditionalInformationBusinessLogic.class); - } - } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArchiveEndpoint.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArchiveEndpoint.java index ebf2447c56..423181a3a5 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArchiveEndpoint.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArchiveEndpoint.java @@ -25,6 +25,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import javax.inject.Inject; import org.openecomp.sdc.be.components.impl.ArchiveBusinessLogic; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.model.catalog.CatalogComponent; @@ -51,6 +52,7 @@ public class ArchiveEndpoint { private final ArchiveBusinessLogic archiveBusinessLogic; + @Inject public ArchiveEndpoint(ArchiveBusinessLogic archiveBusinessLogic) { this.archiveBusinessLogic = archiveBusinessLogic; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java index b69fa0b840..ce7df4c652 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java @@ -23,17 +23,22 @@ package org.openecomp.sdc.be.servlets; import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; +import javax.inject.Inject; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic; import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.ArtifactUiDownloadData; import org.openecomp.sdc.be.model.Operation; import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; @@ -46,6 +51,7 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.Map; + /** * Root resource (exposed at "/" path) */ @@ -55,6 +61,15 @@ import java.util.Map; @Singleton public class ArtifactServlet extends BeGenericServlet { + private final ArtifactsBusinessLogic artifactsBusinessLogic; + + @Inject + public ArtifactServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, ArtifactsBusinessLogic artifactsBusinessLogic) { + super(userBusinessLogic, componentsUtils); + this.artifactsBusinessLogic = artifactsBusinessLogic; + } + private static final Logger log = Logger.getLogger(ArtifactServlet.class); // *************** Resources @@ -507,12 +522,10 @@ public class ArtifactServlet extends BeGenericServlet { log.debug("Start handle request of {}" , url); try { - ServletContext context = request.getSession().getServletContext(); - ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); Either uploadArtifactEither = - artifactsLogic.updateArtifactOnInterfaceOperationByResourceUUID(data, request, + artifactsBusinessLogic.updateArtifactOnInterfaceOperationByResourceUUID(data, request, ComponentTypeEnum.findByParamName(assetType), uuid, interfaceUUID, operationUUID, artifactUUID, - new ResourceCommonInfo(assetType), artifactsLogic.new ArtifactOperationInfo(true, + new ResourceCommonInfo(assetType), artifactsBusinessLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE)); if (uploadArtifactEither.isRight()) { log.debug("failed to update artifact"); @@ -543,8 +556,8 @@ public class ArtifactServlet extends BeGenericServlet { private Response handleDownloadRequest(HttpServletRequest request, String componentId, String artifactId, String parentId, ComponentTypeEnum componentType, String containerComponentType) { String userId = request.getHeader(Constants.USER_ID_HEADER); ServletContext context = request.getSession().getServletContext(); - ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); - Either, ResponseFormat> actionResult = artifactsLogic.handleDownloadRequestById(componentId, artifactId, userId, componentType, parentId, containerComponentType); + Either, ResponseFormat> actionResult = artifactsBusinessLogic + .handleDownloadRequestById(componentId, artifactId, userId, componentType, parentId, containerComponentType); Response response; if (actionResult.isRight()) { @@ -564,10 +577,8 @@ public class ArtifactServlet extends BeGenericServlet { private Response handleGetArtifactsRequest(HttpServletRequest request, String componentId, String parentId, String artifactGroupType, String containerComponentType) { String userId = request.getHeader(Constants.USER_ID_HEADER); - ServletContext context = request.getSession().getServletContext(); - ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); ComponentTypeEnum componentTypeEnum = parentId == null || parentId.isEmpty()? ComponentTypeEnum.findByParamName(containerComponentType): ComponentTypeEnum.RESOURCE_INSTANCE; - Either, ResponseFormat> actionResult = artifactsLogic.handleGetArtifactsByType(containerComponentType, parentId, componentTypeEnum, componentId, artifactGroupType, userId); + Either, ResponseFormat> actionResult = artifactsBusinessLogic.handleGetArtifactsByType(containerComponentType, parentId, componentTypeEnum, componentId, artifactGroupType, userId); Response response; if (actionResult.isRight()) { @@ -588,8 +599,7 @@ public class ArtifactServlet extends BeGenericServlet { private Response handleDeleteRequest(HttpServletRequest request, String componentId, String artifactId, ComponentTypeEnum componentType, String interfaceType, String operationName, String parentId) { String userId = request.getHeader(Constants.USER_ID_HEADER); ServletContext context = request.getSession().getServletContext(); - ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); - Either, ResponseFormat> actionResult = artifactsLogic.handleArtifactRequest(componentId, userId, componentType, artifactsLogic.new ArtifactOperationInfo (false, false, ArtifactOperationEnum.DELETE), artifactId, null, null, null, interfaceType, operationName, + Either, ResponseFormat> actionResult = artifactsBusinessLogic.handleArtifactRequest(componentId, userId, componentType, artifactsBusinessLogic.new ArtifactOperationInfo (false, false, ArtifactOperationEnum.DELETE), artifactId, null, null, null, interfaceType, operationName, parentId, null); Response response; if (actionResult.isRight()) { @@ -613,10 +623,8 @@ public class ArtifactServlet extends BeGenericServlet { String userId = request.getHeader(Constants.USER_ID_HEADER); - ServletContext context = request.getSession().getServletContext(); - ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); - Either, ResponseFormat> actionResult = artifactsLogic.handleArtifactRequest(componentId, userId, componentType, - artifactsLogic.new ArtifactOperationInfo (false, false,operationEnum), artifactId, artifactInfo, origMd5, data, interfaceName, operationName, parentId, + Either, ResponseFormat> actionResult = artifactsBusinessLogic.handleArtifactRequest(componentId, userId, componentType, + artifactsBusinessLogic.new ArtifactOperationInfo (false, false,operationEnum), artifactId, artifactInfo, origMd5, data, interfaceName, operationName, parentId, containerComponentType); Response response; if (actionResult.isRight()) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java index 53bac884f0..f2c4286c01 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java @@ -25,11 +25,18 @@ import com.google.gson.GsonBuilder; import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; +import javax.inject.Inject; import org.openecomp.sdc.be.components.impl.AttributeBusinessLogic; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.datastructure.Wrapper; import org.openecomp.sdc.common.log.wrappers.Logger; @@ -56,6 +63,14 @@ import javax.ws.rs.core.Response; public class AttributeServlet extends AbstractValidationsServlet { private static final Logger log = Logger.getLogger(AttributeServlet.class); + @Inject + public AttributeServlet(UserBusinessLogic userBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); + } + /** * Creates new Attribute on a resource with given resource ID * diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AutomatedUpgradeEndpoint.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AutomatedUpgradeEndpoint.java index 77be190424..9f12b51b17 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AutomatedUpgradeEndpoint.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AutomatedUpgradeEndpoint.java @@ -22,12 +22,17 @@ package org.openecomp.sdc.be.servlets; import com.jcabi.aspects.Loggable; import io.swagger.annotations.*; +import javax.inject.Inject; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.upgrade.UpgradeBusinessLogic; import org.openecomp.sdc.be.components.upgrade.UpgradeRequest; import org.openecomp.sdc.be.components.upgrade.UpgradeStatus; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.jsongraph.utils.JsonParserUtils; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.springframework.stereotype.Controller; @@ -50,11 +55,14 @@ public class AutomatedUpgradeEndpoint extends BeGenericServlet { private final UpgradeBusinessLogic businessLogic; - public AutomatedUpgradeEndpoint(UpgradeBusinessLogic businessLogic) { + @Inject + public AutomatedUpgradeEndpoint(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, + UpgradeBusinessLogic businessLogic) { + super(userBusinessLogic, componentsUtils); this.businessLogic = businessLogic; } - - + @POST @Path("/{componentType}/{componentId}/automatedupgrade") @Consumes(MediaType.APPLICATION_JSON) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java index 8e7d406bea..f7bb744a98 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java @@ -45,33 +45,14 @@ import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; -import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic; import org.openecomp.sdc.be.components.impl.BaseBusinessLogic; -import org.openecomp.sdc.be.components.impl.CapabilitiesBusinessLogic; -import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic; -import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; -import org.openecomp.sdc.be.components.impl.ElementBusinessLogic; -import org.openecomp.sdc.be.components.impl.GenericArtifactBrowserBusinessLogic; -import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.impl.InputsBusinessLogic; -import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic; -import org.openecomp.sdc.be.components.impl.MonitoringBusinessLogic; import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic; -import org.openecomp.sdc.be.components.impl.ProductBusinessLogic; -import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic; -import org.openecomp.sdc.be.components.impl.RelationshipTypeBusinessLogic; -import org.openecomp.sdc.be.components.impl.RequirementBusinessLogic; -import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic; -import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic; -import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; -import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic; -import org.openecomp.sdc.be.components.upgrade.UpgradeBusinessLogic; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.DeclarationTypeEnum; import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition; -import org.openecomp.sdc.be.ecomp.converters.AssetMetadataConverter; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.model.ComponentInstInputsMap; @@ -92,6 +73,12 @@ import org.springframework.web.context.WebApplicationContext; public class BeGenericServlet extends BasicServlet { + public BeGenericServlet(UserBusinessLogic userAdminManager, + ComponentsUtils componentsUtils) { + this.userAdminManager = userAdminManager; + this.componentsUtils = componentsUtils; + } + @Context protected HttpServletRequest servletRequest; @@ -99,6 +86,9 @@ public class BeGenericServlet extends BasicServlet { private static final String PROPERTY_NAME_REGEX = "[\\w,\\d,_]+"; + private UserBusinessLogic userAdminManager; + protected ComponentsUtils componentsUtils; + /******************** New error response mechanism * @param requestErrorWrapper **************/ @@ -146,7 +136,7 @@ public class BeGenericServlet extends BasicServlet { /*******************************************************************************************************/ protected Either getUser(final HttpServletRequest request, String userId) { - Either eitherCreator = getUserAdminManager(request.getSession().getServletContext()).getUser(userId, false); + Either eitherCreator = userAdminManager.getUser(userId, false); if (eitherCreator.isRight()) { log.info("createResource method - user is not listed. userId= {}", userId); ResponseFormat errorResponse = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_INFORMATION); @@ -159,92 +149,14 @@ public class BeGenericServlet extends BasicServlet { } - UserBusinessLogic getUserAdminManager(ServletContext context) { - return getClassFromWebAppContext(context, () -> UserBusinessLogic.class); - } - - protected GenericArtifactBrowserBusinessLogic getGenericArtifactBrowserBL(ServletContext context) { - return getClassFromWebAppContext(context, () -> GenericArtifactBrowserBusinessLogic.class); - } - - protected ResourceBusinessLogic getResourceBL(ServletContext context) { - return getClassFromWebAppContext(context, () -> ResourceBusinessLogic.class); - } - - protected InterfaceOperationBusinessLogic getInterfaceOperationBL(ServletContext context) { - return getClassFromWebAppContext(context, () -> InterfaceOperationBusinessLogic.class); - } - - protected CapabilitiesBusinessLogic getCapabilitiesBL(ServletContext context) { - return getClassFromWebAppContext(context, () -> CapabilitiesBusinessLogic.class); - } - - protected RelationshipTypeBusinessLogic getRelationshipTypeBL(ServletContext context) { - return getClassFromWebAppContext(context, () -> RelationshipTypeBusinessLogic.class); - } - protected RequirementBusinessLogic getRequirementBL(ServletContext context) { - return getClassFromWebAppContext(context, () -> RequirementBusinessLogic.class); - } - ComponentsCleanBusinessLogic getComponentCleanerBL(ServletContext context) { - return getClassFromWebAppContext(context, () -> ComponentsCleanBusinessLogic.class); - } - - protected ServiceBusinessLogic getServiceBL(ServletContext context) { - return getClassFromWebAppContext(context, () -> ServiceBusinessLogic.class); - } - - ProductBusinessLogic getProductBL(ServletContext context) { - return getClassFromWebAppContext(context, () -> ProductBusinessLogic.class); - } - - protected ArtifactsBusinessLogic getArtifactBL(ServletContext context) { - return getClassFromWebAppContext(context, () -> ArtifactsBusinessLogic.class); - } - protected UpgradeBusinessLogic getUpgradeBL(ServletContext context) { - return getClassFromWebAppContext(context, () -> UpgradeBusinessLogic.class); - } - - protected ElementBusinessLogic getElementBL(ServletContext context) { - return getClassFromWebAppContext(context, () -> ElementBusinessLogic.class); - } - - MonitoringBusinessLogic getMonitoringBL(ServletContext context) { - return getClassFromWebAppContext(context, () -> MonitoringBusinessLogic.class); - } - - protected AssetMetadataConverter getAssetUtils(ServletContext context) { - return getClassFromWebAppContext(context, () -> AssetMetadataConverter.class); - } - - protected LifecycleBusinessLogic getLifecycleBL(ServletContext context) { - return getClassFromWebAppContext(context, () -> LifecycleBusinessLogic.class); - } - T getClassFromWebAppContext(ServletContext context, Supplier> businessLogicClassGen) { WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); return webApplicationContext.getBean(businessLogicClassGen.get()); } - GroupBusinessLogic getGroupBL(ServletContext context) { - - WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); - WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); - return webApplicationContext.getBean(GroupBusinessLogic.class); - } - - protected ComponentInstanceBusinessLogic getComponentInstanceBL(ServletContext context) { - WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); - WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); - return webApplicationContext.getBean(ComponentInstanceBusinessLogic.class); - } - protected ComponentsUtils getComponentsUtils() { - ServletContext context = this.servletRequest.getSession().getServletContext(); - - WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); - WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); - return webApplicationContext.getBean(ComponentsUtils.class); + return componentsUtils; } /** @@ -267,30 +179,6 @@ public class BeGenericServlet extends BasicServlet { return new StringBuilder().append("attachment; filename=\"").append(artifactFileName).append("\"").toString(); } - - - protected ComponentBusinessLogic getComponentBL(ComponentTypeEnum componentTypeEnum, ServletContext context) { - ComponentBusinessLogic businessLogic; - switch (componentTypeEnum) { - case RESOURCE: - businessLogic = getResourceBL(context); - break; - case SERVICE: - businessLogic = getServiceBL(context); - break; - case PRODUCT: - businessLogic = getProductBL(context); - break; - case RESOURCE_INSTANCE: - businessLogic = getResourceBL(context); - break; - default: - BeEcompErrorManager.getInstance().logBeSystemError("getComponentBL"); - throw new IllegalArgumentException("Illegal component type:" + componentTypeEnum.getValue()); - } - return businessLogic; - } - void convertJsonToObjectOfClass(String json, Wrapper policyWrapper, Class clazz, Wrapper errorWrapper) { T object = null; ObjectMapper mapper = new ObjectMapper() @@ -472,13 +360,6 @@ public class BeGenericServlet extends BasicServlet { } - protected PropertyBusinessLogic getPropertyBL(ServletContext context) { - WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); - WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); - PropertyBusinessLogic propertytBl = webApplicationContext.getBean(PropertyBusinessLogic.class); - return propertytBl; - } - protected InputsBusinessLogic getInputBL(ServletContext context) { WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeMonitoringServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeMonitoringServlet.java index 42dc7b3c18..3750f20c45 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeMonitoringServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeMonitoringServlet.java @@ -28,19 +28,23 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import javax.inject.Inject; import org.apache.commons.lang3.tuple.Pair; import org.openecomp.sdc.be.components.health.HealthCheckBusinessLogic; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.impl.MonitoringBusinessLogic; 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.impl.ComponentsUtils; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.api.HealthCheckInfo; import org.openecomp.sdc.common.api.HealthCheckWrapper; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.common.monitoring.MonitoringEvent; import org.openecomp.sdc.exception.ResponseFormat; -import org.springframework.web.context.WebApplicationContext; +import org.springframework.beans.factory.annotation.Autowired; import javax.inject.Singleton; import javax.servlet.ServletContext; @@ -60,6 +64,18 @@ public class BeMonitoringServlet extends BeGenericServlet { Gson prettyGson = new GsonBuilder().setPrettyPrinting().create(); private static final Logger log = Logger.getLogger(ConfigServlet.class); + private final HealthCheckBusinessLogic healthCheckBusinessLogic; + private final MonitoringBusinessLogic monitoringBusinessLogic; + + @Inject + public BeMonitoringServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, + HealthCheckBusinessLogic healthCheckBusinessLogic, + MonitoringBusinessLogic monitoringBusinessLogic) { + super(userBusinessLogic, componentsUtils); + this.healthCheckBusinessLogic = healthCheckBusinessLogic; + this.monitoringBusinessLogic = monitoringBusinessLogic; + } @GET @Path("/healthCheck") @@ -69,7 +85,6 @@ public class BeMonitoringServlet extends BeGenericServlet { @ApiResponses(value = { @ApiResponse(code = 200, message = "SDC BE components are all up"), @ApiResponse(code = 500, message = "One or more SDC BE components are down") }) public Response getHealthCheck(@Context final HttpServletRequest request) { try { - HealthCheckBusinessLogic healthCheckBusinessLogic = getHealthCheckBL(request.getSession().getServletContext()); Pair> beHealthCheckInfosStatus = healthCheckBusinessLogic.getBeHealthCheckInfosStatus(); Boolean aggregateStatus = beHealthCheckInfosStatus.getLeft(); ActionStatus status = aggregateStatus ? ActionStatus.OK : ActionStatus.GENERAL_ERROR; @@ -103,9 +118,7 @@ public class BeMonitoringServlet extends BeGenericServlet { return buildErrorResponse(getComponentsUtils().getResponseFormatAdditionalProperty(ActionStatus.GENERAL_ERROR)); } log.trace("Received monitoring metrics: {}", monitoringEvent); - ServletContext context = request.getSession().getServletContext(); - MonitoringBusinessLogic bl = getMonitoringBL(context); - Either result = bl.logMonitoringEvent(monitoringEvent); + Either result = monitoringBusinessLogic.logMonitoringEvent(monitoringEvent); if (result.isRight()) { return buildErrorResponse(result.right().value()); } @@ -166,10 +179,4 @@ public class BeMonitoringServlet extends BeGenericServlet { return object; } - private HealthCheckBusinessLogic getHealthCheckBL(ServletContext context) { - WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); - WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); - return webApplicationContext.getBean(HealthCheckBusinessLogic.class); - } - } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CapabilityServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CapabilityServlet.java index a1456bb65d..eacfbc774b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CapabilityServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CapabilityServlet.java @@ -23,14 +23,21 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import javax.inject.Inject; import org.openecomp.sdc.be.components.impl.CapabilitiesBusinessLogic; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.CapabilityDefinition; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; @@ -52,6 +59,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; import java.util.Optional; +import org.springframework.beans.factory.annotation.Autowired; @Loggable(prepend = true, value = Loggable.DEBUG, trim = false) @Path("/v1/catalog") @@ -61,6 +69,18 @@ import java.util.Optional; @Singleton public class CapabilityServlet extends AbstractValidationsServlet { private static final Logger LOGGER = Logger.getLogger(CapabilityServlet.class); + private final CapabilitiesBusinessLogic capabilitiesBusinessLogic; + + @Inject + public CapabilityServlet(UserBusinessLogic userBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager, + CapabilitiesBusinessLogic capabilitiesBusinessLogic) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); + this.capabilitiesBusinessLogic = capabilitiesBusinessLogic; + } + @POST @Consumes(MediaType.APPLICATION_JSON) @@ -211,7 +231,6 @@ public class CapabilityServlet extends AbstractValidationsServlet { String userId, boolean isUpdate, String errorContext) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); User modifier = new User(); @@ -219,7 +238,6 @@ public class CapabilityServlet extends AbstractValidationsServlet { LOGGER.debug("Start create or update request of {} with modifier id {}", url, userId); try { String componentIdLower = componentId.toLowerCase(); - CapabilitiesBusinessLogic businessLogic = getCapabilitiesBL(context); Either, ResponseFormat> mappedCapabilitiesDataEither = getMappedCapabilitiesData(data, modifier, ComponentTypeEnum.findByParamName(componentType)); @@ -230,10 +248,10 @@ public class CapabilityServlet extends AbstractValidationsServlet { List mappedCapabilitiesData = mappedCapabilitiesDataEither.left().value(); Either, ResponseFormat> actionResponse; if(isUpdate) { - actionResponse = businessLogic.updateCapabilities(componentIdLower, + actionResponse = capabilitiesBusinessLogic.updateCapabilities(componentIdLower, mappedCapabilitiesData, modifier, errorContext, true); } else { - actionResponse = businessLogic.createCapabilities(componentIdLower, + actionResponse = capabilitiesBusinessLogic.createCapabilities(componentIdLower, mappedCapabilitiesData, modifier, errorContext, true); } if (actionResponse.isRight()) { @@ -251,7 +269,6 @@ public class CapabilityServlet extends AbstractValidationsServlet { private Response get (String capabilityIdToGet, String componentId, HttpServletRequest request, String userId){ - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); User modifier = new User(); @@ -260,9 +277,8 @@ public class CapabilityServlet extends AbstractValidationsServlet { try { String componentIdLower = componentId.toLowerCase(); - CapabilitiesBusinessLogic businessLogic = getCapabilitiesBL(context); - Either actionResponse = businessLogic + Either actionResponse = capabilitiesBusinessLogic .getCapability(componentIdLower, capabilityIdToGet, modifier, true); if (actionResponse.isRight()) { LOGGER.error("failed to get capability"); @@ -280,7 +296,6 @@ public class CapabilityServlet extends AbstractValidationsServlet { private Response delete (String capabilityId, String componentId, HttpServletRequest request, String userId){ - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); User modifier = new User(); @@ -289,9 +304,8 @@ public class CapabilityServlet extends AbstractValidationsServlet { try { String componentIdLower = componentId.toLowerCase(); - CapabilitiesBusinessLogic businessLogic = getCapabilitiesBL(context); - Either actionResponse = businessLogic + Either actionResponse = capabilitiesBusinessLogic .deleteCapability(componentIdLower, capabilityId, modifier, true); if (actionResponse.isRight()) { LOGGER.error("failed to delete capability"); 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 45d1c5f589..638e929c97 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 @@ -27,10 +27,12 @@ import com.google.gson.reflect.TypeToken; import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; +import javax.inject.Inject; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic; import org.openecomp.sdc.be.components.impl.utils.DirectivesUtils; import org.openecomp.sdc.be.config.BeEcompErrorManager; @@ -39,10 +41,13 @@ import org.openecomp.sdc.be.datamodel.ForwardingPaths; import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.info.CreateAndAssotiateInfo; import org.openecomp.sdc.be.info.GroupDefinitionInfo; import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.datastructure.Wrapper; import org.openecomp.sdc.common.log.wrappers.Logger; @@ -87,6 +92,22 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { private static final Logger log = Logger.getLogger(ComponentInstanceServlet.class); private static final Type PROPERTY_CONSTRAINT_TYPE = new TypeToken() {}.getType(); private static final Gson gsonDeserializer = new GsonBuilder().registerTypeAdapter(PROPERTY_CONSTRAINT_TYPE, new PropertyConstraintDeserialiser()).create(); + private final GroupBusinessLogic groupBL; + private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic; + private final ServiceBusinessLogic serviceBusinessLogic; + + + @Inject + public ComponentInstanceServlet(UserBusinessLogic userBusinessLogic, + GroupBusinessLogic groupBL, ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager, + ServiceBusinessLogic serviceBusinessLogic) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); + this.groupBL = groupBL; + this.componentInstanceBusinessLogic = componentInstanceBL; + this.serviceBusinessLogic = serviceBusinessLogic; + } @POST @Path("/{containerComponentType}/{componentId}/resourceInstance") @@ -105,12 +126,11 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { ComponentInstance componentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class); componentInstance.setInvariantName(null); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } - Either actionResponse = componentInstanceLogic.createComponentInstance(containerComponentType, containerComponentId, userId, componentInstance); + Either actionResponse = componentInstanceBusinessLogic.createComponentInstance(containerComponentType, containerComponentId, userId, componentInstance); if (actionResponse.isRight()) { return buildErrorResponse(actionResponse.right().value()); @@ -134,7 +154,6 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { @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, @Context final HttpServletRequest request) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); @@ -155,8 +174,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { String data = new String(bytes); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } @@ -169,7 +187,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { } ComponentInstance resourceInstance = convertResponse.left().value(); - Either actionResponse = componentInstanceLogic.updateComponentInstanceMetadata(containerComponentType, componentId, componentInstanceId, userId, resourceInstance); + Either actionResponse = componentInstanceBusinessLogic.updateComponentInstanceMetadata(containerComponentType, componentId, componentInstanceId, userId, resourceInstance); if (actionResponse.isRight()) { return buildErrorResponse(actionResponse.right().value()); @@ -178,8 +196,6 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { if (componentTypeEnum.equals(ComponentTypeEnum.SERVICE)){ boolean shouldCreateServiceFilter = resourceInstance.getDirectives() != null && resourceInstance.getDirectives().contains( DirectivesUtils.SELECTABLE); - ServiceBusinessLogic - serviceBusinessLogic = (ServiceBusinessLogic) getComponentBL(componentTypeEnum, context); if(shouldCreateServiceFilter) { Either either = @@ -238,8 +254,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { String userId = request.getHeader(Constants.USER_ID_HEADER); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } @@ -255,7 +270,8 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { List componentInstanceList = convertResponse.left().value(); - Either, ResponseFormat> actionResponse = componentInstanceLogic.updateComponentInstance(containerComponentType, componentId, userId, componentInstanceList, true); + Either, ResponseFormat> actionResponse = componentInstanceBusinessLogic + .updateComponentInstance(containerComponentType, componentId, userId, componentInstanceList, true); if (actionResponse.isRight()) { return buildErrorResponse(actionResponse.right().value()); @@ -287,13 +303,12 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { try { log.debug(START_HANDLE_REQUEST_OF, url); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } String userId = request.getHeader(Constants.USER_ID_HEADER); - Either actionResponse = componentInstanceLogic.deleteComponentInstance(containerComponentType, componentId, resourceInstanceId, userId); + Either actionResponse = componentInstanceBusinessLogic.deleteComponentInstance(containerComponentType, componentId, resourceInstanceId, userId); if (actionResponse.isRight()) { response = buildErrorResponse(actionResponse.right().value()); @@ -320,7 +335,6 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { @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, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "RelationshipInfo", required = true) String data, @Context final HttpServletRequest request) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); @@ -331,8 +345,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { log.debug(START_HANDLE_REQUEST_OF, url); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } @@ -347,7 +360,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { } else { RequirementCapabilityRelDef requirementDef = regInfoW.left().value(); requirementDef.setOriginUI(true); - resultOp = componentInstanceLogic.associateRIToRI(componentId, userId, requirementDef, componentTypeEnum); + resultOp = componentInstanceBusinessLogic.associateRIToRI(componentId, userId, requirementDef, componentTypeEnum); } Either actionResponse = resultOp; @@ -387,8 +400,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { log.debug(START_HANDLE_REQUEST_OF, url); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } @@ -401,7 +413,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { } RequirementCapabilityRelDef requirementDef = regInfoW.left().value(); - Either actionResponse = componentInstanceLogic.dissociateRIFromRI(componentId, userId, requirementDef, componentTypeEnum); + Either actionResponse = componentInstanceBusinessLogic.dissociateRIFromRI(componentId, userId, requirementDef, componentTypeEnum); if (actionResponse.isRight()) { return buildErrorResponse(actionResponse.right().value()); @@ -447,8 +459,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { String data = new String(bytes); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } @@ -464,7 +475,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { CreateAndAssotiateInfo createAndAssotiateInfo = convertStatus.left().value(); RequirementCapabilityRelDef requirementDef = createAndAssotiateInfo.getAssociate(); requirementDef.setOriginUI(true); - Either actionResponse = componentInstanceLogic.createAndAssociateRIToRI(containerComponentType, componentId, userId, createAndAssotiateInfo); + Either actionResponse = componentInstanceBusinessLogic.createAndAssociateRIToRI(containerComponentType, componentId, userId, createAndAssotiateInfo); if (actionResponse.isRight()) { return buildErrorResponse(actionResponse.right().value()); @@ -512,13 +523,13 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { ServletContext context = request.getSession().getServletContext(); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } - Either, ResponseFormat> actionResponse = componentInstanceLogic.createOrUpdatePropertiesValues(componentTypeEnum, componentId, componentInstanceId, propertiesToUpdate, userId); + Either, ResponseFormat> actionResponse = + componentInstanceBusinessLogic.createOrUpdatePropertiesValues(componentTypeEnum, componentId, componentInstanceId, propertiesToUpdate, userId); if (actionResponse.isRight()) { return buildErrorResponse(actionResponse.right().value()); @@ -570,14 +581,13 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { ServletContext context = request.getSession().getServletContext(); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } Either, ResponseFormat> actionResponse = - componentInstanceLogic.createOrUpdateInstanceInputValues(componentTypeEnum, componentId, componentInstanceId, inputsToUpdate, userId); + componentInstanceBusinessLogic.createOrUpdateInstanceInputValues(componentTypeEnum, componentId, componentInstanceId, inputsToUpdate, userId); if (actionResponse.isRight()) { return buildErrorResponse(actionResponse.right().value()); @@ -668,20 +678,17 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { @ApiParam(value = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId, @ApiParam(value = "property id") @PathParam("propertyId") final String propertyId, @ApiParam(value = "id of user initiating the operation") @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) { - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); try { ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } - Either actionResponse = componentInstanceLogic.deletePropertyValue(componentTypeEnum, componentId, componentInstanceId, propertyId, userId); + Either actionResponse = componentInstanceBusinessLogic.deletePropertyValue(componentTypeEnum, componentId, componentInstanceId, propertyId, userId); if (actionResponse.isRight()) { return buildErrorResponse(actionResponse.right().value()); } @@ -720,8 +727,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { String data = new String(bytes); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } @@ -735,7 +741,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { } ComponentInstance newResourceInstance = convertResponse.left().value(); - Either actionResponse = componentInstanceLogic.changeComponentInstanceVersion(containerComponentType, componentId, componentInstanceId, userId, newResourceInstance); + Either actionResponse = componentInstanceBusinessLogic.changeComponentInstanceVersion(containerComponentType, componentId, componentInstanceId, userId, newResourceInstance); if (actionResponse.isRight()) { return buildErrorResponse(actionResponse.right().value()); @@ -786,13 +792,12 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { ServletContext context = request.getSession().getServletContext(); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } - Either actionResponse = componentInstanceLogic.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, componentInstanceId, groupInstanceId, property, userId); + Either actionResponse = componentInstanceBusinessLogic.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, componentInstanceId, groupInstanceId, property, userId); if (actionResponse.isRight()) { return buildErrorResponse(actionResponse.right().value()); @@ -818,15 +823,15 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { @ApiResponses(value = { @ApiResponse(code = 200, message = "group found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Group not found") }) public Response getGroupArtifactById(@PathParam("containerComponentType") final String containerComponentType, @PathParam("componentId") final String componentId, @PathParam("componentInstanceId") final String componentInstanceId, @PathParam("groupInstId") final String groupInstId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug(GET_START_HANDLE_REQUEST_OF, url); try { - GroupBusinessLogic businessLogic = this.getGroupBL(context); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - Either actionResponse = businessLogic.getGroupInstWithArtifactsById(componentTypeEnum, componentId, componentInstanceId, groupInstId, userId, false); + Either actionResponse = groupBL + .getGroupInstWithArtifactsById(componentTypeEnum, componentId, componentInstanceId, + groupInstId, userId, false); if (actionResponse.isRight()) { log.debug("failed to get all non abstract {}", containerComponentType); @@ -859,9 +864,8 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { try { ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceBL = getComponentInstanceBL(context); - Either, ResponseFormat> componentInstancePropertiesById = componentInstanceBL.getComponentInstancePropertiesById(containerComponentType, containerComponentId, componentInstanceUniqueId, userId); + Either, ResponseFormat> componentInstancePropertiesById = componentInstanceBusinessLogic.getComponentInstancePropertiesById(containerComponentType, containerComponentId, componentInstanceUniqueId, userId); if (componentInstancePropertiesById.isRight()) { log.debug(FAILED_TO_GET_PROPERTIES_OF_COMPONENT_INSTANCE_ID_IN_WITH_ID, componentInstanceUniqueId, containerComponentType, containerComponentId); @@ -894,9 +898,8 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { try { ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceBL = getComponentInstanceBL(context); - Either, ResponseFormat> componentInstancePropertiesById = componentInstanceBL.getComponentInstanceCapabilityPropertiesById(containerComponentType, containerComponentId, componentInstanceUniqueId, + Either, ResponseFormat> componentInstancePropertiesById = componentInstanceBusinessLogic.getComponentInstanceCapabilityPropertiesById(containerComponentType, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, ownerId, userId); if (componentInstancePropertiesById.isRight()) { @@ -944,9 +947,8 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { } ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceBL = getComponentInstanceBL(context); - Either, ResponseFormat> updateCICapProperty = componentInstanceBL.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, propertiesToUpdate, userId); + Either, ResponseFormat> updateCICapProperty = componentInstanceBusinessLogic.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, propertiesToUpdate, userId); if (updateCICapProperty.isRight()) { log.debug(FAILED_TO_GET_PROPERTIES_OF_COMPONENT_INSTANCE_ID_IN_WITH_ID, componentInstanceUniqueId, containerComponentType, containerComponentId); @@ -982,12 +984,11 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { log.debug("Unsupported container component type {}", containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } - Either actionResponse = componentInstanceLogic.createServiceProxy(); + Either actionResponse = componentInstanceBusinessLogic.createServiceProxy(); if (actionResponse.isRight()) { return buildErrorResponse(actionResponse.right().value()); @@ -1017,13 +1018,12 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { try { log.debug(START_HANDLE_REQUEST_OF, url); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } String userId = request.getHeader(Constants.USER_ID_HEADER); - Either actionResponse = componentInstanceLogic.deleteServiceProxy(); + Either actionResponse = componentInstanceBusinessLogic.deleteServiceProxy(); if (actionResponse.isRight()) { response = buildErrorResponse(actionResponse.right().value()); @@ -1056,12 +1056,11 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { String userId = request.getHeader(Constants.USER_ID_HEADER); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } - Either actionResponse = componentInstanceLogic.changeServiceProxyVersion(); + Either actionResponse = componentInstanceBusinessLogic.changeServiceProxyVersion(); if (actionResponse.isRight()) { return buildErrorResponse(actionResponse.right().value()); @@ -1102,9 +1101,8 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - Either actionResponse = componentInstanceLogic.getRelationById(componentId, relationId, userId, componentTypeEnum); + Either actionResponse = componentInstanceBusinessLogic.getRelationById(componentId, relationId, userId, componentTypeEnum); if (actionResponse.isRight()) { return buildErrorResponse(actionResponse.right().value()); } @@ -1213,8 +1211,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } @@ -1226,7 +1223,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { log.error("missing component id"); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_DATA)); } - Either,ResponseFormat> actionResponse= componentInstanceLogic.forwardingPathOnVersionChange( + Either,ResponseFormat> actionResponse= componentInstanceBusinessLogic.forwardingPathOnVersionChange( containerComponentType,componentId,oldComponentInstanceId,newComponentInstance); if (actionResponse.isRight()) { return buildErrorResponse(actionResponse.right().value()); @@ -1259,12 +1256,11 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { ComponentInstance inputComponentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class); inputComponentInstance.setInvariantName(null); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(CNTAINER_CMPT_TYPE); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug(UNSUPPORTED_COMPONENT_TYPE, componentTypeEnum); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, "services")); } - Either, ResponseFormat> copyComponentInstance = componentInstanceLogic.copyComponentInstance( + Either, ResponseFormat> copyComponentInstance = componentInstanceBusinessLogic.copyComponentInstance( inputComponentInstance, containerComponentId, componentInstanceId, userId); if (copyComponentInstance.isRight()) { @@ -1298,7 +1294,6 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { @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); @@ -1306,8 +1301,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { } - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.error("Unsupported component type {}", containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } @@ -1323,7 +1317,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { String userId = request.getHeader(Constants.USER_ID_HEADER); List componentInstanceIdList = convertResponse.left().value(); log.debug("batchDeleteResourceInstances componentInstanceIdList is {}", componentInstanceIdList); - Map> deleteErrorMap = componentInstanceLogic.batchDeleteComponentInstance(containerComponentType, + Map> deleteErrorMap = componentInstanceBusinessLogic.batchDeleteComponentInstance(containerComponentType, componentId, componentInstanceIdList, userId); return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), deleteErrorMap); @@ -1353,7 +1347,6 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { @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) { @@ -1362,9 +1355,8 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { } ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context); - if (componentInstanceLogic == null) { + if (componentInstanceBusinessLogic == null) { log.debug("Unsupported component type {}", containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); } @@ -1378,7 +1370,7 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { } List requirementDefList = regInfoWs.left().value(); - List delOkResult = componentInstanceLogic.batchDissociateRIFromRI( + List delOkResult = componentInstanceBusinessLogic.batchDissociateRIFromRI( componentId, userId, requirementDefList, componentTypeEnum); return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), delOkResult); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java index 037bd95190..688863784c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java @@ -25,6 +25,7 @@ import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import java.util.List; import java.util.Map; +import javax.inject.Inject; import javax.inject.Singleton; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; @@ -40,14 +41,18 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; 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.datamodel.utils.PropertyValueConstraintValidationUtil; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache; import org.openecomp.sdc.be.resources.data.EntryData; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.exception.ResponseFormat; import org.slf4j.Logger; @@ -60,8 +65,18 @@ import org.springframework.beans.factory.annotation.Autowired; @Singleton public class ComponentPropertyServlet extends BeGenericServlet { - @Autowired - ApplicationDataTypeCache applicationDataTypeCache; + private final PropertyBusinessLogic propertyBusinessLogic; + private final ApplicationDataTypeCache applicationDataTypeCache; + + @Inject + public ComponentPropertyServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, + ApplicationDataTypeCache applicationDataTypeCache, + PropertyBusinessLogic propertyBusinessLogic) { + super(userBusinessLogic, componentsUtils); + this.applicationDataTypeCache = applicationDataTypeCache; + this.propertyBusinessLogic = propertyBusinessLogic; + } private static final Logger log = LoggerFactory.getLogger(ComponentPropertyServlet.class); private static final String CREATE_PROPERTY = "Create Property"; @@ -207,13 +222,10 @@ public class ComponentPropertyServlet extends BeGenericServlet { } private Response createProperty(String componentId, String data, HttpServletRequest request,String userId) { - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {} modifier id is {} data is {}", url, userId, data); try{ - PropertyBusinessLogic propertyBL = getPropertyBL(context); Either, ActionStatus> propertyDefinition = getPropertyModel(componentId, data); if (propertyDefinition.isRight()) { @@ -234,7 +246,7 @@ public class ComponentPropertyServlet extends BeGenericServlet { String propertyName = newPropertyDefinition.getName(); Either, ResponseFormat> addPropertyEither = - propertyBL.addPropertyToComponent(componentId, propertyName, newPropertyDefinition, userId); + propertyBusinessLogic.addPropertyToComponent(componentId, propertyName, newPropertyDefinition, userId); if(addPropertyEither.isRight()) { return buildErrorResponse(addPropertyEither.right().value()); @@ -253,8 +265,6 @@ public class ComponentPropertyServlet extends BeGenericServlet { private Response updateProperty(String componentId, String data, HttpServletRequest request, String userId) { - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -293,10 +303,9 @@ public class ComponentPropertyServlet extends BeGenericServlet { // update property - PropertyBusinessLogic businessLogic = getPropertyBL(context); for(PropertyDefinition propertyDefinition : properties.values()) { Either, ResponseFormat> status = - businessLogic.updateComponentProperty( + propertyBusinessLogic.updateComponentProperty( componentId, propertyDefinition.getUniqueId(), propertyDefinition, userId); if (status.isRight()) { log.info("Failed to update Property. Reason - ", status.right().value()); @@ -322,15 +331,12 @@ public class ComponentPropertyServlet extends BeGenericServlet { } private Response getProperty(String componentId, String propertyId, HttpServletRequest request, String userId) { - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug(DEBUG_MESSAGE, url, userId); try { - PropertyBusinessLogic propertyBL = getPropertyBL(context); Either, ResponseFormat> retrievedPropertyEither = - propertyBL.getComponentProperty(componentId, propertyId, userId); + propertyBusinessLogic.getComponentProperty(componentId, propertyId, userId); if(retrievedPropertyEither.isRight()) { return buildErrorResponse(retrievedPropertyEither.right().value()); @@ -347,15 +353,13 @@ public class ComponentPropertyServlet extends BeGenericServlet { } } private Response getPropertyList(String componentId, HttpServletRequest request, String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug(DEBUG_MESSAGE, url, userId); try { - PropertyBusinessLogic propertyBL = getPropertyBL(context); Either, ResponseFormat> propertiesListEither = - propertyBL.getPropertiesList(componentId, userId); + propertyBusinessLogic.getPropertiesList(componentId, userId); if(propertiesListEither.isRight()) { return buildErrorResponse(propertiesListEither.right().value()); @@ -372,17 +376,14 @@ public class ComponentPropertyServlet extends BeGenericServlet { } } private Response deleteProperty(String componentId, String propertyId, HttpServletRequest request, String userId) { - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug(DEBUG_MESSAGE, url, userId); try { // delete the property - PropertyBusinessLogic businessLogic = getPropertyBL(context); Either, ResponseFormat> status = - businessLogic.deletePropertyFromComponent(componentId, propertyId, userId); + propertyBusinessLogic.deletePropertyFromComponent(componentId, propertyId, userId); if (status.isRight()) { log.debug("Failed to delete Property. Reason - ", status.right().value()); return buildErrorResponse(status.right().value()); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java index f9297c4db2..574359ee4c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java @@ -23,22 +23,28 @@ package org.openecomp.sdc.be.servlets; import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; +import javax.inject.Inject; import org.apache.commons.collections.CollectionUtils; import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic; import org.openecomp.sdc.be.components.impl.ComponentBusinessLogicProvider; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.FilterKeyEnum; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.mixin.GroupCompositionMixin; import org.openecomp.sdc.be.mixin.PolicyCompositionMixin; import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.be.view.ResponseView; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import javax.servlet.ServletContext; @@ -69,7 +75,11 @@ public class ComponentServlet extends BeGenericServlet { private final ComponentBusinessLogicProvider componentBusinessLogicProvider; - public ComponentServlet(ComponentBusinessLogicProvider componentBusinessLogicProvider) { + @Inject + public ComponentServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, + ComponentBusinessLogicProvider componentBusinessLogicProvider) { + super(userBusinessLogic, componentsUtils); this.componentBusinessLogicProvider = componentBusinessLogicProvider; } @@ -82,14 +92,13 @@ public class ComponentServlet extends BeGenericServlet { public Response conformanceLevelValidation(@PathParam("componentType") final String componentType, @PathParam("componentUuid") final String componentUuid, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { Response response; - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType); if (componentTypeEnum != null) { - ComponentBusinessLogic compBL = getComponentBL(componentTypeEnum, context); + ComponentBusinessLogic compBL = componentBusinessLogicProvider.getInstance(componentTypeEnum); Either eitherConformanceLevel = compBL.validateConformanceLevel(componentUuid, componentTypeEnum, userId); if (eitherConformanceLevel.isRight()) { response = buildErrorResponse(eitherConformanceLevel.right().value()); @@ -112,7 +121,6 @@ public class ComponentServlet extends BeGenericServlet { public Response getRequirementAndCapabilities(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { Response response; - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); @@ -120,7 +128,7 @@ public class ComponentServlet extends BeGenericServlet { ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType); if (componentTypeEnum != null) { try { - ComponentBusinessLogic compBL = getComponentBL(componentTypeEnum, context); + ComponentBusinessLogic compBL = componentBusinessLogicProvider.getInstance(componentTypeEnum); Either eitherRequirementsAndCapabilities = compBL.getRequirementsAndCapabilities(componentId, componentTypeEnum, userId); if (eitherRequirementsAndCapabilities.isRight()) { response = buildErrorResponse(eitherRequirementsAndCapabilities.right().value()); @@ -148,8 +156,6 @@ public class ComponentServlet extends BeGenericServlet { public Response getLatestVersionNotAbstractCheckoutComponents(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request, @QueryParam("internalComponentType") String internalComponentType, @QueryParam("componentUids") List componentUids, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug("(get) Start handle request of {}", url); Response response = null; @@ -157,7 +163,7 @@ public class ComponentServlet extends BeGenericServlet { try { ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType); - ComponentBusinessLogic businessLogic = getComponentBL(componentTypeEnum, context); + ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum); log.debug("Received componentUids size is {}", componentUids == null ? 0 : componentUids.size()); @@ -189,8 +195,6 @@ public class ComponentServlet extends BeGenericServlet { public Response getLatestVersionNotAbstractCheckoutComponentsByBody(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request, @QueryParam("internalComponentType") String internalComponentType, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "Consumer Object to be created", required = true) List data) { - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug("(GET) Start handle request of {}", url); Response response = null; @@ -198,7 +202,7 @@ public class ComponentServlet extends BeGenericServlet { try { ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType); - ComponentBusinessLogic businessLogic = getComponentBL(componentTypeEnum, context); + ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum); if (log.isDebugEnabled()) { log.debug("Received componentUids size is {}", data == null ? 0 : data.size()); } @@ -234,13 +238,12 @@ public class ComponentServlet extends BeGenericServlet { public Response getLatestVersionNotAbstractCheckoutComponentsIdesOnly(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request, @QueryParam("internalComponentType") String internalComponentType, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "uid list", required = true) String data) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("(get) Start handle request of {}", url); Response response = null; try { ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType); - ComponentBusinessLogic businessLogic = getComponentBL(componentTypeEnum, context); + ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum); Either, ResponseFormat> actionResponse = businessLogic.getLatestVersionNotAbstractComponentsMetadata(false, HighestFilterEnum.HIGHEST_ONLY, componentTypeEnum, internalComponentType, userId); if (actionResponse.isRight()) { @@ -269,13 +272,12 @@ public class ComponentServlet extends BeGenericServlet { public Response getComponentInstancesFilteredByPropertiesAndInputs(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId, @Context final HttpServletRequest request, @QueryParam("searchText") String searchText, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "uid" + " " + "list", required = true) String data) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("(GET) Start handle request of {}", url); Response response = null; try { ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType); - ComponentBusinessLogic businessLogic = getComponentBL(componentTypeEnum, context); + ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum); Either, ResponseFormat> actionResponse = businessLogic.getComponentInstancesFilteredByPropertiesAndInputs(componentId, userId); if (actionResponse.isRight()) { @@ -365,14 +367,13 @@ public class ComponentServlet extends BeGenericServlet { @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); User user = new User(); user.setUserId(userId); log.debug("User Id is {}" , userId); Response response; try { ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType); - ComponentBusinessLogic businessLogic = getComponentBL(componentTypeEnum, context); + ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum); Map> filters = new EnumMap<>(FilterKeyEnum.class); List propertyNameFragments = new ArrayList<>(); propertyNameFragments.add(propertyNameFragment); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConsumerServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConsumerServlet.java index bbc09bf435..e6553a2df1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConsumerServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConsumerServlet.java @@ -24,17 +24,21 @@ import com.google.gson.Gson; import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; +import javax.inject.Inject; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.ConsumerBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; 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.impl.ComponentsUtils; import org.openecomp.sdc.be.model.ConsumerDefinition; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; -import org.springframework.web.context.WebApplicationContext; +import org.springframework.beans.factory.annotation.Autowired; import javax.inject.Singleton; import javax.servlet.ServletContext; @@ -53,6 +57,15 @@ public class ConsumerServlet extends BeGenericServlet { private static final String MODIFIER_ID_IS = "modifier id is {}"; private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}"; private static final Logger log = Logger.getLogger(ConsumerServlet.class); + private final ConsumerBusinessLogic businessLogic; + + @Inject + public ConsumerServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, + ConsumerBusinessLogic businessLogic) { + super(userBusinessLogic, componentsUtils); + this.businessLogic = businessLogic; + } @POST @Consumes(MediaType.APPLICATION_JSON) @@ -71,8 +84,6 @@ public class ConsumerServlet extends BeGenericServlet { log.debug(MODIFIER_ID_IS, userId); try { - ConsumerBusinessLogic businessLogic = getConsumerBL(context); - Either convertionResponse = convertJsonToObject(data, modifier, AuditingActionEnum.ADD_ECOMP_USER_CREDENTIALS); if (convertionResponse.isRight()) { @@ -119,8 +130,6 @@ public class ConsumerServlet extends BeGenericServlet { Response response = null; try { - ConsumerBusinessLogic businessLogic = getConsumerBL(context); - Either actionResponse = businessLogic.getConsumer(consumerId, modifier); if (actionResponse.isRight()) { @@ -157,8 +166,6 @@ public class ConsumerServlet extends BeGenericServlet { Response response = null; try { - ConsumerBusinessLogic businessLogic = getConsumerBL(context); - Either actionResponse = businessLogic.deleteConsumer(consumerId, modifier); if (actionResponse.isRight()) { @@ -176,12 +183,6 @@ public class ConsumerServlet extends BeGenericServlet { } } - private ConsumerBusinessLogic getConsumerBL(ServletContext context) { - WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); - WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); - return webApplicationContext.getBean(ConsumerBusinessLogic.class); - } - public Either convertJsonToObject(String data, User user, AuditingActionEnum actionEnum) { ConsumerDefinition consumer; Gson gson = new Gson(); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CsarBuildServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CsarBuildServlet.java index 640f54e67d..8c5a2247f9 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CsarBuildServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CsarBuildServlet.java @@ -21,7 +21,14 @@ package org.openecomp.sdc.be.servlets; import com.jcabi.aspects.Loggable; +import javax.inject.Inject; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.DownloadArtifactLogic; +import org.openecomp.sdc.be.resources.api.IResourceUploader; import org.openecomp.sdc.be.resources.data.ESArtifactData; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.log.wrappers.Logger; import javax.servlet.http.HttpServletRequest; @@ -37,6 +44,14 @@ public class CsarBuildServlet extends ToscaDaoServlet { private static final Logger log = Logger.getLogger(CsarBuildServlet.class); + @Inject + public CsarBuildServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, + IResourceUploader resourceUploader, + DownloadArtifactLogic logic) { + super(userBusinessLogic, componentsUtils, resourceUploader, logic); + } + @GET @Path("/{serviceName}/{serviceVersion}") public Response getDefaultTemplate(@Context final HttpServletRequest request, @PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DistributionServiceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DistributionServiceServlet.java index c14eb87cc5..26ff236dec 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DistributionServiceServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DistributionServiceServlet.java @@ -26,20 +26,21 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import javax.inject.Inject; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.DistributionMonitoringBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; 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.impl.ComponentsUtils; import org.openecomp.sdc.be.info.DistributionStatusListResponse; import org.openecomp.sdc.be.info.DistributionStatusOfServiceListResponce; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; -import org.springframework.web.context.WebApplicationContext; -import javax.annotation.Resource; import javax.inject.Singleton; -import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.*; import javax.ws.rs.core.Context; @@ -56,7 +57,14 @@ import javax.ws.rs.core.Response; public class DistributionServiceServlet extends BeGenericServlet { private static final Logger log = Logger.getLogger(DistributionServiceServlet.class); - @Resource + @Inject + public DistributionServiceServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, + DistributionMonitoringBusinessLogic distributionMonitoringLogic) { + super(userBusinessLogic, componentsUtils); + this.distributionMonitoringLogic = distributionMonitoringLogic; + } + private DistributionMonitoringBusinessLogic distributionMonitoringLogic; @GET @@ -67,7 +75,6 @@ public class DistributionServiceServlet extends BeGenericServlet { @ApiResponses(value = { @ApiResponse(code = 200, message = "Service found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Service not found") }) public Response getServiceById(@PathParam("serviceUUID") final String serviceUUID, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - init(request); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); Response response = null; @@ -107,7 +114,6 @@ public class DistributionServiceServlet extends BeGenericServlet { @ApiResponses(value = { @ApiResponse(code = 200, message = "Service found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Status not found") }) public Response getListOfDistributionStatuses(@PathParam("did") final String did, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - init(request); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); Response response = null; @@ -142,16 +148,4 @@ public class DistributionServiceServlet extends BeGenericServlet { } - private void init(HttpServletRequest request) { - if (distributionMonitoringLogic == null) { - distributionMonitoringLogic = getDistributionBL(request.getSession().getServletContext()); - } - } - - private DistributionMonitoringBusinessLogic getDistributionBL(ServletContext context) { - WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); - WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); - return webApplicationContext.getBean(DistributionMonitoringBusinessLogic.class); - } - } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java index 081c9cad1a..e143203400 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java @@ -23,7 +23,10 @@ package org.openecomp.sdc.be.servlets; import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; +import javax.inject.Inject; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.ElementBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.config.ConfigurationManager; @@ -31,6 +34,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.info.ArtifactTypesInfo; import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.be.model.Tag; @@ -70,6 +74,20 @@ import java.util.Map; public class ElementServlet extends BeGenericServlet { private static final Logger log = Logger.getLogger(ElementServlet.class); + private final ComponentsCleanBusinessLogic componentsCleanBusinessLogic; + private final ElementBusinessLogic elementBusinessLogic; + private final UserBusinessLogic userBusinessLogic; + + @Inject + public ElementServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, + ComponentsCleanBusinessLogic componentsCleanBusinessLogic, + ElementBusinessLogic elementBusinessLogic) { + super(userBusinessLogic, componentsUtils); + this.componentsCleanBusinessLogic = componentsCleanBusinessLogic; + this.elementBusinessLogic = elementBusinessLogic; + this.userBusinessLogic = userBusinessLogic; + } /* ****************************************************************************** @@ -94,8 +112,7 @@ public class ElementServlet extends BeGenericServlet { + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) { try { - ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext()); - Either, ResponseFormat> either = elementBL .getAllCategories(componentType, userId); + Either, ResponseFormat> either = elementBusinessLogic.getAllCategories(componentType, userId); if (either.isRight()) { log.debug("No categories were found for type {}", componentType); return buildErrorResponse(either.right().value()); @@ -119,8 +136,8 @@ public class ElementServlet extends BeGenericServlet { public Response getAllCategories(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { try { - ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext()); - Either either = elementBL.getAllCategories(userId); + Either either = elementBusinessLogic + .getAllCategories(userId); if (either.isRight()) { log.debug("No categories were found"); return buildErrorResponse(either.right().value()); @@ -147,10 +164,10 @@ public class ElementServlet extends BeGenericServlet { + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType, @ApiParam(value = "Category to be created", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { try { - ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext()); CategoryDefinition category = RepresentationUtils.fromRepresentation(data, CategoryDefinition.class); - Either createResourceCategory = elementBL.createCategory(category, componentType, userId); + Either createResourceCategory = + elementBusinessLogic.createCategory(category, componentType, userId); if (createResourceCategory.isRight()) { return buildErrorResponse(createResourceCategory.right().value()); } @@ -177,8 +194,8 @@ public class ElementServlet extends BeGenericServlet { @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { try { - ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext()); - Either createResourceCategory = elementBL.deleteCategory(categoryUniqueId, componentType, userId); + Either createResourceCategory = + elementBusinessLogic.deleteCategory(categoryUniqueId, componentType, userId); if (createResourceCategory.isRight()) { return buildErrorResponse(createResourceCategory.right().value()); @@ -215,10 +232,10 @@ public class ElementServlet extends BeGenericServlet { @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { try { - ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext()); SubCategoryDefinition subCategory = RepresentationUtils.fromRepresentation(data, SubCategoryDefinition.class); - Either createSubcategory = elementBL.createSubCategory(subCategory, componentType, categoryId, userId); + Either createSubcategory = elementBusinessLogic + .createSubCategory(subCategory, componentType, categoryId, userId); if (createSubcategory.isRight()) { return buildErrorResponse(createSubcategory.right().value()); } @@ -244,8 +261,8 @@ public class ElementServlet extends BeGenericServlet { @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { try { - ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext()); - Either deleteSubResourceCategory = elementBL.deleteSubCategory(subCategoryUniqueId, componentType, userId); + Either deleteSubResourceCategory = + elementBusinessLogic.deleteSubCategory(subCategoryUniqueId, componentType, userId); if (deleteSubResourceCategory.isRight()) { return buildErrorResponse(deleteSubResourceCategory.right().value()); } @@ -276,10 +293,10 @@ public class ElementServlet extends BeGenericServlet { @ApiParam(value = "Parent sub-category unique ID", required = true) @PathParam(value = "subCategoryId") final String parentSubCategoryId, @ApiParam(value = "Subcategory to be created", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { try { - ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext()); GroupingDefinition grouping = RepresentationUtils.fromRepresentation(data, GroupingDefinition.class); - Either createGrouping = elementBL.createGrouping(grouping, componentType, grandParentCategoryId, parentSubCategoryId, userId); + Either createGrouping = elementBusinessLogic + .createGrouping(grouping, componentType, grandParentCategoryId, parentSubCategoryId, userId); if (createGrouping.isRight()) { return buildErrorResponse(createGrouping.right().value()); } @@ -306,8 +323,8 @@ public class ElementServlet extends BeGenericServlet { @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { try { - ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext()); - Either deleteGrouping = elementBL.deleteGrouping(groupingUniqueId, componentType, userId); + Either deleteGrouping = elementBusinessLogic + .deleteGrouping(groupingUniqueId, componentType, userId); if (deleteGrouping.isRight()) { return buildErrorResponse(deleteGrouping.right().value()); } @@ -335,8 +352,7 @@ public class ElementServlet extends BeGenericServlet { log.debug("(getTags) Start handle request of {}", url); try { - ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext()); - Either, ActionStatus> either = elementBL.getAllTags(userId); + Either, ActionStatus> either = elementBusinessLogic.getAllTags(userId); if (either.isRight() || either.left().value() == null) { log.debug("No tags were found"); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT)); @@ -363,8 +379,7 @@ public class ElementServlet extends BeGenericServlet { log.debug("(getPropertyScopes) Start handle request of {}", url); try { - ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext()); - Either, ActionStatus> either = elementBL.getAllPropertyScopes(userId); + Either, ActionStatus> either = elementBusinessLogic.getAllPropertyScopes(userId); if (either.isRight() || either.left().value() == null) { log.debug("No property scopes were found"); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT)); @@ -391,8 +406,7 @@ public class ElementServlet extends BeGenericServlet { log.debug("(GET - getArtifactTypes) Start handle request of {}", url); try { - ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext()); - Either, ActionStatus> either = elementBL.getAllArtifactTypes(userId); + Either, ActionStatus> either = elementBusinessLogic.getAllArtifactTypes(userId); if (either.isRight() || either.left().value() == null) { log.debug("No artifact types were found"); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT)); @@ -425,11 +439,10 @@ public class ElementServlet extends BeGenericServlet { log.debug("(getConfiguration) Start handle request of {}", url); try { - ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext()); - Either, ActionStatus> otherEither = elementBL.getAllArtifactTypes(userId); - Either defaultHeatTimeout = elementBL.getDefaultHeatTimeout(); - Either, ActionStatus> deploymentEither = elementBL.getAllDeploymentArtifactTypes(); - Either, ActionStatus> resourceTypesMap = elementBL.getResourceTypesMap(); + Either, ActionStatus> otherEither = elementBusinessLogic.getAllArtifactTypes(userId); + Either defaultHeatTimeout = elementBusinessLogic.getDefaultHeatTimeout(); + Either, ActionStatus> deploymentEither = elementBusinessLogic.getAllDeploymentArtifactTypes(); + Either, ActionStatus> resourceTypesMap = elementBusinessLogic.getResourceTypesMap(); if (otherEither.isRight() || otherEither.left().value() == null) { log.debug("No other artifact types were found"); @@ -451,8 +464,8 @@ public class ElementServlet extends BeGenericServlet { artifacts.put("deployment", deploymentEither.left().value()); configuration.put("artifacts", artifacts); configuration.put("defaultHeatTimeout", defaultHeatTimeout.left().value()); - configuration.put("componentTypes", elementBL.getAllComponentTypesParamNames()); - configuration.put("roles", elementBL.getAllSupportedRoles()); + configuration.put("componentTypes", elementBusinessLogic.getAllComponentTypesParamNames()); + configuration.put("roles", elementBusinessLogic.getAllSupportedRoles()); configuration.put("resourceTypes", resourceTypesMap.left().value()); configuration.put("environmentContext", ConfigurationManager.getConfigurationManager().getConfiguration().getEnvironmentContext()); configuration.put("gab", ConfigurationManager.getConfigurationManager().getConfiguration().getGabConfig()); @@ -483,10 +496,9 @@ public class ElementServlet extends BeGenericServlet { try { String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); - UserBusinessLogic userAdminManager = getUserAdminManager(request.getSession().getServletContext()); // Getting the user - Either either = userAdminManager.getUser(userId, false); + Either either = userBusinessLogic.getUser(userId, false); if (either.isRight()) { // Couldn't find or otherwise fetch the user return buildErrorResponse(getComponentsUtils().getResponseFormatByUserId(either.right().value(), userId)); @@ -494,7 +506,8 @@ public class ElementServlet extends BeGenericServlet { if (either.left().value() != null) { userData = either.left().value(); - Either>, ResponseFormat> followedResourcesServices = getElementBL(request.getSession().getServletContext()).getFollowed(userData); + Either>, ResponseFormat> followedResourcesServices = + elementBusinessLogic.getFollowed(userData); if (followedResourcesServices.isRight()) { log.debug("failed to get followed resources services "); return buildErrorResponse(followedResourcesServices.right().value()); @@ -528,7 +541,8 @@ public class ElementServlet extends BeGenericServlet { String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); - Either>, ResponseFormat> catalogData = getElementBL(request.getSession().getServletContext()).getCatalogComponents(userId, excludeTypes); + Either>, ResponseFormat> catalogData = elementBusinessLogic + .getCatalogComponents(userId, excludeTypes); if (catalogData.isRight()) { log.debug("failed to get catalog data"); @@ -548,9 +562,6 @@ public class ElementServlet extends BeGenericServlet { @DELETE @Path("/inactiveComponents/{componentType}") public Response deleteMarkedResources(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request) { - - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -571,8 +582,7 @@ public class ElementServlet extends BeGenericServlet { List componentsList = new ArrayList<>(); componentsList.add(nodeType); try { - ComponentsCleanBusinessLogic businessLogic = getComponentCleanerBL(context); - Map, ResponseFormat>> cleanComponentsResult = businessLogic.cleanComponents(componentsList); + Map, ResponseFormat>> cleanComponentsResult = componentsCleanBusinessLogic.cleanComponents(componentsList); Either, ResponseFormat> cleanResult = cleanComponentsResult.get(nodeType); if (cleanResult.isRight()) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GenericArtifactBrowserServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GenericArtifactBrowserServlet.java index ea00a86ad9..afa57f7957 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GenericArtifactBrowserServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GenericArtifactBrowserServlet.java @@ -30,6 +30,7 @@ import io.swagger.annotations.ApiResponses; import java.io.IOException; import java.util.Set; import java.util.stream.Collectors; +import javax.inject.Inject; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; @@ -42,7 +43,13 @@ import javax.ws.rs.core.Response; import org.apache.commons.lang3.tuple.ImmutablePair; import org.onap.sdc.gab.model.GABQuery; import org.onap.sdc.gab.model.GABQuery.GABQueryType; +import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GenericArtifactBrowserBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.info.GenericArtifactQueryInfo; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; import org.owasp.esapi.ESAPI; @@ -57,6 +64,18 @@ import org.springframework.stereotype.Controller; public class GenericArtifactBrowserServlet extends BeGenericServlet { private static final Logger LOGGER = Logger.getLogger(GenericArtifactBrowserServlet.class); + private final GenericArtifactBrowserBusinessLogic gabLogic; + private final ArtifactsBusinessLogic artifactsBusinessLogic; + + @Inject + public GenericArtifactBrowserServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, + ArtifactsBusinessLogic artifactsBusinessLogic, + GenericArtifactBrowserBusinessLogic gabLogic) { + super(userBusinessLogic, componentsUtils); + this.artifactsBusinessLogic = artifactsBusinessLogic; + this.gabLogic = gabLogic; + } @POST @Path("/searchFor") @@ -68,12 +87,11 @@ public class GenericArtifactBrowserServlet extends BeGenericServlet { @ApiParam(value = "Generic Artifact search model", required = true) GenericArtifactQueryInfo query, @Context final HttpServletRequest request) { try { - ServletContext context = request.getSession().getServletContext(); - Either, ResponseFormat> immutablePairResponseFormatEither = getArtifactBL(context) + Either, ResponseFormat> immutablePairResponseFormatEither = artifactsBusinessLogic .downloadArtifact(ESAPI.encoder().canonicalize(query.getParentId()), ESAPI.encoder().canonicalize(query.getArtifactUniqueId())); if (immutablePairResponseFormatEither.isLeft()){ GABQuery gabQuery = prepareGabQuery(query, immutablePairResponseFormatEither); - return buildOkResponse(getGenericArtifactBrowserBL(context).searchFor(gabQuery)); + return buildOkResponse(gabLogic.searchFor(gabQuery)); }else{ throw new IOException(immutablePairResponseFormatEither.right().value().getFormattedMessage()); } @@ -89,5 +107,4 @@ public class GenericArtifactBrowserServlet extends BeGenericServlet { Set queryFields = query.getFields().stream().map(ESAPI.encoder()::canonicalize).collect(Collectors.toSet()); return new GABQuery(queryFields, new String(content), GABQueryType.CONTENT); } - } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupEndpoint.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupEndpoint.java index 3a4a6d1010..eb61e8992a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupEndpoint.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupEndpoint.java @@ -22,6 +22,7 @@ package org.openecomp.sdc.be.servlets; import com.jcabi.aspects.Loggable; import io.swagger.annotations.*; +import javax.inject.Inject; import org.openecomp.sdc.be.components.impl.GroupBusinessLogicNew; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; @@ -46,6 +47,7 @@ public class GroupEndpoint { private final GroupBusinessLogicNew groupBusinessLogic; + @Inject public GroupEndpoint(GroupBusinessLogicNew groupBusinessLogic) { this.groupBusinessLogic = groupBusinessLogic; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java index 6d61e0685b..557304f903 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java @@ -23,14 +23,20 @@ package org.openecomp.sdc.be.servlets; import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; +import javax.inject.Inject; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.info.GroupDefinitionInfo; import org.openecomp.sdc.be.model.GroupDefinition; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; @@ -56,6 +62,16 @@ public class GroupServlet extends AbstractValidationsServlet { private static final Logger log = Logger.getLogger(GroupServlet.class); public static final String START_HANDLE_REQUEST = "Start handle request of {}"; + private final GroupBusinessLogic groupBL; + + @Inject + public GroupServlet(UserBusinessLogic userBusinessLogic, + GroupBusinessLogic groupBL, ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); + this.groupBL = groupBL; + } @POST @Path("/{containerComponentType}/{componentId}/groups/{groupType}") @@ -72,13 +88,11 @@ public class GroupServlet extends AbstractValidationsServlet { @PathParam("groupType") final String type, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("(post) Start handle request of {}", url); - GroupBusinessLogic businessLogic = getGroupBL(context); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - GroupDefinition groupDefinition = businessLogic + GroupDefinition groupDefinition = groupBL .createGroup(componentId, componentTypeEnum, type, userId); return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), @@ -95,15 +109,13 @@ public class GroupServlet extends AbstractValidationsServlet { @PathParam("componentId") final String componentId, @PathParam("groupId") final String groupId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("(get) Start handle request of {}", url); try { - GroupBusinessLogic businessLogic = this.getGroupBL(context); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - Either actionResponse = businessLogic + Either actionResponse = groupBL .getGroupWithArtifactsById(componentTypeEnum, componentId, groupId, userId, false); if (actionResponse.isRight()) { @@ -137,12 +149,10 @@ public class GroupServlet extends AbstractValidationsServlet { @PathParam("groupUniqueId") final String groupId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST, url); - GroupBusinessLogic businessLogic = this.getGroupBL(context); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - GroupDefinition groupDefinition = businessLogic + GroupDefinition groupDefinition = groupBL .deleteGroup(componentId, componentTypeEnum, groupId, userId); return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), groupDefinition.getUniqueId()); @@ -162,10 +172,8 @@ public class GroupServlet extends AbstractValidationsServlet { @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "GroupDefinition", required = true) GroupDefinition groupData, @Context final HttpServletRequest request) { - ServletContext context = request.getSession().getServletContext(); - GroupBusinessLogic businessLogic = this.getGroupBL(context); ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - GroupDefinition updatedGroup = businessLogic.updateGroup(componentId, componentTypeEnum, groupId, userId, groupData); + GroupDefinition updatedGroup = groupBL.updateGroup(componentId, componentTypeEnum, groupId, userId, groupData); return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), updatedGroup); } @@ -184,7 +192,6 @@ public class GroupServlet extends AbstractValidationsServlet { @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST, url); @@ -195,8 +202,6 @@ public class GroupServlet extends AbstractValidationsServlet { Response response = null; try { - GroupBusinessLogic businessLogic = getGroupBL(context); - Either convertResponse = parseToObject(data, () -> GroupDefinition.class); if (convertResponse.isRight()) { log.debug("failed to parse group"); @@ -207,7 +212,7 @@ public class GroupServlet extends AbstractValidationsServlet { // Update GroupDefinition ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); - Either actionResponse = businessLogic + Either actionResponse = groupBL .validateAndUpdateGroupMetadata(componentId, user, componentTypeEnum, updatedGroup, true ,true); if (actionResponse.isRight()) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java index 9f77c5150a..4f97eaf198 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java @@ -30,6 +30,7 @@ import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import java.util.Arrays; import java.util.List; +import javax.inject.Inject; import javax.inject.Singleton; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; @@ -45,13 +46,16 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.DataTypeBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.impl.InputsBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; -import org.openecomp.sdc.be.impl.WebAppContextWrapper; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.datatypes.enums.DeclarationTypeEnum; import org.openecomp.sdc.be.model.ComponentInstInputsMap; @@ -63,10 +67,10 @@ import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.ComponentInstListInput; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; -import org.springframework.web.context.WebApplicationContext; @Loggable(prepend = true, value = Loggable.DEBUG, trim = false) @Api(value = "Input Catalog", description = "Input Servlet") @@ -78,6 +82,21 @@ public class InputsServlet extends AbstractValidationsServlet { private static final Logger log = Logger.getLogger(InputsServlet.class); + private final DataTypeBusinessLogic businessLogic; + private final InputsBusinessLogic inputsBusinessLogic; + + @Inject + public InputsServlet(UserBusinessLogic userBusinessLogic, + InputsBusinessLogic inputsBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager, + DataTypeBusinessLogic dataTypeBusinessLogic) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); + this.inputsBusinessLogic = inputsBusinessLogic; + this.businessLogic = dataTypeBusinessLogic; + } + @POST @Path("/{containerComponentType}/{componentId}/update/inputs") @ApiOperation(value = "Update resource inputs", httpMethod = "POST", notes = "Returns updated input", response = Response.class) @@ -110,13 +129,12 @@ public class InputsServlet extends AbstractValidationsServlet { ServletContext context = request.getSession().getServletContext(); ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(containerComponentType); - InputsBusinessLogic businessLogic = getInputBL(context); if (businessLogic == null) { log.debug("Unsupported component type {}", containerComponentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR)); } - Either, ResponseFormat> actionResponse = businessLogic.updateInputsValue(componentType, componentId, inputsToUpdate, userId, true, false); + Either, ResponseFormat> actionResponse = inputsBusinessLogic.updateInputsValue(componentType, componentId, inputsToUpdate, userId, true, false); if (actionResponse.isRight()) { return buildErrorResponse(actionResponse.right().value()); @@ -148,9 +166,7 @@ public class InputsServlet extends AbstractValidationsServlet { Response response; try { - InputsBusinessLogic businessLogic = getInputBL(context); - - Either, ResponseFormat> inputsResponse = businessLogic.getComponentInstanceInputs(userId, componentId, instanceId); + Either, ResponseFormat> inputsResponse = inputsBusinessLogic.getComponentInstanceInputs(userId, componentId, instanceId); if (inputsResponse.isRight()) { log.debug("failed to get component instance inputs {}", componentType); return buildErrorResponse(inputsResponse.right().value()); @@ -180,9 +196,7 @@ public class InputsServlet extends AbstractValidationsServlet { Response response = null; try { - InputsBusinessLogic businessLogic = getInputBL(context); - - Either, ResponseFormat> inputPropertiesRes = businessLogic.getComponentInstancePropertiesByInputId(userId, componentId, instanceId, inputId); + Either, ResponseFormat> inputPropertiesRes = inputsBusinessLogic.getComponentInstancePropertiesByInputId(userId, componentId, instanceId, inputId); if (inputPropertiesRes.isRight()) { log.debug("failed to get properties of input: {}, with instance id: {}", inputId, instanceId); return buildErrorResponse(inputPropertiesRes.right().value()); @@ -211,9 +225,7 @@ public class InputsServlet extends AbstractValidationsServlet { log.debug("(get) Start handle request of {}", url); Response response; try { - InputsBusinessLogic businessLogic = getInputBL(context); - - Either, ResponseFormat> inputsRes = businessLogic.getInputsForComponentInput(userId, componentId, inputId); + Either, ResponseFormat> inputsRes = inputsBusinessLogic.getInputsForComponentInput(userId, componentId, inputId); if (inputsRes.isRight()) { log.debug("failed to get inputs of input: {}, with instance id: {}", inputId, componentId); @@ -244,9 +256,7 @@ public class InputsServlet extends AbstractValidationsServlet { Response response; try { - InputsBusinessLogic businessLogic = getInputBL(context); - - Either inputsRes = businessLogic.getInputsAndPropertiesForComponentInput(userId, componentId, inputId, false); + Either inputsRes = inputsBusinessLogic.getInputsAndPropertiesForComponentInput(userId, componentId, inputId, false); if (inputsRes.isRight()) { log.debug("failed to get inputs of input: {}, with instance id: {}", inputId, componentId); @@ -310,8 +320,6 @@ public class InputsServlet extends AbstractValidationsServlet { Response response = null; try { - InputsBusinessLogic businessLogic = getInputBL(context); - // get modifier id User modifier = new User(); modifier.setUserId(userId); @@ -332,7 +340,7 @@ public class InputsServlet extends AbstractValidationsServlet { log.debug("parsed componentInstInputsMap={}", ReflectionToStringBuilder.toString(componentInstInputsMap)); } - Either, ResponseFormat> inputPropertiesRes = businessLogic.createListInput( + Either, ResponseFormat> inputPropertiesRes = inputsBusinessLogic.createListInput( userId, componentId, componentTypeEnum, componentInstInputsMap, true, false); if (inputPropertiesRes.isRight()) { log.debug("failed to create list input for service: {}", componentId); @@ -368,8 +376,7 @@ public class InputsServlet extends AbstractValidationsServlet { Response response = null; try { - InputsBusinessLogic businessLogic = getInputBL(context); - Either deleteInput = businessLogic.deleteInput(componentId, userId, inputId); + Either deleteInput = inputsBusinessLogic.deleteInput(componentId, userId, inputId); if (deleteInput.isRight()){ ResponseFormat deleteResponseFormat = deleteInput.right().value(); response = buildErrorResponse(deleteResponseFormat); @@ -407,14 +414,12 @@ public class InputsServlet extends AbstractValidationsServlet { @PathParam("dataTypeName") final String dataTypeName, @Context final HttpServletRequest request ) { - ServletContext context = request.getSession().getServletContext(); ComponentsUtils componentsUtils = getComponentsUtils(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("(getDataType) Start handle request of {}", url); Response response; try { - DataTypeBusinessLogic businessLogic = getDataTypeBL(context); Either getResult = businessLogic.getPrivateDataType(componentId, dataTypeName); if (getResult.isRight()) { ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getResult.right().value()); @@ -457,7 +462,6 @@ public class InputsServlet extends AbstractValidationsServlet { Response response; try { - DataTypeBusinessLogic businessLogic = getDataTypeBL(context); Either, StorageOperationStatus> getResult = businessLogic.getPrivateDataTypes(componentId); if (getResult.isRight()) { ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getResult.right().value()); @@ -502,7 +506,6 @@ public class InputsServlet extends AbstractValidationsServlet { Response response; try { - DataTypeBusinessLogic businessLogic = getDataTypeBL(context); Either deleteResult = businessLogic.deletePrivateDataType(componentId, dataTypeName); if (deleteResult.isRight()) { ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteResult.right().value()); @@ -517,10 +520,4 @@ public class InputsServlet extends AbstractValidationsServlet { return response; } } - - private DataTypeBusinessLogic getDataTypeBL(ServletContext context) { - WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); - WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); - return webApplicationContext.getBean(DataTypeBusinessLogic.class); - } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java index 4388b1db56..66b465d40f 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; +import javax.inject.Inject; import javax.inject.Singleton; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; @@ -44,19 +45,26 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.exception.ResponseFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; @Loggable(prepend = true, value = Loggable.DEBUG, trim = false) @Path("/v1/catalog") @@ -67,6 +75,17 @@ import org.slf4j.LoggerFactory; public class InterfaceOperationServlet extends AbstractValidationsServlet { private static final Logger log = LoggerFactory.getLogger(InterfaceOperationServlet.class); + private final InterfaceOperationBusinessLogic interfaceOperationBusinessLogic; + + @Inject + public InterfaceOperationServlet(UserBusinessLogic userBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager, + InterfaceOperationBusinessLogic interfaceOperationBusinessLogic) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); + this.interfaceOperationBusinessLogic = interfaceOperationBusinessLogic; + } @POST @Consumes(MediaType.APPLICATION_JSON) @@ -88,7 +107,6 @@ public class InterfaceOperationServlet extends AbstractValidationsServlet { private Response createOrUpdate(String data, ComponentTypeEnum componentType, String componentId, HttpServletRequest request, String userId, boolean isUpdate) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); User modifier = new User(); @@ -97,16 +115,17 @@ public class InterfaceOperationServlet extends AbstractValidationsServlet { try { String componentIdLower = componentId.toLowerCase(); - InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context); List mappedInterfaceData = getMappedInterfaceData(data, modifier, componentType); Either, ResponseFormat> actionResponse; if (isUpdate) { actionResponse = - businessLogic.updateInterfaceOperation(componentIdLower, mappedInterfaceData, modifier, true); + interfaceOperationBusinessLogic + .updateInterfaceOperation(componentIdLower, mappedInterfaceData, modifier, true); } else { actionResponse = - businessLogic.createInterfaceOperation(componentIdLower, mappedInterfaceData, modifier, true); + interfaceOperationBusinessLogic + .createInterfaceOperation(componentIdLower, mappedInterfaceData, modifier, true); } if (actionResponse.isRight()) { @@ -175,7 +194,6 @@ public class InterfaceOperationServlet extends AbstractValidationsServlet { private Response delete(String interfaceId, String operationId, String componentId, HttpServletRequest request, String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); User modifier = new User(); @@ -184,8 +202,8 @@ public class InterfaceOperationServlet extends AbstractValidationsServlet { try { String componentIdLower = componentId.toLowerCase(); - InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context); - Either, ResponseFormat> actionResponse = businessLogic.deleteInterfaceOperation( + Either, ResponseFormat> actionResponse = + interfaceOperationBusinessLogic.deleteInterfaceOperation( componentIdLower, interfaceId, Collections.singletonList(operationId), modifier, true); if (actionResponse.isRight()) { log.error("failed to delete interface operation"); @@ -221,7 +239,6 @@ public class InterfaceOperationServlet extends AbstractValidationsServlet { private Response get(String interfaceId, String operationId, String componentId, HttpServletRequest request, String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); User modifier = new User(); @@ -230,8 +247,8 @@ public class InterfaceOperationServlet extends AbstractValidationsServlet { try { String componentIdLower = componentId.toLowerCase(); - InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context); - Either, ResponseFormat> actionResponse = businessLogic.getInterfaceOperation( + Either, ResponseFormat> actionResponse = + interfaceOperationBusinessLogic.getInterfaceOperation( componentIdLower, interfaceId, Collections.singletonList(operationId), modifier, true); if (actionResponse.isRight()) { log.error("failed to get interface operation"); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/LifecycleServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/LifecycleServlet.java index 0d2308407e..60e8f3c0fa 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/LifecycleServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/LifecycleServlet.java @@ -24,6 +24,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; +import javax.inject.Inject; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoBase; import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction; @@ -31,11 +34,13 @@ import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.LifeCycleTransitionEnum; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.ui.model.UiComponentMetadata; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; @@ -47,6 +52,7 @@ import javax.ws.rs.*; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.springframework.beans.factory.annotation.Autowired; @Loggable(prepend = true, value = Loggable.DEBUG, trim = false) @Path("/v1/catalog") @@ -55,6 +61,16 @@ import javax.ws.rs.core.Response; public class LifecycleServlet extends BeGenericServlet { private static final Logger log = Logger.getLogger(LifecycleServlet.class); + private final LifecycleBusinessLogic lifecycleBusinessLogic; + + @Inject + public LifecycleServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, + LifecycleBusinessLogic lifecycleBusinessLogic) { + super(userBusinessLogic, componentsUtils); + this.lifecycleBusinessLogic = lifecycleBusinessLogic; + } + @POST @Path("/{componentCollection}/{componentId}/lifecycleState/{lifecycleOperation}") @@ -69,9 +85,6 @@ public class LifecycleServlet extends BeGenericServlet { @ApiParam(value = "id of component to be changed") @PathParam(value = "componentId") final String componentId, @Context final HttpServletRequest request, @ApiParam(value = "id of user initiating the operation") @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); - LifecycleBusinessLogic businessLogic = getLifecycleBL(context); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -112,7 +125,8 @@ public class LifecycleServlet extends BeGenericServlet { LifeCycleTransitionEnum transitionEnum = validateEnum.left().value(); ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(componentCollection); if (componentType != null) { - Either actionResponse = businessLogic.changeComponentState(componentType, componentId, user, transitionEnum, changeInfo, false, true); + Either actionResponse = lifecycleBusinessLogic + .changeComponentState(componentType, componentId, user, transitionEnum, changeInfo, false, true); if (actionResponse.isRight()) { log.info("failed to change resource state"); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java index cb228a1e9b..38f38787a6 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java @@ -31,6 +31,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -45,6 +46,8 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.apache.commons.lang3.StringUtils; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic; import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.config.BeEcompErrorManager; @@ -58,6 +61,7 @@ import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.PolicyDefinition; import org.openecomp.sdc.be.model.PolicyTargetDTO; import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.datastructure.Wrapper; import org.openecomp.sdc.common.log.wrappers.Logger; @@ -78,11 +82,14 @@ public class PolicyServlet extends AbstractValidationsServlet { private static final Logger log = Logger.getLogger(PolicyServlet.class); private final PolicyBusinessLogic policyBusinessLogic; - public PolicyServlet(PolicyBusinessLogic policyBusinessLogic, ServletUtils servletUtils, ResourceImportManager resourceImportManager, ComponentsUtils componentsUtils) { + @Inject + public PolicyServlet(UserBusinessLogic userBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager, + PolicyBusinessLogic policyBusinessLogic) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); this.policyBusinessLogic = policyBusinessLogic; - this.servletUtils = servletUtils; - this.resourceImportManager = resourceImportManager; - this.componentsUtils = componentsUtils; } @POST diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ProductServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ProductServlet.java index 370f5d5b1d..922db5adac 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ProductServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ProductServlet.java @@ -23,11 +23,16 @@ package org.openecomp.sdc.be.servlets; import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; +import javax.inject.Inject; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.impl.ProductBusinessLogic; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.Product; import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; @@ -47,6 +52,15 @@ import java.util.Map; @Singleton public class ProductServlet extends BeGenericServlet { private static final Logger log = Logger.getLogger(ProductServlet.class); + private final ProductBusinessLogic productBusinessLogic; + + @Inject + public ProductServlet(UserBusinessLogic userBusinessLogic, + ProductBusinessLogic productBusinessLogic, + ComponentsUtils componentsUtils) { + super(userBusinessLogic, componentsUtils); + this.productBusinessLogic = productBusinessLogic; + } @POST @Path("/products") @@ -58,7 +72,6 @@ public class ProductServlet extends BeGenericServlet { public Response createProduct(@ApiParam(value = "Product object to be created", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) @ApiParam(value = "USER_ID of product strategist user", required = true) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -68,9 +81,8 @@ public class ProductServlet extends BeGenericServlet { Response response = null; try { - ProductBusinessLogic businessLogic = getProductBL(context); Product product = RepresentationUtils.fromRepresentation(data, Product.class); - Either actionResponse = businessLogic.createProduct(product, modifier); + Either actionResponse = productBusinessLogic.createProduct(product, modifier); if (actionResponse.isRight()) { log.debug("Failed to create product"); @@ -99,7 +111,6 @@ public class ProductServlet extends BeGenericServlet { @ApiResponse(code = 500, message = "Internal Server Error"), @ApiResponse(code = 404, message = "Product not found"), }) public Response getProductById(@PathParam("productId") final String productId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -110,9 +121,8 @@ public class ProductServlet extends BeGenericServlet { Response response = null; try { - ProductBusinessLogic businessLogic = getProductBL(context); log.trace("get product with id {}", productId); - Either actionResponse = businessLogic.getProduct(productId, modifier); + Either actionResponse = productBusinessLogic.getProduct(productId, modifier); if (actionResponse.isRight()) { log.debug("Failed to get product"); @@ -140,7 +150,6 @@ public class ProductServlet extends BeGenericServlet { public Response getServiceByNameAndVersion(@PathParam("productName") final String productName, @PathParam("productVersion") final String productVersion, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); // get modifier id User modifier = new User(); modifier.setUserId(userId); @@ -148,8 +157,7 @@ public class ProductServlet extends BeGenericServlet { Response response = null; try { - ProductBusinessLogic businessLogic = getProductBL(context); - Either actionResponse = businessLogic.getProductByNameAndVersion(productName, productVersion, userId); + Either actionResponse = productBusinessLogic.getProductByNameAndVersion(productName, productVersion, userId); if (actionResponse.isRight()) { response = buildErrorResponse(actionResponse.right().value()); @@ -173,8 +181,6 @@ public class ProductServlet extends BeGenericServlet { @Path("/products/{productId}") public Response deleteProduct(@PathParam("productId") final String productId, @Context final HttpServletRequest request) { - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -187,9 +193,8 @@ public class ProductServlet extends BeGenericServlet { Response response = null; try { - ProductBusinessLogic businessLogic = getProductBL(context); log.trace("delete product with id {}", productId); - Either actionResponse = businessLogic.deleteProduct(productId, modifier); + Either actionResponse = productBusinessLogic.deleteProduct(productId, modifier); if (actionResponse.isRight()) { log.debug("Failed to delete product"); @@ -219,7 +224,6 @@ public class ProductServlet extends BeGenericServlet { public Response updateProductMetadata(@PathParam("productId") final String productId, @ApiParam(value = "Product object to be Updated", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -230,9 +234,8 @@ public class ProductServlet extends BeGenericServlet { try { String productIdLower = productId.toLowerCase(); - ProductBusinessLogic businessLogic = getProductBL(context); Product updatedProduct = RepresentationUtils.fromRepresentation(data, Product.class); - Either actionResponse = businessLogic.updateProductMetadata(productIdLower, updatedProduct, modifier); + Either actionResponse = productBusinessLogic.updateProductMetadata(productIdLower, updatedProduct, modifier); if (actionResponse.isRight()) { log.debug("failed to update product"); @@ -258,7 +261,6 @@ public class ProductServlet extends BeGenericServlet { @ApiOperation(value = "validate product name", httpMethod = "GET", notes = "checks if the chosen product name is available ", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Service found"), @ApiResponse(code = 403, message = "Restricted operation") }) public Response validateServiceName(@PathParam("productName") final String productName, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -267,9 +269,7 @@ public class ProductServlet extends BeGenericServlet { log.debug("modifier id is {}", userId); Response response = null; try { - ProductBusinessLogic businessLogic = getProductBL(context); - - Either, ResponseFormat> actionResponse = businessLogic.validateProductNameExists(productName, userId); + Either, ResponseFormat> actionResponse = productBusinessLogic.validateProductNameExists(productName, userId); if (actionResponse.isRight()) { log.debug("failed to get validate service name"); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementServlet.java index 51f6783f0d..1abc69bf42 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementServlet.java @@ -23,14 +23,21 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import javax.inject.Inject; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.impl.RequirementBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.RequirementDefinition; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; @@ -61,6 +68,17 @@ import java.util.Optional; @Singleton public class RequirementServlet extends AbstractValidationsServlet { private static final Logger LOGGER = Logger.getLogger(RequirementServlet.class); + private final RequirementBusinessLogic requirementBusinessLogic; + + @Inject + public RequirementServlet(UserBusinessLogic userBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager, + RequirementBusinessLogic requirementBusinessLogic) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); + this.requirementBusinessLogic = requirementBusinessLogic; + } @POST @Consumes(MediaType.APPLICATION_JSON) @@ -213,7 +231,6 @@ public class RequirementServlet extends AbstractValidationsServlet { private Response createOrUpdate (String data, String componentType, String componentId, HttpServletRequest request, String userId, boolean isUpdate, String errorContext) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); User modifier = new User(); @@ -222,7 +239,6 @@ public class RequirementServlet extends AbstractValidationsServlet { try { String componentIdLower = componentId.toLowerCase(); - RequirementBusinessLogic businessLogic = getRequirementBL(context); Either, ResponseFormat> mappedRequirementDataEither = getMappedRequirementData(data, modifier, ComponentTypeEnum.findByParamName(componentType)); @@ -233,10 +249,10 @@ public class RequirementServlet extends AbstractValidationsServlet { List mappedRequirementData = mappedRequirementDataEither.left().value(); Either, ResponseFormat> actionResponse; if(isUpdate) { - actionResponse = businessLogic.updateRequirements(componentIdLower, mappedRequirementData, modifier, + actionResponse = requirementBusinessLogic.updateRequirements(componentIdLower, mappedRequirementData, modifier, errorContext, true); } else { - actionResponse = businessLogic.createRequirements(componentIdLower, mappedRequirementData, modifier, + actionResponse = requirementBusinessLogic.createRequirements(componentIdLower, mappedRequirementData, modifier, errorContext, true); } @@ -256,7 +272,6 @@ public class RequirementServlet extends AbstractValidationsServlet { private Response get (String requirementIdToGet, String componentId, HttpServletRequest request, String userId){ - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); User modifier = new User(); @@ -265,9 +280,7 @@ public class RequirementServlet extends AbstractValidationsServlet { try { String componentIdLower = componentId.toLowerCase(); - RequirementBusinessLogic businessLogic = getRequirementBL(context); - - Either actionResponse = businessLogic + Either actionResponse = requirementBusinessLogic .getRequirement(componentIdLower, requirementIdToGet, modifier, true); if (actionResponse.isRight()) { LOGGER.error("failed to get requirements"); @@ -284,8 +297,6 @@ public class RequirementServlet extends AbstractValidationsServlet { private Response delete (String requirementId, String componentId, HttpServletRequest request, String userId){ - - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); User modifier = new User(); @@ -294,9 +305,8 @@ public class RequirementServlet extends AbstractValidationsServlet { try { String componentIdLower = componentId.toLowerCase(); - RequirementBusinessLogic businessLogic = getRequirementBL(context); - Either actionResponse = businessLogic + Either actionResponse = requirementBusinessLogic .deleteRequirement(componentIdLower, requirementId, modifier, true); if (actionResponse.isRight()) { LOGGER.error("failed to delete requirements"); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementsServlet.java index 17a9bf67ba..d1f50c9361 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementsServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementsServlet.java @@ -25,7 +25,12 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import javax.inject.Inject; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; @@ -41,6 +46,12 @@ public class RequirementsServlet extends BeGenericServlet { private static final Logger log = Logger.getLogger(RequirementsServlet.class); + @Inject + public RequirementsServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils) { + super(userBusinessLogic, componentsUtils); + } + @PUT @Path("resources/{resourceId}/requirements/{requirementId}") @Consumes(MediaType.APPLICATION_JSON) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceArtifactDownloadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceArtifactDownloadServlet.java index fae48103d8..932dc51214 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceArtifactDownloadServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceArtifactDownloadServlet.java @@ -23,13 +23,17 @@ package org.openecomp.sdc.be.servlets; import com.jcabi.aspects.Loggable; import fj.data.Either; import org.apache.http.HttpStatus; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.api.ResourceUploadStatus; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.impl.DownloadArtifactLogic; import org.openecomp.sdc.be.info.ArtifactAccessInfo; import org.openecomp.sdc.be.resources.api.IResourceUploader; import org.openecomp.sdc.be.resources.data.ESArtifactData; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; @@ -49,6 +53,12 @@ public class ResourceArtifactDownloadServlet extends ToscaDaoServlet { private static final Logger log = Logger.getLogger(ResourceArtifactDownloadServlet.class); + public ResourceArtifactDownloadServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, + IResourceUploader resourceUploader, DownloadArtifactLogic logic) { + super(userBusinessLogic, componentsUtils, resourceUploader, logic); + } + @GET @Path("/{resourceName}/{resourceVersion}/artifacts/{artifactName}") // @Produces(MediaType.APPLICATION_OCTET_STREAM) @@ -62,18 +72,8 @@ public class ResourceArtifactDownloadServlet extends ToscaDaoServlet { // get the artifact data String artifactId = String.format(Constants.ARTIFACT_ID_FORMAT, resourceName, resourceVersion, artifactName); - IResourceUploader resouceUploader = getResourceUploader(request.getSession().getServletContext()); - if (resouceUploader == null) { - return buildResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, ""); - - } - Either getArtifactStatus = resouceUploader.getArtifact(artifactId); - - DownloadArtifactLogic logic = getLogic(request.getSession().getServletContext()); - if (logic == null) { - return buildResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, ""); + Either getArtifactStatus = resourceUploader.getArtifact(artifactId); - } response = logic.downloadArtifact(artifactName, getArtifactStatus, artifactId); log.info("Finish handle request of {} | result = {}", url, response.getStatus()); @@ -98,15 +98,9 @@ public class ResourceArtifactDownloadServlet extends ToscaDaoServlet { Response response = null; try { - IResourceUploader resourceDao = getResourceUploader(request.getSession().getServletContext()); - if (resourceDao == null) { - log.error("resource dao cannot be found"); - response = buildResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Resource dao cannot be found"); - return response; - } String artifactId = String.format(Constants.ARTIFACT_ID_FORMAT, resourceName, resourceVersion, artifactName); - Either getArtifactStatus = resourceDao.getArtifact(artifactId); + Either getArtifactStatus = resourceUploader.getArtifact(artifactId); if (getArtifactStatus.isRight()) { ResourceUploadStatus status = getArtifactStatus.right().value(); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java index af8903124c..6e78b503d3 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java @@ -22,21 +22,24 @@ package org.openecomp.sdc.be.servlets; import com.jcabi.aspects.Loggable; import io.swagger.annotations.*; +import javax.inject.Inject; import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataParam; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.impl.ResourceImportManager; 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.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.UploadResourceInfo; import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.datastructure.Wrapper; import org.openecomp.sdc.common.log.wrappers.Logger; -import org.springframework.web.context.WebApplicationContext; import javax.inject.Singleton; -import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.*; import javax.ws.rs.core.Context; @@ -59,6 +62,14 @@ public class ResourceUploadServlet extends AbstractValidationsServlet { public static final String USER_TYPE_RESOURCE = "user-resource"; public static final String USER_TYPE_RESOURCE_UI_IMPORT = "user-resource-ui-import"; + @Inject + public ResourceUploadServlet(UserBusinessLogic userBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); + } + public enum ResourceAuthorityTypeEnum { NORMATIVE_TYPE_BE(NORMATIVE_TYPE_RESOURCE, true, false), USER_TYPE_BE(USER_TYPE_RESOURCE, true, true), USER_TYPE_UI(USER_TYPE_RESOURCE_UI_IMPORT, false, true), CSAR_TYPE_BE(CSAR_TYPE_RESOURCE, true, true); @@ -110,7 +121,6 @@ public class ResourceUploadServlet extends AbstractValidationsServlet { // updateResourse Query Parameter if false checks if already exist @DefaultValue("true") @QueryParam("createNewVersion") boolean createNewVersion) { - init(request.getSession().getServletContext()); try { Wrapper responseWrapper = new Wrapper<>(); @@ -152,12 +162,4 @@ public class ResourceUploadServlet extends AbstractValidationsServlet { } /********************************************************************************************************************/ - - private void init(ServletContext context) { - init(); - WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); - WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); - resourceImportManager = webApplicationContext.getBean(ResourceImportManager.class); - resourceImportManager.init(context); - } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourcesServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourcesServlet.java index 818743f7b3..e18cbfc1af 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourcesServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourcesServlet.java @@ -23,22 +23,29 @@ package org.openecomp.sdc.be.servlets; import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; +import javax.inject.Inject; import org.apache.http.HttpStatus; import org.json.JSONException; import org.json.JSONObject; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.CsarValidationUtils; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.impl.ImportUtils; import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.UploadResourceInfo; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.servlets.ResourceUploadServlet.ResourceAuthorityTypeEnum; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.datastructure.Wrapper; import org.openecomp.sdc.common.log.wrappers.Logger; @@ -63,6 +70,17 @@ import java.util.Map; public class ResourcesServlet extends AbstractValidationsServlet { private static final Logger log = Logger.getLogger(ResourcesServlet.class); + private final ResourceBusinessLogic resourceBusinessLogic; + + @Inject + public ResourcesServlet(UserBusinessLogic userBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, + ResourceBusinessLogic resourceBusinessLogic, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); + this.resourceBusinessLogic = resourceBusinessLogic; + } @POST @Path("/resources") @@ -76,8 +94,6 @@ public class ResourcesServlet extends AbstractValidationsServlet { userId = (userId != null) ? userId : request.getHeader(Constants.USER_ID_HEADER); init(); - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}" , url); @@ -97,8 +113,6 @@ public class ResourcesServlet extends AbstractValidationsServlet { // UI Create else { - ResourceBusinessLogic businessLogic = getResourceBL(context); - Either convertResponse = parseToResource(data, modifier); if (convertResponse.isRight()) { log.debug("failed to parse resource"); @@ -107,7 +121,7 @@ public class ResourcesServlet extends AbstractValidationsServlet { } Resource resource = convertResponse.left().value(); - Resource createdResource = businessLogic.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, modifier, null, null); + Resource createdResource = resourceBusinessLogic.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, modifier, null, null); Object representation = RepresentationUtils.toRepresentation(createdResource); response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), representation); responseWrapper.setInnerElement(response); @@ -189,8 +203,7 @@ public class ResourcesServlet extends AbstractValidationsServlet { try { String resourceIdLower = resourceId.toLowerCase(); - ResourceBusinessLogic businessLogic = getResourceBL(context); - ResponseFormat actionResponse = businessLogic.deleteResource(resourceIdLower, modifier); + ResponseFormat actionResponse = resourceBusinessLogic.deleteResource(resourceIdLower, modifier); if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) { log.debug("failed to delete resource"); @@ -225,8 +238,7 @@ public class ResourcesServlet extends AbstractValidationsServlet { log.debug("modifier id is {}" , userId); Response response; - ResourceBusinessLogic businessLogic = getResourceBL(context); - ResponseFormat actionResponse = businessLogic.deleteResourceByNameAndVersion(resourceName, version, modifier); + ResponseFormat actionResponse = resourceBusinessLogic.deleteResourceByNameAndVersion(resourceName, version, modifier); if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) { log.debug("failed to delete resource"); @@ -259,9 +271,8 @@ public class ResourcesServlet extends AbstractValidationsServlet { try { String resourceIdLower = resourceId.toLowerCase(); - ResourceBusinessLogic businessLogic = getResourceBL(context); log.trace("get resource with id {}", resourceId); - Either actionResponse = businessLogic.getResource(resourceIdLower, modifier); + Either actionResponse = resourceBusinessLogic.getResource(resourceIdLower, modifier); if (actionResponse.isRight()) { log.debug("failed to get resource"); @@ -295,8 +306,7 @@ public class ResourcesServlet extends AbstractValidationsServlet { log.debug("modifier id is {}" , userId); Response response; try { - ResourceBusinessLogic businessLogic = getResourceBL(context); - Either actionResponse = businessLogic.getResourceByNameAndVersion(resourceName, resourceVersion, userId); + Either actionResponse = resourceBusinessLogic.getResourceByNameAndVersion(resourceName, resourceVersion, userId); if (actionResponse.isRight()) { response = buildErrorResponse(actionResponse.right().value()); return response; @@ -328,7 +338,6 @@ public class ResourcesServlet extends AbstractValidationsServlet { modifier.setUserId(userId); log.debug("modifier id is {}" , userId); Response response; - ResourceBusinessLogic businessLogic = getResourceBL(context); if (resourceType != null && !ResourceTypeEnum.containsName(resourceType)) { log.debug("invalid resource type received"); @@ -340,7 +349,7 @@ public class ResourcesServlet extends AbstractValidationsServlet { if (resourceType != null) { typeEnum = ResourceTypeEnum.valueOf(resourceType); } - Either, ResponseFormat> actionResponse = businessLogic.validateResourceNameExists(resourceName, typeEnum, userId); + Either, ResponseFormat> actionResponse = resourceBusinessLogic.validateResourceNameExists(resourceName, typeEnum, userId); if (actionResponse.isRight()) { log.debug("failed to validate resource name"); @@ -355,13 +364,10 @@ public class ResourcesServlet extends AbstractValidationsServlet { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response getCertifiedAbstractResources(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug("(get) Start handle request of {}" , url); try { - List resources = getResourceBL(context) + List resources = resourceBusinessLogic .getAllCertifiedResources(true, HighestFilterEnum.HIGHEST_ONLY, userId); return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), RepresentationUtils.toRepresentation(resources)); @@ -377,12 +383,10 @@ public class ResourcesServlet extends AbstractValidationsServlet { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response getCertifiedNotAbstractResources(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("(get) Start handle request of {}" , url); try { - ResourceBusinessLogic businessLogic = getResourceBL(context); - List resouces = businessLogic.getAllCertifiedResources(false, HighestFilterEnum.ALL, userId); + List resouces = resourceBusinessLogic.getAllCertifiedResources(false, HighestFilterEnum.ALL, userId); return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), RepresentationUtils.toRepresentation(resouces)); } catch (IOException e) { @@ -402,8 +406,6 @@ public class ResourcesServlet extends AbstractValidationsServlet { public Response updateResourceMetadata(@PathParam("resourceId") final String resourceId, @ApiParam(value = "Resource metadata to be updated", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}" , url); @@ -413,7 +415,6 @@ public class ResourcesServlet extends AbstractValidationsServlet { log.debug("modifier id is {}", userId); Response response; try { - ResourceBusinessLogic businessLogic = getResourceBL(context); String resourceIdLower = resourceId.toLowerCase(); Either updateInfoResource = getComponentsUtils().convertJsonToObjectUsingObjectMapper(data, modifier, Resource.class, AuditingActionEnum.UPDATE_RESOURCE_METADATA, ComponentTypeEnum.RESOURCE); if (updateInfoResource.isRight()) { @@ -421,7 +422,7 @@ public class ResourcesServlet extends AbstractValidationsServlet { response = buildErrorResponse(updateInfoResource.right().value()); return response; } - Resource updatedResource = businessLogic.updateResourceMetadata(resourceIdLower, updateInfoResource.left().value(), null, modifier, false); + Resource updatedResource = resourceBusinessLogic.updateResourceMetadata(resourceIdLower, updateInfoResource.left().value(), null, modifier, false); Object resource = RepresentationUtils.toRepresentation(updatedResource); return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), resource); } catch (IOException e) { @@ -445,7 +446,6 @@ public class ResourcesServlet extends AbstractValidationsServlet { userId = (userId != null) ? userId : request.getHeader(Constants.USER_ID_HEADER); init(); - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}" , url); // get modifier id @@ -459,14 +459,13 @@ public class ResourcesServlet extends AbstractValidationsServlet { if (isUIImport(data)) { performUIImport(responseWrapper, data, request, userId, resourceId); } else { - ResourceBusinessLogic businessLogic = getResourceBL(context); Either convertResponse = parseToLightResource(data, modifier); if (convertResponse.isRight()) { log.debug("failed to parse resource"); response = buildErrorResponse(convertResponse.right().value()); return response; } - Resource updatedResource = businessLogic.validateAndUpdateResourceFromCsar(convertResponse.left().value(), modifier, null, null, resourceId); + Resource updatedResource = resourceBusinessLogic.validateAndUpdateResourceFromCsar(convertResponse.left().value(), modifier, null, null, resourceId); Object representation = RepresentationUtils.toRepresentation(updatedResource); response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation); responseWrapper.setInnerElement(response); @@ -491,8 +490,6 @@ public class ResourcesServlet extends AbstractValidationsServlet { init(); - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}" , url); @@ -507,9 +504,7 @@ public class ResourcesServlet extends AbstractValidationsServlet { try { - ResourceBusinessLogic businessLogic = getResourceBL(context); - - Either eitherResource = businessLogic.getLatestResourceFromCsarUuid(csarUUID, user); + Either eitherResource = resourceBusinessLogic.getLatestResourceFromCsarUuid(csarUUID, user); // validate response if (eitherResource.isRight()) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceConsumptionServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceConsumptionServlet.java index 9ce5674cc3..f87d7347b0 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceConsumptionServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceConsumptionServlet.java @@ -36,16 +36,20 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import javax.inject.Inject; import org.apache.commons.lang3.StringUtils; import org.json.simple.JSONArray; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic; import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.Operation; import org.openecomp.sdc.be.model.OperationInput; import org.openecomp.sdc.be.model.User; @@ -53,6 +57,7 @@ import org.openecomp.sdc.be.model.tosca.ToscaFunctions; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.types.ServiceConsumptionData; import org.openecomp.sdc.be.types.ServiceConsumptionSource; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.exception.ResponseFormat; import org.slf4j.Logger; @@ -79,6 +84,18 @@ import javax.ws.rs.core.Response; public class ServiceConsumptionServlet extends BeGenericServlet { private static final Logger log = LoggerFactory.getLogger(ServiceConsumptionServlet.class); + private final InterfaceOperationBusinessLogic interfaceOperationBusinessLogic; + private final ServiceBusinessLogic serviceBusinessLogic; + + @Inject + public ServiceConsumptionServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, + InterfaceOperationBusinessLogic interfaceOperationBusinessLogic, + ServiceBusinessLogic serviceBusinessLogic) { + super(userBusinessLogic, componentsUtils); + this.interfaceOperationBusinessLogic = interfaceOperationBusinessLogic; + this.serviceBusinessLogic = serviceBusinessLogic; + } @POST @Path("/services/{serviceId}/consumption/{serviceInstanceId}") @@ -110,12 +127,11 @@ public class ServiceConsumptionServlet extends BeGenericServlet { } Map> serviceConsumptionDataMap = dataFromJson.left().value(); - ServiceBusinessLogic serviceBL = getServiceBL(context); for(Entry> consumptionEntry : serviceConsumptionDataMap.entrySet()) { List consumptionList = consumptionEntry.getValue(); Either, ResponseFormat> operationEither = - serviceBL.addServiceConsumptionData(serviceId, serviceInstanceId, + serviceBusinessLogic.addServiceConsumptionData(serviceId, serviceInstanceId, consumptionEntry.getKey(), consumptionList, userId); if (operationEither.isRight()) { return buildErrorResponse(operationEither.right().value()); @@ -145,24 +161,21 @@ public class ServiceConsumptionServlet extends BeGenericServlet { @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {} modifier id is {}", url, userId); User user = new User(); user.setUserId(userId); try { - InterfaceOperationBusinessLogic interfaceOperationBL = getInterfaceOperationBL(context); Either, ResponseFormat> inputsEither = - interfaceOperationBL.getInputsListForOperation(serviceId, serviceInstanceId, interfaceId, operationId, user); + interfaceOperationBusinessLogic.getInputsListForOperation(serviceId, serviceInstanceId, interfaceId, operationId, user); if(inputsEither.isRight()) { return buildErrorResponse(inputsEither.right().value()); } List inputs = inputsEither.left().value(); - return buildOkResponse(updateOperationInputListForUi(inputs, interfaceOperationBL)); + return buildOkResponse(updateOperationInputListForUi(inputs, interfaceOperationBusinessLogic)); } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Operation Inputs"); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceFilterServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceFilterServlet.java index cfa2fbdf88..08485a2894 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceFilterServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceFilterServlet.java @@ -29,6 +29,7 @@ import io.swagger.annotations.ApiResponses; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import javax.inject.Inject; import javax.inject.Singleton; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; @@ -45,6 +46,9 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.codehaus.jackson.map.ObjectMapper; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic; import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction; import org.openecomp.sdc.be.config.BeEcompErrorManager; @@ -52,11 +56,14 @@ 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.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.tosca.utils.NodeFilterConverter; import org.openecomp.sdc.be.ui.model.UIConstraint; import org.openecomp.sdc.be.ui.model.UINodeFilter; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.exception.ResponseFormat; import org.slf4j.Logger; @@ -77,6 +84,17 @@ public class ServiceFilterServlet extends AbstractValidationsServlet { private static final String NODE_FILTER_CREATION_OR_UPDATE = "Node Filter Creation or update"; private static final String CREATE_OR_UPDATE_NODE_FILTER_WITH_AN_ERROR = "create or update node filter with an error"; + private final ServiceBusinessLogic serviceBusinessLogic; + + @Inject + public ServiceFilterServlet(UserBusinessLogic userBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager, + ServiceBusinessLogic serviceBusinessLogic) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); + this.serviceBusinessLogic = serviceBusinessLogic; + } @POST @Consumes(MediaType.APPLICATION_JSON) @@ -104,7 +122,6 @@ public class ServiceFilterServlet extends AbstractValidationsServlet { try { String serviceIdLower = serviceId.toLowerCase(); - ServiceBusinessLogic businessLogic = getServiceBL(context); Either convertResponse = parseToConstraint(data, modifier); if (convertResponse.isRight()) { @@ -120,7 +137,7 @@ public class ServiceFilterServlet extends AbstractValidationsServlet { } Either actionResponse; String constraint = new ConstraintConvertor().convert(uiConstraint); - actionResponse = businessLogic + actionResponse = serviceBusinessLogic .addOrDeleteServiceFilter(serviceIdLower, ciId, NodeFilterConstraintAction.ADD, uiConstraint.getServicePropertyName(), constraint, -1, modifier, true); @@ -168,7 +185,6 @@ public class ServiceFilterServlet extends AbstractValidationsServlet { try { String serviceIdLower = serviceId.toLowerCase(); - ServiceBusinessLogic businessLogic = getServiceBL(context); Either convertResponse = parseToConstraints(data, modifier); if (convertResponse.isRight()) { @@ -192,7 +208,7 @@ public class ServiceFilterServlet extends AbstractValidationsServlet { } Either actionResponse; List constraints = new ConstraintConvertor().convertToList(uiConstraints); - actionResponse = businessLogic.updateServiceFilter(serviceIdLower, ciId, constraints, modifier, true); + actionResponse = serviceBusinessLogic.updateServiceFilter(serviceIdLower, ciId, constraints, modifier, true); if (actionResponse.isRight()) { log.debug(FAILED_TO_UPDATE_OR_CREATE_NODE_FILTER); @@ -227,7 +243,6 @@ public class ServiceFilterServlet extends AbstractValidationsServlet { @ApiParam(value = "Resource Instance Id") @PathParam("resourceInstanceId") String ciId, @ApiParam(value = "Constraint Index") @PathParam("constraintIndex") int index, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); @@ -239,10 +254,9 @@ public class ServiceFilterServlet extends AbstractValidationsServlet { try { String serviceIdLower = serviceId.toLowerCase(); - ServiceBusinessLogic businessLogic = getServiceBL(context); Either actionResponse; - actionResponse = businessLogic + actionResponse = serviceBusinessLogic .addOrDeleteServiceFilter(serviceIdLower, ciId, NodeFilterConstraintAction.DELETE, null, null, index, modifier, true); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceForwardingPathServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceForwardingPathServlet.java index c97ef42cd5..a9c257f6d1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceForwardingPathServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceForwardingPathServlet.java @@ -25,18 +25,25 @@ import com.google.common.collect.Sets; import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; +import javax.inject.Inject; import org.apache.commons.collections.MapUtils; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer; import org.openecomp.sdc.be.ui.model.UiServiceDataTransfer; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; @@ -60,6 +67,17 @@ import java.util.Set; public class ServiceForwardingPathServlet extends AbstractValidationsServlet { private static final Logger log = Logger.getLogger(ServiceForwardingPathServlet.class); + private final ServiceBusinessLogic serviceBusinessLogic; + + @Inject + public ServiceForwardingPathServlet(UserBusinessLogic userBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager, + ServiceBusinessLogic serviceBusinessLogic) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); + this.serviceBusinessLogic = serviceBusinessLogic; + } @POST @Consumes(MediaType.APPLICATION_JSON) @@ -100,7 +118,6 @@ public class ServiceForwardingPathServlet extends AbstractValidationsServlet { } private Response createOrUpdate( String data, String serviceId, HttpServletRequest request, String userId, boolean isUpdate) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -112,7 +129,6 @@ public class ServiceForwardingPathServlet extends AbstractValidationsServlet { try { String serviceIdLower = serviceId.toLowerCase(); - ServiceBusinessLogic businessLogic = getServiceBL(context); Either convertResponse = parseToService(data, modifier); if (convertResponse.isRight()) { @@ -123,9 +139,9 @@ public class ServiceForwardingPathServlet extends AbstractValidationsServlet { Service updatedService = convertResponse.left().value(); Either actionResponse ; if (isUpdate) { - actionResponse = businessLogic.updateForwardingPath(serviceIdLower, updatedService, modifier, true); + actionResponse = serviceBusinessLogic.updateForwardingPath(serviceIdLower, updatedService, modifier, true); } else { - actionResponse = businessLogic.createForwardingPath(serviceIdLower, updatedService, modifier, true); + actionResponse = serviceBusinessLogic.createForwardingPath(serviceIdLower, updatedService, modifier, true); } if (actionResponse.isRight()) { @@ -163,7 +179,6 @@ public class ServiceForwardingPathServlet extends AbstractValidationsServlet { @ApiParam(value = "Forwarding Path Id") @PathParam("forwardingPathId") String forwardingPathId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -173,8 +188,7 @@ public class ServiceForwardingPathServlet extends AbstractValidationsServlet { try { - ServiceBusinessLogic businessLogic = getServiceBL(context); - Either serviceResponse = businessLogic.getComponentDataFilteredByParams(serviceId, modifier, Collections.singletonList(ComponentFieldsEnum.FORWARDING_PATHS.getValue())); + Either serviceResponse = serviceBusinessLogic.getComponentDataFilteredByParams(serviceId, modifier, Collections.singletonList(ComponentFieldsEnum.FORWARDING_PATHS.getValue())); if (serviceResponse.isRight()) { return buildErrorResponse(serviceResponse.right().value()); } @@ -210,7 +224,6 @@ public class ServiceForwardingPathServlet extends AbstractValidationsServlet { @ApiParam(value = "Service Id") @PathParam("serviceId") String serviceId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -222,9 +235,8 @@ public class ServiceForwardingPathServlet extends AbstractValidationsServlet { try { String serviceIdLower = serviceId.toLowerCase(); - ServiceBusinessLogic businessLogic = getServiceBL(context); - Either, ResponseFormat> actionResponse = businessLogic.deleteForwardingPaths(serviceIdLower, Sets.newHashSet(forwardingPathId), modifier, true); + Either, ResponseFormat> actionResponse = serviceBusinessLogic.deleteForwardingPaths(serviceIdLower, Sets.newHashSet(forwardingPathId), modifier, true); if (actionResponse.isRight()) { log.debug("failed to delete paths"); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java index 2c19c0fc2f..9e960b0d97 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java @@ -24,16 +24,40 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.reflect.TypeToken; import com.jcabi.aspects.Loggable; import fj.data.Either; -import io.swagger.annotations.*; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; import org.apache.http.HttpStatus; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic; import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datamodel.ServiceRelations; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.model.*; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; +import org.openecomp.sdc.be.model.DistributionStatusEnum; +import org.openecomp.sdc.be.model.GroupInstanceProperty; +import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.Service; +import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.datastructure.Wrapper; import org.openecomp.sdc.common.log.wrappers.Logger; @@ -42,7 +66,6 @@ import org.openecomp.sdc.exception.ResponseFormat; import javax.inject.Singleton; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.*; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -58,6 +81,20 @@ import java.util.Map; public class ServiceServlet extends AbstractValidationsServlet { private static final Logger log = Logger.getLogger(ServiceServlet.class); + private final ServiceBusinessLogic serviceBusinessLogic; + private final ResourceBusinessLogic resourceBusinessLogic; + + @Inject + public ServiceServlet(UserBusinessLogic userBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager, + ServiceBusinessLogic serviceBusinessLogic, + ResourceBusinessLogic resourceBusinessLogic) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); + this.serviceBusinessLogic = serviceBusinessLogic; + this.resourceBusinessLogic = resourceBusinessLogic; + } @POST @Path("/services") @@ -68,7 +105,6 @@ public class ServiceServlet extends AbstractValidationsServlet { @ApiResponse(code = 409, message = "Service already exist") }) public Response createService(@ApiParam(value = "Service object to be created", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -78,7 +114,6 @@ public class ServiceServlet extends AbstractValidationsServlet { Response response = null; try { - ServiceBusinessLogic businessLogic = getServiceBL(context); Either convertResponse = parseToService(data, modifier); if (convertResponse.isRight()) { log.debug("failed to parse service"); @@ -87,7 +122,7 @@ public class ServiceServlet extends AbstractValidationsServlet { } Service service = convertResponse.left().value(); - Either actionResponse = businessLogic.createService(service, modifier); + Either actionResponse = serviceBusinessLogic.createService(service, modifier); if (actionResponse.isRight()) { log.debug("Failed to create service"); @@ -118,7 +153,6 @@ public class ServiceServlet extends AbstractValidationsServlet { @ApiOperation(value = "validate service name", httpMethod = "GET", notes = "checks if the chosen service name is available ", response = Response.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Service found"), @ApiResponse(code = 403, message = "Restricted operation") }) public Response validateServiceName(@PathParam("serviceName") final String serviceName, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -128,9 +162,7 @@ public class ServiceServlet extends AbstractValidationsServlet { log.debug("modifier id is {}", userId); Response response = null; try { - ServiceBusinessLogic businessLogic = getServiceBL(context); - - Either, ResponseFormat> actionResponse = businessLogic.validateServiceNameExists(serviceName, userId); + Either, ResponseFormat> actionResponse = serviceBusinessLogic.validateServiceNameExists(serviceName, userId); if (actionResponse.isRight()) { log.debug("failed to get validate service name"); @@ -178,7 +210,7 @@ public class ServiceServlet extends AbstractValidationsServlet { } if (responseWrapper.isEmpty()) { - Either>, ResponseFormat> eitherServiceAudit = getServiceBL(context).getComponentAuditRecords(versionWrapper.getInnerElement(), uuidWrapper.getInnerElement(), userId); + Either>, ResponseFormat> eitherServiceAudit = serviceBusinessLogic.getComponentAuditRecords(versionWrapper.getInnerElement(), uuidWrapper.getInnerElement(), userId); if (eitherServiceAudit.isRight()) { Response errorResponse = buildErrorResponse(eitherServiceAudit.right().value()); @@ -203,7 +235,7 @@ public class ServiceServlet extends AbstractValidationsServlet { private void fillUUIDAndVersion(Wrapper responseWrapper, Wrapper uuidWrapper, Wrapper versionWrapper, User user, final ComponentTypeEnum componentTypeEnum, final String componentUniqueId, ServletContext context) { if (componentTypeEnum == ComponentTypeEnum.RESOURCE) { - Either eitherResource = getResourceBL(context).getResource(componentUniqueId, user); + Either eitherResource = resourceBusinessLogic.getResource(componentUniqueId, user); if (eitherResource.isLeft()) { uuidWrapper.setInnerElement(eitherResource.left().value().getUUID()); versionWrapper.setInnerElement(eitherResource.left().value().getVersion()); @@ -212,7 +244,7 @@ public class ServiceServlet extends AbstractValidationsServlet { } } else { - Either eitherService = getServiceBL(context).getService(componentUniqueId, user); + Either eitherService = serviceBusinessLogic.getService(componentUniqueId, user); if (eitherService.isLeft()) { uuidWrapper.setInnerElement(eitherService.left().value().getUUID()); versionWrapper.setInnerElement(eitherService.left().value().getVersion()); @@ -226,7 +258,6 @@ public class ServiceServlet extends AbstractValidationsServlet { @DELETE @Path("/services/{serviceId}") public Response deleteService(@PathParam("serviceId") final String serviceId, @Context final HttpServletRequest request) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -240,8 +271,7 @@ public class ServiceServlet extends AbstractValidationsServlet { try { String serviceIdLower = serviceId.toLowerCase(); - ServiceBusinessLogic businessLogic = getServiceBL(context); - ResponseFormat actionResponse = businessLogic.deleteService(serviceIdLower, modifier); + ResponseFormat actionResponse = serviceBusinessLogic.deleteService(serviceIdLower, modifier); if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) { log.debug("failed to delete service"); @@ -263,7 +293,6 @@ public class ServiceServlet extends AbstractValidationsServlet { @DELETE @Path("/services/{serviceName}/{version}") public Response deleteServiceByNameAndVersion(@PathParam("serviceName") final String serviceName, @PathParam("version") final String version, @Context final HttpServletRequest request) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -276,8 +305,7 @@ public class ServiceServlet extends AbstractValidationsServlet { Response response = null; try { - ServiceBusinessLogic businessLogic = getServiceBL(context); - ResponseFormat actionResponse = businessLogic.deleteServiceByNameAndVersion(serviceName, version, modifier); + ResponseFormat actionResponse = serviceBusinessLogic.deleteServiceByNameAndVersion(serviceName, version, modifier); if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) { log.debug("failed to delete service"); @@ -317,7 +345,6 @@ public class ServiceServlet extends AbstractValidationsServlet { try { String serviceIdLower = serviceId.toLowerCase(); - ServiceBusinessLogic businessLogic = getServiceBL(context); Either convertResponse = parseToService(data, modifier); if (convertResponse.isRight()) { @@ -326,7 +353,7 @@ public class ServiceServlet extends AbstractValidationsServlet { return response; } Service updatedService = convertResponse.left().value(); - Either actionResponse = businessLogic.updateServiceMetadata(serviceIdLower, updatedService, modifier); + Either actionResponse = serviceBusinessLogic.updateServiceMetadata(serviceIdLower, updatedService, modifier); if (actionResponse.isRight()) { log.debug("failed to update service"); @@ -367,7 +394,6 @@ public class ServiceServlet extends AbstractValidationsServlet { @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { Response response = null; - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -375,7 +401,6 @@ public class ServiceServlet extends AbstractValidationsServlet { modifier.setUserId(userId); log.debug("modifier id is {}",userId); - ServiceBusinessLogic businessLogic; Either, ResponseFormat> actionResponse = null; try { List updatedProperties; @@ -386,8 +411,7 @@ public class ServiceServlet extends AbstractValidationsServlet { } if(actionResponse == null){ log.debug("Start handle update group instance property values request. Received group instance is {}", groupInstanceId); - businessLogic = getServiceBL(context); - actionResponse = businessLogic.updateGroupInstancePropertyValues(modifier, serviceId, componentInstanceId, groupInstanceId, newProperties); + actionResponse = serviceBusinessLogic.updateGroupInstancePropertyValues(modifier, serviceId, componentInstanceId, groupInstanceId, newProperties); if(actionResponse.isRight()){ actionResponse = Either.right(actionResponse.right().value()); } @@ -416,7 +440,6 @@ public class ServiceServlet extends AbstractValidationsServlet { @ApiResponses(value = { @ApiResponse(code = 200, message = "Service found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Service not found") }) public Response getServiceById(@PathParam("serviceId") final String serviceId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -428,9 +451,8 @@ public class ServiceServlet extends AbstractValidationsServlet { Response response = null; try { String serviceIdLower = serviceId.toLowerCase(); - ServiceBusinessLogic businessLogic = getServiceBL(context); log.debug("get service with id {}", serviceId); - Either actionResponse = businessLogic.getService(serviceIdLower, modifier); + Either actionResponse = serviceBusinessLogic.getService(serviceIdLower, modifier); if (actionResponse.isRight()) { log.debug("failed to get service"); @@ -460,7 +482,6 @@ public class ServiceServlet extends AbstractValidationsServlet { public Response getServiceByNameAndVersion(@PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); // get modifier id User modifier = new User(); modifier.setUserId(userId); @@ -468,8 +489,7 @@ public class ServiceServlet extends AbstractValidationsServlet { Response response = null; try { - ServiceBusinessLogic businessLogic = getServiceBL(context); - Either actionResponse = businessLogic.getServiceByNameAndVersion(serviceName, serviceVersion, userId); + Either actionResponse = serviceBusinessLogic.getServiceByNameAndVersion(serviceName, serviceVersion, userId); if (actionResponse.isRight()) { response = buildErrorResponse(actionResponse.right().value()); @@ -499,7 +519,6 @@ public class ServiceServlet extends AbstractValidationsServlet { public Response updateServiceDistributionState(@ApiParam(value = "DistributionChangeInfo - get comment out of body", required = true) LifecycleChangeInfoWithAction jsonChangeInfo, @PathParam("serviceId") final String serviceId, @ApiParam(allowableValues = "approve, reject", required = true) @PathParam("state") final String state, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -509,8 +528,7 @@ public class ServiceServlet extends AbstractValidationsServlet { Response response = null; try { - ServiceBusinessLogic businessLogic = getServiceBL(context); - Either actionResponse = businessLogic.changeServiceDistributionState(serviceId, state, jsonChangeInfo, modifier); + Either actionResponse = serviceBusinessLogic.changeServiceDistributionState(serviceId, state, jsonChangeInfo, modifier); if (actionResponse.isRight()) { log.debug("failed to Update Service Distribution State"); @@ -538,7 +556,6 @@ public class ServiceServlet extends AbstractValidationsServlet { @ApiResponse(code = 500, message = "Internal Server Error. Please try again later.") }) public Response activateDistribution(@PathParam("serviceId") final String serviceId, @PathParam("env") final String env, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -548,8 +565,7 @@ public class ServiceServlet extends AbstractValidationsServlet { Response response = null; try { - ServiceBusinessLogic businessLogic = getServiceBL(context); - Either distResponse = businessLogic.activateDistribution(serviceId, env, modifier, request); + Either distResponse = serviceBusinessLogic.activateDistribution(serviceId, env, modifier, request); if (distResponse.isRight()) { log.debug("failed to activate service distribution"); @@ -576,7 +592,6 @@ public class ServiceServlet extends AbstractValidationsServlet { @ApiResponse(code = 400, message = "Invalid content / Missing content"), @ApiResponse(code = 404, message = "Requested service was not found"), @ApiResponse(code = 500, message = "Internal Server Error. Please try again later.") }) public Response markDistributionAsDeployed(@PathParam("serviceId") final String serviceId, @PathParam("did") final String did, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -586,8 +601,7 @@ public class ServiceServlet extends AbstractValidationsServlet { Response response = null; try { - ServiceBusinessLogic businessLogic = getServiceBL(context); - Either distResponse = businessLogic.markDistributionAsDeployed(serviceId, did, modifier); + Either distResponse = serviceBusinessLogic.markDistributionAsDeployed(serviceId, did, modifier); if (distResponse.isRight()) { log.debug("failed to mark distribution as deployed"); @@ -622,9 +636,8 @@ public class ServiceServlet extends AbstractValidationsServlet { Response response; try { - ServiceBusinessLogic businessLogic = getServiceBL(context); - Service service = (businessLogic.getService(serviceId, modifier)).left().value(); - Either res = businessLogic.updateDistributionStatusForActivation(service, modifier, DistributionStatusEnum.DISTRIBUTED); + Service service = (serviceBusinessLogic.getService(serviceId, modifier)).left().value(); + Either res = serviceBusinessLogic.updateDistributionStatusForActivation(service, modifier, DistributionStatusEnum.DISTRIBUTED); if (res.isRight()) { response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); @@ -647,7 +660,6 @@ public class ServiceServlet extends AbstractValidationsServlet { @ApiResponses(value = { @ApiResponse(code = 200, message = "Service found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Service not found") }) public Response getServiceComponentRelationMap(@PathParam("serviceId") final String serviceId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); @@ -659,9 +671,8 @@ public class ServiceServlet extends AbstractValidationsServlet { Response response = null; try { String serviceIdLower = serviceId.toLowerCase(); - ServiceBusinessLogic businessLogic = getServiceBL(context); log.debug("get service components relations with id {}", serviceId); - Either actionResponse = businessLogic.getServiceComponentsRelations(serviceIdLower, modifier); + Either actionResponse = serviceBusinessLogic.getServiceComponentsRelations(serviceIdLower, modifier); if (actionResponse.isRight()) { log.debug("failed to get service relations data"); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ToscaDaoServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ToscaDaoServlet.java index 82cf0ca59f..1964202297 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ToscaDaoServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ToscaDaoServlet.java @@ -20,44 +20,32 @@ package org.openecomp.sdc.be.servlets; -import org.openecomp.sdc.be.config.BeEcompErrorManager; +import javax.inject.Inject; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.impl.DownloadArtifactLogic; -import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.info.ServletJsonResponse; import org.openecomp.sdc.be.resources.api.IResourceUploader; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; -import org.springframework.web.context.WebApplicationContext; -import javax.servlet.ServletContext; import javax.ws.rs.core.Response; public abstract class ToscaDaoServlet extends BeGenericServlet { public abstract Logger getLogger(); - - protected IResourceUploader getResourceUploader(ServletContext context) { - WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); - - if (webApplicationContextWrapper == null) { - getLogger().error("Failed to get web application context from context."); - return null; - } - - WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); - - return webApplicationContext.getBean(IResourceUploader.class); - - } - - - protected DownloadArtifactLogic getLogic(ServletContext context) { - DownloadArtifactLogic downloadLogic = (DownloadArtifactLogic) context.getAttribute(Constants.DOWNLOAD_ARTIFACT_LOGIC_ATTR); - - if (downloadLogic == null) { - BeEcompErrorManager.getInstance().logBeInitializationError("DownloadArtifactLogic from context"); - return null; - } - return downloadLogic; + protected final IResourceUploader resourceUploader; + protected final DownloadArtifactLogic logic; + + @Inject + public ToscaDaoServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils, + IResourceUploader resourceUploader, + DownloadArtifactLogic logic) { + super(userBusinessLogic, componentsUtils); + this.resourceUploader = resourceUploader; + this.logic = logic; } protected Response buildResponse(int status, String errorMessage) { 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 459629ff26..33df8bc4b6 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,23 +26,31 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import javax.inject.Inject; import org.apache.commons.collections4.ListUtils; import org.openecomp.sdc.be.components.impl.CapabilitiesBusinessLogic; import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic; import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic; import org.openecomp.sdc.be.components.impl.RelationshipTypeBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum; import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.CapabilityTypeDefinition; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.RelationshipTypeDefinition; import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.datastructure.Wrapper; import org.openecomp.sdc.common.log.wrappers.Logger; @@ -73,6 +81,29 @@ public class TypesFetchServlet extends AbstractValidationsServlet { private static final Logger log = Logger.getLogger(TypesFetchServlet.class); private static final String FAILED_TO_GET_ALL_NON_ABSTRACT = "failed to get all non abstract {}"; + private final PropertyBusinessLogic propertyBusinessLogic; + private final RelationshipTypeBusinessLogic relationshipTypeBusinessLogic; + private final CapabilitiesBusinessLogic capabilitiesBusinessLogic; + private final InterfaceOperationBusinessLogic interfaceOperationBusinessLogic; + private final ResourceBusinessLogic resourceBusinessLogic; + + @Inject + public TypesFetchServlet(UserBusinessLogic userBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager, + PropertyBusinessLogic propertyBusinessLogic, + RelationshipTypeBusinessLogic relationshipTypeBusinessLogic, + CapabilitiesBusinessLogic capabilitiesBusinessLogic, + InterfaceOperationBusinessLogic interfaceOperationBusinessLogic, + ResourceBusinessLogic resourceBusinessLogic) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); + this.propertyBusinessLogic = propertyBusinessLogic; + this.relationshipTypeBusinessLogic = relationshipTypeBusinessLogic; + this.capabilitiesBusinessLogic = capabilitiesBusinessLogic; + this.interfaceOperationBusinessLogic = interfaceOperationBusinessLogic; + this.resourceBusinessLogic = resourceBusinessLogic; + } @GET @Path("dataTypes") @@ -85,8 +116,6 @@ public class TypesFetchServlet extends AbstractValidationsServlet { Wrapper responseWrapper = new Wrapper<>(); Wrapper userWrapper = new Wrapper<>(); - ServletContext context = request.getSession().getServletContext(); - try { init(); validateUserExist(responseWrapper, userWrapper, userId); @@ -95,8 +124,8 @@ public class TypesFetchServlet extends AbstractValidationsServlet { String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {} | modifier id is {}", url, userId); - PropertyBusinessLogic businessLogic = getPropertyBL(context); - Either, ResponseFormat> allDataTypes = businessLogic.getAllDataTypes(); + Either, ResponseFormat> allDataTypes = + propertyBusinessLogic.getAllDataTypes(); if (allDataTypes.isRight()) { log.info("Failed to get all dara types. Reason - {}", allDataTypes.right().value()); @@ -137,7 +166,6 @@ public class TypesFetchServlet extends AbstractValidationsServlet { Wrapper responseWrapper = new Wrapper<>(); Wrapper userWrapper = new Wrapper<>(); - ServletContext context = request.getSession().getServletContext(); try { validateUserExist(responseWrapper, userWrapper, userId); @@ -146,9 +174,8 @@ public class TypesFetchServlet extends AbstractValidationsServlet { 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(); + interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(); if (allInterfaceLifecycleTypes.isRight()) { log.info("Failed to get all interface lifecycle types. Reason - {}", @@ -186,7 +213,6 @@ public class TypesFetchServlet extends AbstractValidationsServlet { Wrapper responseWrapper = new Wrapper<>(); Wrapper userWrapper = new Wrapper<>(); - ServletContext context = request.getSession().getServletContext(); try { init(); @@ -196,9 +222,8 @@ public class TypesFetchServlet extends AbstractValidationsServlet { String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {} | modifier id is {}", url, userId); - CapabilitiesBusinessLogic businessLogic = getCapabilitiesBL(context); Either, ResponseFormat> allDataTypes = - businessLogic.getAllCapabilityTypes(); + capabilitiesBusinessLogic.getAllCapabilityTypes(); if (allDataTypes.isRight()) { log.info("Failed to get all capability types. Reason - {}", allDataTypes.right().value()); @@ -240,7 +265,6 @@ public class TypesFetchServlet extends AbstractValidationsServlet { Wrapper responseWrapper = new Wrapper<>(); Wrapper userWrapper = new Wrapper<>(); - ServletContext context = request.getSession().getServletContext(); try { init(); @@ -250,9 +274,8 @@ public class TypesFetchServlet extends AbstractValidationsServlet { String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {} | modifier id is {}", url, userId); - RelationshipTypeBusinessLogic businessLogic = getRelationshipTypeBL(context); Either, ResponseFormat> allDataTypes = - businessLogic.getAllRelationshipTypes(); + relationshipTypeBusinessLogic.getAllRelationshipTypes(); if (allDataTypes.isRight()) { log.info("Failed to get all relationship types. Reason - {}", allDataTypes.right().value()); @@ -304,14 +327,13 @@ public class TypesFetchServlet extends AbstractValidationsServlet { String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {} | modifier id is {}", url, userId); - ComponentBusinessLogic resourceBL = getComponentBL(ComponentTypeEnum.RESOURCE, context); - response = getComponent(resourceBL, true, userId); + response = getComponent(resourceBusinessLogic, true, userId); if (response.isRight()) { return response.right().value(); } componentMap = new HashMap<>(response.left().value()); - response = getComponent(resourceBL, false, userId); + response = getComponent(resourceBusinessLogic, false, userId); if (response.isRight()) { return response.right().value(); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java index 8ecda2ce61..e838dc9a93 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java @@ -24,6 +24,7 @@ import com.google.gson.reflect.TypeToken; import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; +import javax.inject.Inject; import org.apache.commons.lang3.tuple.ImmutablePair; import org.glassfish.jersey.media.multipart.FormDataParam; import org.openecomp.sdc.be.components.impl.*; @@ -31,12 +32,15 @@ import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.GroupTypeDefinition; import org.openecomp.sdc.be.model.PolicyTypeDefinition; import org.openecomp.sdc.be.model.RelationshipTypeDefinition; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.normatives.ToscaTypeMetadata; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.datastructure.FunctionalInterfaces.ConsumerTwoParam; import org.openecomp.sdc.common.datastructure.Wrapper; @@ -75,9 +79,19 @@ public class TypesUploadServlet extends AbstractValidationsServlet { private final PolicyTypeImportManager policyTypeImportManager; private final RelationshipTypeImportManager relationshipTypeImportManager; - public TypesUploadServlet(CapabilityTypeImportManager capabilityTypeImportManager, InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager, CategoriesImportManager categoriesImportManager, DataTypeImportManager dataTypeImportManager, - GroupTypeImportManager groupTypeImportManager, PolicyTypeImportManager policyTypeImportManager, - RelationshipTypeImportManager relationshipTypeImportManager) { + @Inject + public TypesUploadServlet(UserBusinessLogic userBusinessLogic, + ComponentInstanceBusinessLogic componentInstanceBL, + ComponentsUtils componentsUtils, ServletUtils servletUtils, + ResourceImportManager resourceImportManager, + CapabilityTypeImportManager capabilityTypeImportManager, + InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager, + CategoriesImportManager categoriesImportManager, + DataTypeImportManager dataTypeImportManager, + GroupTypeImportManager groupTypeImportManager, + PolicyTypeImportManager policyTypeImportManager, + RelationshipTypeImportManager relationshipTypeImportManager) { + super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); this.capabilityTypeImportManager = capabilityTypeImportManager; this.interfaceLifecycleTypeImportManager = interfaceLifecycleTypeImportManager; this.categoriesImportManager = categoriesImportManager; diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/UserAdminServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/UserAdminServlet.java index 4d886be6c2..328b4a9874 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/UserAdminServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/UserAdminServlet.java @@ -23,8 +23,12 @@ package org.openecomp.sdc.be.servlets; import com.jcabi.aspects.Loggable; import fj.data.Either; import io.swagger.annotations.*; +import javax.inject.Inject; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.user.UserBusinessLogic; @@ -43,6 +47,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.ArrayList; import java.util.List; + @Loggable(prepend = true, value = Loggable.DEBUG, trim = false) @Path("/v1/user") @Api(value = "User Administration", description = "User admininstarator operations") @@ -53,6 +58,14 @@ public class UserAdminServlet extends BeGenericServlet { private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}"; private static final String ROLE_DELIMITER = ","; private static final Logger log = Logger.getLogger(UserAdminServlet.class); + private final UserBusinessLogic userBusinessLogic; + + @Inject + public UserAdminServlet(UserBusinessLogic userBusinessLogic, + ComponentsUtils componentsUtils) { + super(userBusinessLogic, componentsUtils); + this.userBusinessLogic = userBusinessLogic; + } /*************************************** * API start @@ -74,10 +87,8 @@ public class UserAdminServlet extends BeGenericServlet { String url = request.getMethod() + " " + request.getRequestURI(); log.debug("(get) Start handle request of {}", url); - UserBusinessLogic userAdminManager = getUserAdminManager(request.getSession().getServletContext()); - try { - Either either = userAdminManager.getUser(userId, false); + Either either = userBusinessLogic.getUser(userId, false); if (either.isRight()) { return buildErrorResponse(getComponentsUtils().getResponseFormatByUserId(either.right().value(), userId)); @@ -107,10 +118,8 @@ public class UserAdminServlet extends BeGenericServlet { String url = request.getMethod() + " " + request.getRequestURI(); log.debug("(getRole) Start handle request of {}", url); - UserBusinessLogic userAdminManager = getUserAdminManager(request.getSession().getServletContext()); - try { - Either either = userAdminManager.getUser(userId, false); + Either either = userBusinessLogic.getUser(userId, false); if (either.isRight()) { return buildErrorResponse(getComponentsUtils().getResponseFormatByUserId(either.right().value(), userId)); } else { @@ -140,8 +149,6 @@ public class UserAdminServlet extends BeGenericServlet { public Response updateUserRole(@ApiParam(value = "userId of user to get", required = true) @PathParam("userId") final String userIdUpdateUser, @Context final HttpServletRequest request, @ApiParam(value = "json describe the update role", required = true) String data, @HeaderParam(value = Constants.USER_ID_HEADER) String modifierUserId) { - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); @@ -153,9 +160,8 @@ public class UserAdminServlet extends BeGenericServlet { Response response = null; try { - UserBusinessLogic businessLogic = getUserAdminManager(context); User updateInfoUser = getComponentsUtils().convertJsonToObject(data, modifier, User.class, AuditingActionEnum.UPDATE_USER).left().value(); - Either updateUserResponse = businessLogic.updateUserRole(modifier, userIdUpdateUser, updateInfoUser.getRole()); + Either updateUserResponse = userBusinessLogic.updateUserRole(modifier, userIdUpdateUser, updateInfoUser.getRole()); if (updateUserResponse.isRight()) { log.debug("failed to update user role"); @@ -185,8 +191,6 @@ public class UserAdminServlet extends BeGenericServlet { @ApiResponse(code = 405, message = "Method Not Allowed"), @ApiResponse(code = 409, message = "User already exists"), @ApiResponse(code = 500, message = "Internal Server Error") }) public Response createUser(@Context final HttpServletRequest request, @ApiParam(value = "json describe the user", required = true) String newUserData, @HeaderParam(value = Constants.USER_ID_HEADER) String modifierAttId) { - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); @@ -198,9 +202,8 @@ public class UserAdminServlet extends BeGenericServlet { Response response = null; try { - UserBusinessLogic businessLogic = getUserAdminManager(context); User newUserInfo = getComponentsUtils().convertJsonToObject(newUserData, modifier, User.class, AuditingActionEnum.ADD_USER).left().value(); - Either createUserResponse = businessLogic.createUser(modifier, newUserInfo); + Either createUserResponse = userBusinessLogic.createUser(modifier, newUserInfo); if (createUserResponse.isRight()) { log.debug("failed to create user"); @@ -247,7 +250,6 @@ public class UserAdminServlet extends BeGenericServlet { return buildErrorResponse(errorResponseWrapper); } - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); @@ -260,8 +262,7 @@ public class UserAdminServlet extends BeGenericServlet { Response response = null; try { - UserBusinessLogic userAdminManager = getUserAdminManager(context); - Either authorize = userAdminManager.authorize(authUser); + Either authorize = userBusinessLogic.authorize(authUser); if (authorize.isRight()) { log.debug("authorize user failed"); @@ -290,10 +291,8 @@ public class UserAdminServlet extends BeGenericServlet { String url = request.getMethod() + " " + request.getRequestURI(); log.debug("(get) Start handle request of {}", url); - UserBusinessLogic userAdminManager = getUserAdminManager(request.getSession().getServletContext()); - try { - Either, ResponseFormat> either = userAdminManager.getAllAdminUsers(); + Either, ResponseFormat> either = userBusinessLogic.getAllAdminUsers(); if (either.isRight()) { log.debug("Failed to get all admin users"); @@ -322,7 +321,6 @@ public class UserAdminServlet extends BeGenericServlet { public Response getUsersList(@Context final HttpServletRequest request, @ApiParam(value = "Any active user's USER_ID ") @HeaderParam(Constants.USER_ID_HEADER) final String userId, @ApiParam(value = "TESTER,DESIGNER,PRODUCT_STRATEGIST,OPS,PRODUCT_MANAGER,GOVERNOR, ADMIN OR all users by not typing anything") @QueryParam("roles") final String roles) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {} modifier id is {}", url, userId); @@ -335,8 +333,7 @@ public class UserAdminServlet extends BeGenericServlet { } try { - UserBusinessLogic userAdminManager = getUserAdminManager(context); - Either, ResponseFormat> either = userAdminManager.getUsersList(userId, rolesList, roles); + Either, ResponseFormat> either = userBusinessLogic.getUsersList(userId, rolesList, roles); if (either.isRight()) { log.debug("Failed to get ASDC users"); @@ -363,7 +360,6 @@ public class UserAdminServlet extends BeGenericServlet { @ApiResponse(code = 404, message = "User not found"), @ApiResponse(code = 405, message = "Method Not Allowed"), @ApiResponse(code = 409, message = "Restricted operation"), @ApiResponse(code = 500, message = "Internal Server Error") }) public Response deActivateUser(@ApiParam(value = "userId of user to get", required = true) @PathParam("userId") final String userId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userIdHeader) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {} modifier id is {}", url, userIdHeader); @@ -372,8 +368,7 @@ public class UserAdminServlet extends BeGenericServlet { Response response = null; try { - UserBusinessLogic userAdminManager = getUserAdminManager(context); - Either deactiveUserResponse = userAdminManager.deActivateUser(modifier, userId); + Either deactiveUserResponse = userBusinessLogic.deActivateUser(modifier, userId); if (deactiveUserResponse.isRight()) { log.debug("Failed to deactivate user"); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/servlet/DistributionServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/servlet/DistributionServletTest.java index bb1e663363..a33b24d5da 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/servlet/DistributionServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/servlet/DistributionServletTest.java @@ -20,8 +20,18 @@ package org.openecomp.sdc.be.distribution.servlet; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Application; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.apache.http.HttpStatus; import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.server.ResourceConfig; @@ -33,13 +43,17 @@ import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.openecomp.sdc.be.components.distribution.engine.DistributionEngine; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.config.SpringConfig; import org.openecomp.sdc.be.distribution.AuditHandler; import org.openecomp.sdc.be.distribution.DistributionBusinessLogic; import org.openecomp.sdc.be.distribution.api.client.RegistrationRequest; import org.openecomp.sdc.be.distribution.api.client.TopicRegistrationResponse; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.datastructure.Wrapper; import org.openecomp.sdc.common.impl.ExternalConfiguration; @@ -48,18 +62,6 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.web.context.WebApplicationContext; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.Application; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; - public class DistributionServletTest extends JerseyTest { public static final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); @@ -84,7 +86,6 @@ public class DistributionServletTest extends JerseyTest { when(session.getServletContext()).thenReturn(servletContext); when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper); when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext); - when(webApplicationContext.getBean(DistributionBusinessLogic.class)).thenReturn(distributionBusinessLogic); when(distributionBusinessLogic.getDistributionEngine()).thenReturn(distributionEngine); when(distributionEngine.isEnvironmentAvailable(ENV_NAME)).thenReturn(StorageOperationStatus.OK); when(distributionEngine.isEnvironmentAvailable()).thenReturn(StorageOperationStatus.OK); @@ -145,6 +146,11 @@ public class DistributionServletTest extends JerseyTest { @Override protected Application configure() { + UserBusinessLogic userBusinessLogic = Mockito.mock(UserBusinessLogic.class); + GroupBusinessLogic groupBusinessLogic = Mockito.mock(GroupBusinessLogic.class); + ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class); + ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class); + ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class); forceSet(TestProperties.CONTAINER_PORT, "0"); return new ResourceConfig(DistributionServlet.class) @@ -153,6 +159,11 @@ public class DistributionServletTest extends JerseyTest { @Override protected void configure() { bind(request).to(HttpServletRequest.class); + bind(userBusinessLogic).to(UserBusinessLogic.class); + bind(groupBusinessLogic).to(GroupBusinessLogic.class); + bind(componentInstanceBusinessLogic).to(ComponentInstanceBusinessLogic.class); + bind(componentsUtils).to(ComponentsUtils.class); + bind(distributionBusinessLogic).to(DistributionBusinessLogic.class); } }) .property("contextConfig", context); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServletTest.java index fa700a8dc5..24f06b4543 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServletTest.java @@ -33,9 +33,11 @@ import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mockito; import org.mockito.stubbing.Answer; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.ElementBusinessLogic; import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic; import org.openecomp.sdc.be.components.impl.ResourceImportManager; +import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; import org.openecomp.sdc.be.config.SpringConfig; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; @@ -47,6 +49,7 @@ import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.category.CategoryDefinition; import org.openecomp.sdc.be.model.category.SubCategoryDefinition; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.datastructure.FunctionalInterfaces; import org.openecomp.sdc.common.impl.ExternalConfiguration; @@ -65,7 +68,6 @@ import javax.ws.rs.core.Response; import java.util.Arrays; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; public class AssetsDataServletTest extends JerseyTest { @@ -85,9 +87,10 @@ public class AssetsDataServletTest extends JerseyTest { public static final CategoryDefinition categoryDefinition = Mockito.mock(CategoryDefinition.class); public static final SubCategoryDefinition subCategoryDefinition = Mockito.mock(SubCategoryDefinition.class); public static final AssetMetadataConverter assetMetadataConverter = Mockito.mock(AssetMetadataConverter.class); -// public static final ResourceAssetMetadata resourceAssetMetadata = Mockito.mock(ResourceAssetMetadata.class); - public static final ResourceAssetMetadata resourceAssetMetadata = new ResourceAssetMetadata();; - + public static final ResourceAssetMetadata resourceAssetMetadata = new ResourceAssetMetadata(); + public static final UserBusinessLogic userBusinessLogic = Mockito.mock(UserBusinessLogic.class); + public static final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class); + public static final LifecycleBusinessLogic lifecycleBusinessLogic = Mockito.mock(LifecycleBusinessLogic.class); @@ -157,7 +160,7 @@ public class AssetsDataServletTest extends JerseyTest { final JSONObject createRequest = buildCreateJsonRequest(); Response response = target().path("/v1/catalog/resources").request(MediaType.APPLICATION_JSON).header(Constants.X_ECOMP_INSTANCE_ID_HEADER, "mockXEcompInstanceId").header(Constants.USER_ID_HEADER, "mockAttID") .post(Entity.json(createRequest.toJSONString()), Response.class); - assertEquals(response.getStatus(), HttpStatus.SC_CREATED); + assertEquals(HttpStatus.SC_CREATED, response.getStatus()); } private static final String BASIC_CREATE_REQUEST = "{\r\n" + @@ -191,8 +194,17 @@ public class AssetsDataServletTest extends JerseyTest { @Override protected void configure() { bind(request).to(HttpServletRequest.class); + bind(userBusinessLogic).to(UserBusinessLogic.class); + bind(componentInstanceBusinessLogic).to(ComponentInstanceBusinessLogic.class); + bind(componentsUtils).to(ComponentsUtils.class); + bind(servletUtils).to(ServletUtils.class); + bind(resourceImportManager).to(ResourceImportManager.class); + bind(elementBusinessLogic).to(ElementBusinessLogic.class); + bind(assetMetadataConverter).to(AssetMetadataConverter.class); + bind(lifecycleBusinessLogic).to(LifecycleBusinessLogic.class); + bind(resourceBusinessLogic).to(ResourceBusinessLogic.class); } }) .property("contextConfig", context); } -} +} \ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefServletTest.java index 8036213f1e..97f15022c0 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefServletTest.java @@ -135,11 +135,10 @@ public class ExternalRefServletTest extends JerseyTest { private GraphVertex resourceVertex; private ExternalReferencesOperation externalReferenceOperation; private HealingJanusGraphDao janusGraphDao; - private OperationUtils operationUtils; @Bean ExternalRefsServlet externalRefsServlet() { - return new ExternalRefsServlet(externalRefsBusinessLogic(), componentUtils); + return new ExternalRefsServlet(userAdmin, componentUtils, externalRefsBusinessLogic()); } @Bean diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AbstractValidationsServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AbstractValidationsServletTest.java index 70a7fe898a..5158c438df 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AbstractValidationsServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AbstractValidationsServletTest.java @@ -23,8 +23,16 @@ package org.openecomp.sdc.be.servlets; import fj.data.Either; import org.apache.commons.codec.binary.Base64; import org.junit.Test; +import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; +import org.openecomp.sdc.be.externalapi.servlet.ArtifactExternalServlet; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.UploadResourceInfo; import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.datastructure.Wrapper; import org.openecomp.sdc.exception.ResponseFormat; @@ -40,9 +48,18 @@ import java.util.stream.Stream; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; public class AbstractValidationsServletTest { - private static AbstractValidationsServlet servlet = new AbstractValidationsServlet() {}; + private static UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); + private static ComponentInstanceBusinessLogic componentInstanceBL = mock(ComponentInstanceBusinessLogic.class); + private static ComponentsUtils componentsUtils = mock(ComponentsUtils.class); + private static ServletUtils servletUtils = mock(ServletUtils.class); + private static ResourceImportManager resourceImportManager = mock(ResourceImportManager.class); + private static ArtifactsBusinessLogic artifactsBusinessLogic = mock(ArtifactsBusinessLogic.class); + + private static AbstractValidationsServlet servlet = new ArtifactExternalServlet(userBusinessLogic, + componentInstanceBL, componentsUtils, servletUtils, resourceImportManager, artifactsBusinessLogic); private static final String BASIC_TOSCA_TEMPLATE = "tosca_definitions_version: tosca_simple_yaml_%s"; diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AdditionalInformationServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AdditionalInformationServletTest.java index b0306ce86b..e49420ef3b 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AdditionalInformationServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AdditionalInformationServletTest.java @@ -20,16 +20,28 @@ package org.openecomp.sdc.be.servlets; +import static org.mockito.Mockito.mock; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.junit.Test; +import org.openecomp.sdc.be.components.impl.AdditionalInformationBusinessLogic; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.user.UserBusinessLogic; public class AdditionalInformationServletTest { private AdditionalInformationServlet createTestSubject() { - return new AdditionalInformationServlet(); + UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); + ComponentsUtils componentsUtils = mock(ComponentsUtils.class); + AdditionalInformationBusinessLogic additionalInformationBusinessLogic = + mock(AdditionalInformationBusinessLogic.class); + return new AdditionalInformationServlet(userBusinessLogic, componentsUtils, + additionalInformationBusinessLogic); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArchiveEndpointTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArchiveEndpointTest.java index 50cd2570b9..2636048408 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArchiveEndpointTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArchiveEndpointTest.java @@ -317,7 +317,7 @@ public class ArchiveEndpointTest extends JerseyTest { when(userAdmin.getUser(otherUser.getUserId(), false)).thenReturn(otherEither); //======================================================================================================================== - String appConfigDir = "src/test/resources/config"; + String appConfigDir = "src/test/resources/config/catalog-be"; ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir); ConfigurationManager configurationManager = new ConfigurationManager(configurationSource); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArtifactServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArtifactServletTest.java index 0e66d83f18..74a6555eca 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArtifactServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArtifactServletTest.java @@ -20,16 +20,27 @@ package org.openecomp.sdc.be.servlets; +import static org.mockito.Mockito.mock; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.junit.Test; +import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.ConsumerBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.user.UserBusinessLogic; public class ArtifactServletTest { private ArtifactServlet createTestSubject() { - return new ArtifactServlet(); + UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); + ComponentsUtils componentsUtils = mock(ComponentsUtils.class); + ArtifactsBusinessLogic artifactsBusinessLogic = mock(ArtifactsBusinessLogic.class); + return new ArtifactServlet(userBusinessLogic, componentsUtils,artifactsBusinessLogic); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AttributeServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AttributeServletTest.java index 196d47a3a3..47d2cf4f2f 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AttributeServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AttributeServletTest.java @@ -20,11 +20,19 @@ package org.openecomp.sdc.be.servlets; +import static org.mockito.Mockito.mock; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.junit.Test; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.PropertyDefinition; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.exception.ResponseFormat; import com.google.common.base.Equivalence.Wrapper; @@ -32,7 +40,14 @@ import com.google.common.base.Equivalence.Wrapper; public class AttributeServletTest { private AttributeServlet createTestSubject() { - return new AttributeServlet(); + UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); + ComponentInstanceBusinessLogic componentInstanceBL = mock(ComponentInstanceBusinessLogic.class); + ComponentsUtils componentsUtils = mock(ComponentsUtils.class); + ServletUtils servletUtils = mock(ServletUtils.class); + ResourceImportManager resourceImportManager = mock(ResourceImportManager.class); + + return new AttributeServlet(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, + resourceImportManager); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AutomatedUpgradeEndpointTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AutomatedUpgradeEndpointTest.java index 9e3e9c9dbb..3f07d95096 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AutomatedUpgradeEndpointTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AutomatedUpgradeEndpointTest.java @@ -30,6 +30,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction; import org.openecomp.sdc.be.components.upgrade.ServiceInfo; @@ -47,6 +48,7 @@ import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.UpgradeOperation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.ConfigurationSource; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.impl.ExternalConfiguration; @@ -111,7 +113,12 @@ public class AutomatedUpgradeEndpointTest extends JerseySpringBaseTest { @Bean AutomatedUpgradeEndpoint automatedUpgradeEndpoint() { - return new AutomatedUpgradeEndpoint(upgradeBusinessLogic()); + + UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); + ComponentsUtils componentsUtils = mock(ComponentsUtils.class); + + return new AutomatedUpgradeEndpoint(userBusinessLogic, componentsUtils, + upgradeBusinessLogic()); } @Bean diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceServletTest.java index f9336aa8be..ca407eaed0 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceServletTest.java @@ -36,6 +36,9 @@ import org.junit.Test; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; +import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic; import org.openecomp.sdc.be.config.SpringConfig; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; @@ -46,6 +49,7 @@ import org.openecomp.sdc.be.model.CapabilityDefinition; import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.RequirementCapabilityRelDef; import org.openecomp.sdc.be.model.RequirementDefinition; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.context.ApplicationContext; @@ -82,6 +86,10 @@ public class ComponentInstanceServletTest extends JerseyTest { private static ComponentsUtils componentsUtils; private static ServletUtils servletUtils; private static ResponseFormat responseFormat; + private static UserBusinessLogic userBusinessLogic; + private static GroupBusinessLogic groupBusinessLogic; + private static ResourceImportManager resourceImportManager; + private static ServiceBusinessLogic serviceBusinessLogic; @BeforeClass public static void setup() { @@ -271,6 +279,13 @@ public class ComponentInstanceServletTest extends JerseyTest { @Override protected void configure() { bind(request).to(HttpServletRequest.class); + bind(userBusinessLogic).to(UserBusinessLogic.class); + bind(groupBusinessLogic).to(GroupBusinessLogic.class); + bind(componentInstanceBusinessLogic).to(ComponentInstanceBusinessLogic.class); + bind(componentsUtils).to(ComponentsUtils.class); + bind(servletUtils).to(ServletUtils.class); + bind(resourceImportManager).to(ResourceImportManager.class); + bind(serviceBusinessLogic).to(ServiceBusinessLogic.class); } }) .property("contextConfig", context); @@ -282,10 +297,14 @@ public class ComponentInstanceServletTest extends JerseyTest { servletContext = Mockito.mock(ServletContext.class); webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class); webApplicationContext = Mockito.mock(WebApplicationContext.class); + userBusinessLogic = Mockito.mock(UserBusinessLogic.class); + groupBusinessLogic = Mockito.mock(GroupBusinessLogic.class); + resourceImportManager = Mockito.mock(ResourceImportManager.class); componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class); componentsUtils = Mockito.mock(ComponentsUtils.class); servletUtils = Mockito.mock(ServletUtils.class); responseFormat = Mockito.mock(ResponseFormat.class); + serviceBusinessLogic = Mockito.mock(ServiceBusinessLogic.class); } private static void stubMethods() { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentPropertyServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentPropertyServletTest.java index f736cf46e7..4fcbd06927 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentPropertyServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentPropertyServletTest.java @@ -72,11 +72,6 @@ public class ComponentPropertyServletTest extends JerseySpringBaseTest { private static final String INVALID_PROPERTY_NAME = "invalid_name_$.&"; private static final String STRING_TYPE = "string"; - @Before - public void initClass() { - initMockitoStubbings(); - } - @Test public void testCreatePropertyOnService_success() { PropertyDefinition property = new PropertyDefinition(); @@ -110,15 +105,6 @@ public class ComponentPropertyServletTest extends JerseySpringBaseTest { Assert.assertEquals(HttpStatus.BAD_REQUEST_400.getStatusCode(), propertyInService.getStatus()); } - private static void initMockitoStubbings() { - when(request.getSession()).thenReturn(session); - when(session.getServletContext()).thenReturn(context); - when(context.getAttribute(eq(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR))).thenReturn(wrapper); - when(wrapper.getWebAppContext(any())).thenReturn(webAppContext); - when(webAppContext.getBean(eq(PropertyBusinessLogic.class))).thenReturn(propertyBl); - when(webAppContext.getBean(eq(ComponentsUtils.class))).thenReturn(componentsUtils); - } - private String getValidProperty() { return "{\n" + " \"valid_name_123\": {\n" diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentServletTest.java index 9921561068..8f823c3a7c 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentServletTest.java @@ -27,11 +27,15 @@ import org.json.JSONObject; import org.junit.Before; import org.junit.Test; import org.openecomp.sdc.be.components.impl.ComponentBusinessLogicProvider; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic; import org.openecomp.sdc.be.components.utils.PolicyDefinitionBuilder; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.PolicyDefinition; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import javax.ws.rs.client.Invocation; @@ -51,6 +55,8 @@ public class ComponentServletTest extends JerseySpringBaseTest{ private static final String USER_ID = "userId"; private static final String RESOURCE_ID = "resourceId"; private ResourceBusinessLogic resourceBusinessLogic; + private UserBusinessLogic userBusinessLogic; + private ComponentsUtils componentsUtils; private PolicyDefinition policy1, policy2; @Override @@ -64,7 +70,10 @@ public class ComponentServletTest extends JerseySpringBaseTest{ @Override protected ResourceConfig configure() { resourceBusinessLogic = mock(ResourceBusinessLogic.class); - ComponentServlet componentServlet = new ComponentServlet(new ComponentBusinessLogicProvider(resourceBusinessLogic, null, null)); + userBusinessLogic = mock(UserBusinessLogic.class); + componentsUtils = mock(ComponentsUtils.class); + ComponentServlet componentServlet = new ComponentServlet(userBusinessLogic, componentsUtils, + new ComponentBusinessLogicProvider(resourceBusinessLogic, null, null)); return super.configure().register(componentServlet); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ConsumerServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ConsumerServletTest.java index a2ba87d3d8..6aa11a6366 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ConsumerServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ConsumerServletTest.java @@ -20,15 +20,21 @@ package org.openecomp.sdc.be.servlets; +import static org.mockito.Mockito.mock; + import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.junit.Test; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.ConsumerBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.ConsumerDefinition; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.exception.ResponseFormat; import fj.data.Either; @@ -36,7 +42,10 @@ import fj.data.Either; public class ConsumerServletTest { private ConsumerServlet createTestSubject() { - return new ConsumerServlet(); + UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); + ComponentsUtils componentsUtils = mock(ComponentsUtils.class); + ConsumerBusinessLogic consumerBusinessLogic = mock(ConsumerBusinessLogic.class); + return new ConsumerServlet(userBusinessLogic, componentsUtils, consumerBusinessLogic); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/CsarBuildServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/CsarBuildServletTest.java index 001d5c8d5f..6d820841f0 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/CsarBuildServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/CsarBuildServletTest.java @@ -20,16 +20,32 @@ package org.openecomp.sdc.be.servlets; +import static org.mockito.Mockito.mock; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.junit.Test; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.DownloadArtifactLogic; +import org.openecomp.sdc.be.impl.ServletUtils; +import org.openecomp.sdc.be.resources.api.IResourceUploader; +import org.openecomp.sdc.be.user.UserBusinessLogic; public class CsarBuildServletTest { private CsarBuildServlet createTestSubject() { - return new CsarBuildServlet(); + UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); + ComponentsUtils componentsUtils = mock(ComponentsUtils.class); + IResourceUploader resourceUploader = mock(IResourceUploader.class); + DownloadArtifactLogic logic = mock(DownloadArtifactLogic.class); + + return new CsarBuildServlet(userBusinessLogic, componentsUtils, resourceUploader, + logic); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/DistributionServiceServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/DistributionServiceServletTest.java index c41e1fd21f..df26749ef0 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/DistributionServiceServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/DistributionServiceServletTest.java @@ -20,17 +20,27 @@ package org.openecomp.sdc.be.servlets; +import static org.mockito.Mockito.mock; + import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.junit.Test; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.DistributionMonitoringBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.user.UserBusinessLogic; public class DistributionServiceServletTest { private DistributionServiceServlet createTestSubject() { - return new DistributionServiceServlet(); + UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); + ComponentsUtils componentsUtils = mock(ComponentsUtils.class); + DistributionMonitoringBusinessLogic distributionMonitoringLogic = mock(DistributionMonitoringBusinessLogic.class); + return new DistributionServiceServlet(userBusinessLogic, componentsUtils, + distributionMonitoringLogic); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java index 7d3eca8f16..ac17e2bf6b 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java @@ -20,18 +20,31 @@ package org.openecomp.sdc.be.servlets; +import static org.mockito.Mockito.mock; + import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.junit.Test; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.ConsumerBusinessLogic; +import org.openecomp.sdc.be.components.impl.ElementBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic; import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.user.UserBusinessLogic; public class ElementServletTest { private ElementServlet createTestSubject() { - return new ElementServlet(); + UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); + ComponentsUtils componentsUtils = mock(ComponentsUtils.class); + ComponentsCleanBusinessLogic componentsCleanBusinessLogic = mock(ComponentsCleanBusinessLogic.class); + ElementBusinessLogic elementBusinessLogic = mock(ElementBusinessLogic.class); + return new ElementServlet(userBusinessLogic, componentsUtils, componentsCleanBusinessLogic, elementBusinessLogic); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/GroupServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/GroupServletTest.java index b6fab7864a..01383eae14 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/GroupServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/GroupServletTest.java @@ -20,15 +20,32 @@ package org.openecomp.sdc.be.servlets; +import static org.mockito.Mockito.mock; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.junit.Test; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.DownloadArtifactLogic; +import org.openecomp.sdc.be.impl.ServletUtils; +import org.openecomp.sdc.be.resources.api.IResourceUploader; +import org.openecomp.sdc.be.user.UserBusinessLogic; public class GroupServletTest { private GroupServlet createTestSubject() { - return new GroupServlet(); + UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); + GroupBusinessLogic groupBL = mock(GroupBusinessLogic.class); + ComponentInstanceBusinessLogic componentInstanceBL = mock(ComponentInstanceBusinessLogic.class); + ComponentsUtils componentsUtils = mock(ComponentsUtils.class); + ServletUtils servletUtils = mock(ServletUtils.class); + ResourceImportManager resourceImportManager = mock(ResourceImportManager.class); + return new GroupServlet(userBusinessLogic, groupBL, componentInstanceBL, componentsUtils, servletUtils, + resourceImportManager); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/InputsServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/InputsServletTest.java index 07184704d4..da5352c206 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/InputsServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/InputsServletTest.java @@ -21,14 +21,24 @@ package org.openecomp.sdc.be.servlets; import fj.data.Either; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.Application; +import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.grizzly.http.util.HttpStatus; +import org.glassfish.jersey.test.JerseyTest; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.DataTypeBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.impl.InputsBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder; +import org.openecomp.sdc.be.config.SpringConfig; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; @@ -43,8 +53,11 @@ import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.exception.ResponseFormat; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.web.context.WebApplicationContext; import javax.servlet.ServletContext; @@ -64,7 +77,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; -public class InputsServletTest extends JerseySpringBaseTest { +public class InputsServletTest extends JerseyTest { /* Constants */ private static final String RESOURCE_ID = "serviceId"; @@ -79,62 +92,78 @@ public class InputsServletTest extends JerseySpringBaseTest { private static final String LISTINPUT_PROP2_NAME = "prop2"; private static final String LISTINPUT_PROP2_TYPE = "integer"; - /* Test subject */ - private InputsServletForTest testSubject; - /* Mocks */ - private InputsBusinessLogic inputsBusinessLogic; - private DataTypeBusinessLogic dataTypeBusinessLogic; - private HttpSession httpSession; - private ServletContext servletContext; - private WebApplicationContext webApplicationContext; - private ComponentsUtils componentsUtils; - private ServletUtils servletUtils; - - /** - * This class extends the original InputsServlet - * and provides methods to inject mocks - */ - class InputsServletForTest extends InputsServlet { - public void setComponentsUtils(ComponentsUtils componentsUtils) { - this.componentsUtils = componentsUtils; - } - - public void setServletUtils(ServletUtils servletUtils) { - this.servletUtils = servletUtils; - } - } - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); + private static UserBusinessLogic userBusinessLogic; + private static InputsBusinessLogic inputsBusinessLogic; + private static DataTypeBusinessLogic dataTypeBusinessLogic; + private static GroupBusinessLogic groupBL; + private static ComponentInstanceBusinessLogic componentInstanceBL; + private static HttpSession httpSession; + private static ServletContext servletContext; + private static WebApplicationContext webApplicationContext; + private static ComponentsUtils componentsUtils; + private static ServletUtils servletUtils; + private static ResourceImportManager resourceImportManager; + private static HttpServletRequest request; + + @BeforeClass + public static void configureMocks() { + request = mock(HttpServletRequest.class); + userBusinessLogic = mock(UserBusinessLogic.class); inputsBusinessLogic = mock(InputsBusinessLogic.class); + groupBL = mock(GroupBusinessLogic.class); + componentInstanceBL = mock(ComponentInstanceBusinessLogic.class); dataTypeBusinessLogic = mock(DataTypeBusinessLogic.class); servletContext = mock(ServletContext.class); httpSession = mock(HttpSession.class); webApplicationContext = mock(WebApplicationContext.class); componentsUtils = mock(ComponentsUtils.class); servletUtils = mock(ServletUtils.class); + resourceImportManager = mock(ResourceImportManager.class); + } + + @Before + public void resetMocks() { + Mockito.reset(resourceImportManager); + Mockito.reset(servletUtils); + Mockito.reset(componentsUtils); + Mockito.reset(webApplicationContext); + Mockito.reset(httpSession); + Mockito.reset(servletContext); + Mockito.reset(dataTypeBusinessLogic); + Mockito.reset(componentInstanceBL); + Mockito.reset(groupBL); + Mockito.reset(inputsBusinessLogic); + Mockito.reset(userBusinessLogic); + Mockito.reset(request); + when(request.getSession()).thenReturn(httpSession); when(httpSession.getServletContext()).thenReturn(servletContext); - when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(new WebAppContextWrapper()); + when(servletContext.getAttribute( + Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(new WebAppContextWrapper()); when(servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)).thenReturn(webApplicationContext); - when(webApplicationContext.getBean(InputsBusinessLogic.class)).thenReturn(inputsBusinessLogic); - when(webApplicationContext.getBean(DataTypeBusinessLogic.class)).thenReturn(dataTypeBusinessLogic); - testSubject.setComponentsUtils(componentsUtils); - testSubject.setServletUtils(servletUtils); when(servletUtils.getComponentsUtils()).thenReturn(componentsUtils); } - @Override - protected ResourceConfig configure() { - testSubject = new InputsServletForTest(); - return super.configure().register(testSubject); + protected Application configure() { + InputsServlet inputsServlet = new InputsServlet(userBusinessLogic, inputsBusinessLogic, + componentInstanceBL, componentsUtils, + servletUtils, resourceImportManager, dataTypeBusinessLogic); + ResourceConfig resourceConfig = new ResourceConfig() + .register(inputsServlet) + .register(new AbstractBinder() { + @Override + protected void configure() { + bind(request).to(HttpServletRequest.class); + } + }); + + ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class); + resourceConfig.property("contextConfig", context); + return resourceConfig; } - private InputDefinition setUpListInput() { InputDefinition listInput = new InputDefinition(); listInput.setName(LISTINPUT_NAME); @@ -184,15 +213,14 @@ public class InputsServletTest extends JerseySpringBaseTest { ComponentInstListInput requestBodyObj = setUpCreateListInputParams(); Entity entity = Entity.entity(requestBodyObj, MediaType.APPLICATION_JSON); - // for parseToComponentInstListInput - when(componentsUtils.convertJsonToObjectUsingObjectMapper(any(), any(), eq(ComponentInstListInput.class), - eq(AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.SERVICE))) - .thenReturn(Either.left(requestBodyObj)); + doReturn(Either.left(requestBodyObj)).when(componentsUtils).convertJsonToObjectUsingObjectMapper(any(), any(), eq(ComponentInstListInput.class), + eq(AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.SERVICE)); - when(inputsBusinessLogic.createListInput(eq(USER_ID), eq(RESOURCE_ID), eq(ComponentTypeEnum.SERVICE), - any(), eq(true), eq(false))) - .thenReturn(Either.left(Collections.emptyList())); - when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(new ResponseFormat(HttpStatus.OK_200.getStatusCode())); + doReturn(Either.left(Collections.emptyList())).when(inputsBusinessLogic).createListInput(eq(USER_ID), eq(RESOURCE_ID), eq(ComponentTypeEnum.SERVICE), + any(), eq(true), eq(false)); + + ResponseFormat responseFormat = new ResponseFormat(HttpStatus.OK_200.getStatusCode()); + doReturn(responseFormat).when(componentsUtils).getResponseFormat(ActionStatus.OK); Response response = buildCreateListInputCall().post(entity); assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200.getStatusCode()); @@ -379,9 +407,11 @@ public class InputsServletTest extends JerseySpringBaseTest { @Test public void test_deleteInput_failure_deleteInput() throws Exception { - when(inputsBusinessLogic.deleteInput(RESOURCE_ID, USER_ID, LISTINPUT_NAME)) - .thenReturn(Either.right(new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode()))); - when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(new ResponseFormat(HttpStatus.OK_200.getStatusCode())); + doReturn(Either.right(new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode()))).when(inputsBusinessLogic) + .deleteInput(RESOURCE_ID, USER_ID, LISTINPUT_NAME); + + ResponseFormat responseFormat = new ResponseFormat(HttpStatus.OK_200.getStatusCode()); + doReturn(responseFormat).when(componentsUtils).getResponseFormat(ActionStatus.OK); // invoke delete call Response response = target("/v1/catalog/services/{id}/delete/{inputId}/input") diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/LifecycleServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/LifecycleServletTest.java index de6aa77f6a..b69f2a58dd 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/LifecycleServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/LifecycleServletTest.java @@ -20,19 +20,30 @@ package org.openecomp.sdc.be.servlets; +import static org.mockito.Mockito.mock; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.junit.Test; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.LifeCycleTransitionEnum; import org.openecomp.sdc.be.model.User; import fj.data.Either; +import org.openecomp.sdc.be.user.UserBusinessLogic; public class LifecycleServletTest { private LifecycleServlet createTestSubject() { - return new LifecycleServlet(); + UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); + LifecycleBusinessLogic lifecycleBusinessLogic = mock(LifecycleBusinessLogic.class); + ComponentsUtils componentsUtils = mock(ComponentsUtils.class); + + return new LifecycleServlet(userBusinessLogic, componentsUtils, lifecycleBusinessLogic); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyServletTest.java index 6d23b9871d..cdb66185ab 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyServletTest.java @@ -467,7 +467,8 @@ public class PolicyServletTest extends JerseySpringBaseTest{ @Override protected ResourceConfig configure() { return super.configure() - .register(new PolicyServlet(businessLogic, servletUtils, null, componentsUtils)); + .register(new PolicyServlet(null, null, componentsUtils, + servletUtils, null, businessLogic)); } private static void createMocks() { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ProductServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ProductServletTest.java index bbd0d4c711..352c76a3f6 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ProductServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ProductServletTest.java @@ -20,15 +20,26 @@ package org.openecomp.sdc.be.servlets; +import static org.mockito.Mockito.mock; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.junit.Test; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.impl.ProductBusinessLogic; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.user.UserBusinessLogic; public class ProductServletTest { private ProductServlet createTestSubject() { - return new ProductServlet(); + UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); + ProductBusinessLogic productBusinessLogic = mock(ProductBusinessLogic.class); + ComponentsUtils componentsUtils = mock(ComponentsUtils.class); + + return new ProductServlet(userBusinessLogic, productBusinessLogic, componentsUtils); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/RequirementsServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/RequirementsServletTest.java index be25f6e96e..61f2b15e65 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/RequirementsServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/RequirementsServletTest.java @@ -20,15 +20,25 @@ package org.openecomp.sdc.be.servlets; +import static org.mockito.Mockito.mock; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.junit.Test; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.user.UserBusinessLogic; public class RequirementsServletTest { private RequirementsServlet createTestSubject() { - return new RequirementsServlet(); + UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); + ComponentInstanceBusinessLogic componentInstanceBL = mock(ComponentInstanceBusinessLogic.class); + ComponentsUtils componentsUtils = mock(ComponentsUtils.class); + + return new RequirementsServlet(userBusinessLogic, componentsUtils); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceArtifactDownloadServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceArtifactDownloadServletTest.java index 573244039d..02a16f86dc 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceArtifactDownloadServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceArtifactDownloadServletTest.java @@ -20,17 +20,31 @@ package org.openecomp.sdc.be.servlets; +import static org.mockito.Mockito.mock; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.junit.Test; import ch.qos.logback.classic.Logger; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.DownloadArtifactLogic; +import org.openecomp.sdc.be.resources.api.IResourceUploader; +import org.openecomp.sdc.be.user.UserBusinessLogic; public class ResourceArtifactDownloadServletTest { private ResourceArtifactDownloadServlet createTestSubject() { - return new ResourceArtifactDownloadServlet(); + UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); + ComponentsUtils componentsUtils = mock(ComponentsUtils.class); + IResourceUploader resourceUploader = mock(IResourceUploader.class); + DownloadArtifactLogic downloadArtifactLogic = mock(DownloadArtifactLogic.class); + + return new ResourceArtifactDownloadServlet(userBusinessLogic, componentsUtils, + resourceUploader, downloadArtifactLogic); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java index 8b8dfc6b9c..2cbf1e2c86 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java @@ -35,6 +35,9 @@ import org.junit.Test; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic; import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.config.SpringConfig; import org.openecomp.sdc.be.dao.api.ActionStatus; @@ -251,16 +254,27 @@ public class ResourceServletTest extends JerseyTest { @Override protected Application configure() { + UserBusinessLogic userBusinessLogic = Mockito.mock(UserBusinessLogic.class); + GroupBusinessLogic groupBL = Mockito.mock(GroupBusinessLogic.class); + ComponentInstanceBusinessLogic componentInstanceBL = Mockito.mock(ComponentInstanceBusinessLogic.class); + ResourceBusinessLogic resourceBusinessLogic = Mockito.mock(ResourceBusinessLogic.class); + ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class); forceSet(TestProperties.CONTAINER_PORT, "0"); return new ResourceConfig(ResourcesServlet.class) - .register(new AbstractBinder() { - @Override - protected void configure() { - bind(request).to(HttpServletRequest.class); - } - }) - .property("contextConfig", context); - + .register(new AbstractBinder() { + @Override + protected void configure() { + bind(request).to(HttpServletRequest.class); + bind(servletUtils).to(ServletUtils.class); + bind(componentUtils).to(ComponentsUtils.class); + bind(userBusinessLogic).to(UserBusinessLogic.class); + bind(resourceBusinessLogic).to(ResourceBusinessLogic.class); + bind(groupBL).to(GroupBusinessLogic.class); + bind(componentInstanceBL).to(ComponentInstanceBusinessLogic.class); + bind(resourceImportManager).to(ResourceImportManager.class); + } + }) + .property("contextConfig", context); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourcesServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourcesServletTest.java index dbce3e5048..42103b0740 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourcesServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourcesServletTest.java @@ -20,6 +20,8 @@ package org.openecomp.sdc.be.servlets; +import static org.mockito.Mockito.mock; + import java.util.List; import java.util.Map; @@ -27,9 +29,16 @@ import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.junit.Test; +import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; +import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic; +import org.openecomp.sdc.be.components.impl.ResourceImportManager; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.exception.ResponseFormat; import com.google.common.base.Equivalence.Wrapper; @@ -39,7 +48,15 @@ import fj.data.Either; public class ResourcesServletTest { private ResourcesServlet createTestSubject() { - return new ResourcesServlet(); + UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); + ComponentInstanceBusinessLogic componentInstanceBL = mock(ComponentInstanceBusinessLogic.class); + ResourceBusinessLogic resourceBusinessLogic = mock(ResourceBusinessLogic.class); + ComponentsUtils componentsUtils = mock(ComponentsUtils.class); + ServletUtils servletUtils = mock(ServletUtils.class); + ResourceImportManager resourceImportManager = mock(ResourceImportManager.class); + + return new ResourcesServlet(userBusinessLogic, componentInstanceBL, resourceBusinessLogic, componentsUtils, servletUtils, + resourceImportManager); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ServiceServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ServiceServletTest.java index 6d8f400760..c2a8afec85 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ServiceServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ServiceServletTest.java @@ -20,14 +20,20 @@ package org.openecomp.sdc.be.servlets; +import static org.mockito.Mockito.mock; + import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.junit.Test; +import org.openecomp.sdc.be.components.impl.*; import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.exception.ResponseFormat; import com.google.common.base.Equivalence.Wrapper; @@ -38,7 +44,16 @@ import fj.data.Either; public class ServiceServletTest { private ServiceServlet createTestSubject() { - return new ServiceServlet(); + UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); + ComponentInstanceBusinessLogic componentInstanceBL = mock(ComponentInstanceBusinessLogic.class); + ComponentsUtils componentsUtils = mock(ComponentsUtils.class); + ServletUtils servletUtils = mock(ServletUtils.class); + ResourceImportManager resourceImportManager = mock(ResourceImportManager.class); + ServiceBusinessLogic serviceBusinessLogic = mock(ServiceBusinessLogic.class); + ResourceBusinessLogic resourceBusinessLogic = mock(ResourceBusinessLogic.class); + + return new ServiceServlet(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, + resourceImportManager, serviceBusinessLogic, resourceBusinessLogic); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesFetchServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesFetchServletTest.java index 5127be879b..f27c886e68 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesFetchServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesFetchServletTest.java @@ -20,17 +20,35 @@ package org.openecomp.sdc.be.servlets; +import static org.mockito.Mockito.mock; + import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.junit.Test; -import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic; +import org.openecomp.sdc.be.components.impl.*; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServletUtils; +import org.openecomp.sdc.be.user.UserBusinessLogic; public class TypesFetchServletTest { private TypesFetchServlet createTestSubject() { - return new TypesFetchServlet(); + UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); + ComponentInstanceBusinessLogic componentInstanceBL = mock(ComponentInstanceBusinessLogic.class); + ComponentsUtils componentsUtils = mock(ComponentsUtils.class); + ServletUtils servletUtils = mock(ServletUtils.class); + ResourceImportManager resourceImportManager = mock(ResourceImportManager.class); + PropertyBusinessLogic propertyBusinessLogic = mock(PropertyBusinessLogic.class); + RelationshipTypeBusinessLogic relationshipTypeBusinessLogic = mock(RelationshipTypeBusinessLogic.class); + CapabilitiesBusinessLogic capabilitiesBusinessLogic = mock(CapabilitiesBusinessLogic.class); + InterfaceOperationBusinessLogic interfaceOperationBusinessLogic = mock(InterfaceOperationBusinessLogic.class); + ResourceBusinessLogic resourceBusinessLogic = mock(ResourceBusinessLogic.class); + + return new TypesFetchServlet(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, + resourceImportManager, propertyBusinessLogic, relationshipTypeBusinessLogic, capabilitiesBusinessLogic, + interfaceOperationBusinessLogic, resourceBusinessLogic); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java index 807ded8f5c..92652f59d0 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java @@ -112,7 +112,7 @@ public class TypesUploadServletTest extends JerseyTest { Response response = target().path("/v1/catalog/uploadType/capability").request(MediaType.APPLICATION_JSON).post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class); - assertEquals(response.getStatus(), HttpStatus.CREATED_201); + assertEquals(HttpStatus.CREATED_201, response.getStatus()); } @@ -124,8 +124,14 @@ public class TypesUploadServletTest extends JerseyTest { @Override protected ResourceConfig configure() { + + + TypesUploadServlet typesUploadServlet = new TypesUploadServlet(null, null, componentUtils, + servletUtils, null, importManager, null, + null, null, + null, null, null); ResourceConfig resourceConfig = new ResourceConfig() - .register(new TypesUploadServlet(importManager, null, null, null, null, null, null)); + .register(typesUploadServlet); resourceConfig.register(MultiPartFeature.class); resourceConfig.register(new AbstractBinder() { -- cgit 1.2.3-korg