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 c3718c1df99..a66a4b8ccab 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 894f510dd5b..968be5cce7a 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 b32ab3ab8e0..a2017126428 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 a1088861643..0f0901f0b16 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 919a92d7c52..b6b3d8b261c 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