From 0cb26066c5a6e2ca91c9276a4edd190039c968b0 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Mon, 4 Mar 2019 19:07:50 +0530 Subject: [PATCH] Fix lifecycle instance initiating issue --- .../mgt/core/impl/ApplicationManagerImpl.java | 2 ++ .../ApplicationManagementServiceComponent.java | 13 +++++++------ .../mgt/core/lifecycle/LifecycleStateManger.java | 2 +- .../mgt/core/util/ApplicationManagementUtil.java | 7 +++++++ .../LifecycleManagementTest.java | 3 ++- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index c3718c1df9..a66a4b8cca 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -927,6 +927,8 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException("Failed to get application and application management", e); } catch (LifeCycleManagementDAOException e) { throw new ApplicationManagementException("Failed to get lifecycle state from database", e); + } finally { + ConnectionManagerUtil.closeDBConnection(); } return lifecycleState; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java index 894f510dd5..968be5cce7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java @@ -77,6 +77,13 @@ public class ApplicationManagementServiceComponent { ApplicationManagementDAOFactory.init(dataSourceName); // ApplicationManagementDAOFactory.initDatabases(); + List lifecycleStates = ConfigurationManager.getInstance(). + getConfiguration().getLifecycleStates(); + LifecycleStateManger lifecycleStateManger = ApplicationManagementUtil.getLifecycleStateMangerInstance(); + lifecycleStateManger.init(lifecycleStates); + DataHolder.getInstance().setLifecycleStateManger(lifecycleStateManger); + bundleContext.registerService(LifecycleStateManger.class.getName(), lifecycleStateManger, null); + ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagerInstance(); DataHolder.getInstance().setApplicationManager(applicationManager); bundleContext.registerService(ApplicationManager.class.getName(), applicationManager, null); @@ -94,12 +101,6 @@ public class ApplicationManagementServiceComponent { DataHolder.getInstance().setApplicationStorageManager(applicationStorageManager); bundleContext.registerService(ApplicationStorageManager.class.getName(), applicationStorageManager, null); - List lifecycleStates = ConfigurationManager.getInstance(). - getConfiguration().getLifecycleStates(); - LifecycleStateManger lifecycleStateManger = new LifecycleStateManger(lifecycleStates); - DataHolder.getInstance().setLifecycleStateManger(lifecycleStateManger); - bundleContext.registerService(LifecycleStateManger.class.getName(), lifecycleStateManger, null); - UIConfiguration uiConfiguration = ConfigurationManager.getInstance(). getConfiguration().getUiConfiguration(); ConfigManager configManager = new ConfigManagerImpl(uiConfiguration); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java index b32ab3ab8e..a201712642 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java @@ -15,7 +15,7 @@ public class LifecycleStateManger { private Map lifecycleStates; - public LifecycleStateManger(List states) { + public void init(List states){ lifecycleStates = new HashMap<>(); for (LifecycleState s : states) { if (s.getProceedingStates() != null) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java index a108886164..0f0901f0b1 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java @@ -27,6 +27,7 @@ import org.wso2.carbon.device.application.mgt.common.services.ReviewManager; import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.config.Extension; +import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger; import java.lang.reflect.Constructor; @@ -63,6 +64,12 @@ public class ApplicationManagementUtil { return getInstance(extension, ApplicationStorageManager.class); } + public static LifecycleStateManger getLifecycleStateMangerInstance() throws InvalidConfigurationException { + ConfigurationManager configurationManager = ConfigurationManager.getInstance(); + Extension extension = configurationManager.getExtension(Extension.Name.LifecycleStateManager); + return getInstance(extension, LifecycleStateManger.class); + } + private static T getInstance(Extension extension, Class cls) throws InvalidConfigurationException { try { Class theClass = Class.forName(extension.getClassName()); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java index 919a92d7c5..b6b3d8b261 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java @@ -25,7 +25,8 @@ public class LifecycleManagementTest { ConfigurationManager configurationManager = ConfigurationManager.getInstance(); Configuration configuration = configurationManager.getConfiguration(); lifecycleStates = configuration.getLifecycleStates(); - lifecycleStateManger = new LifecycleStateManger(lifecycleStates); + lifecycleStateManger = new LifecycleStateManger(); + lifecycleStateManger.init(lifecycleStates); } @Test