diff options
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java | 141 |
1 files changed, 11 insertions, 130 deletions
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<User, ResponseFormat> getUser(final HttpServletRequest request, String userId) { - Either<User, ActionStatus> eitherCreator = getUserAdminManager(request.getSession().getServletContext()).getUser(userId, false); + Either<User, ActionStatus> 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> T getClassFromWebAppContext(ServletContext context, Supplier<Class<T>> 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; - } - <T> void convertJsonToObjectOfClass(String json, Wrapper<T> policyWrapper, Class<T> clazz, Wrapper<Response> 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); |