Fix lifecycle instance initiating issue

4.x.x
lasanthaDLPDS 6 years ago
parent 911bc6f9a0
commit 0cb26066c5

@ -927,6 +927,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException("Failed to get application and application management", e); throw new ApplicationManagementException("Failed to get application and application management", e);
} catch (LifeCycleManagementDAOException e) { } catch (LifeCycleManagementDAOException e) {
throw new ApplicationManagementException("Failed to get lifecycle state from database", e); throw new ApplicationManagementException("Failed to get lifecycle state from database", e);
} finally {
ConnectionManagerUtil.closeDBConnection();
} }
return lifecycleState; return lifecycleState;
} }

@ -77,6 +77,13 @@ public class ApplicationManagementServiceComponent {
ApplicationManagementDAOFactory.init(dataSourceName); ApplicationManagementDAOFactory.init(dataSourceName);
// ApplicationManagementDAOFactory.initDatabases(); // ApplicationManagementDAOFactory.initDatabases();
List<LifecycleState> 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(); ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagerInstance();
DataHolder.getInstance().setApplicationManager(applicationManager); DataHolder.getInstance().setApplicationManager(applicationManager);
bundleContext.registerService(ApplicationManager.class.getName(), applicationManager, null); bundleContext.registerService(ApplicationManager.class.getName(), applicationManager, null);
@ -94,12 +101,6 @@ public class ApplicationManagementServiceComponent {
DataHolder.getInstance().setApplicationStorageManager(applicationStorageManager); DataHolder.getInstance().setApplicationStorageManager(applicationStorageManager);
bundleContext.registerService(ApplicationStorageManager.class.getName(), applicationStorageManager, null); bundleContext.registerService(ApplicationStorageManager.class.getName(), applicationStorageManager, null);
List<LifecycleState> 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(). UIConfiguration uiConfiguration = ConfigurationManager.getInstance().
getConfiguration().getUiConfiguration(); getConfiguration().getUiConfiguration();
ConfigManager configManager = new ConfigManagerImpl(uiConfiguration); ConfigManager configManager = new ConfigManagerImpl(uiConfiguration);

@ -15,7 +15,7 @@ public class LifecycleStateManger {
private Map<String, State> lifecycleStates; private Map<String, State> lifecycleStates;
public LifecycleStateManger(List<LifecycleState> states) { public void init(List<LifecycleState> states){
lifecycleStates = new HashMap<>(); lifecycleStates = new HashMap<>();
for (LifecycleState s : states) { for (LifecycleState s : states) {
if (s.getProceedingStates() != null) { if (s.getProceedingStates() != null) {

@ -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.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; 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.config.Extension;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -63,6 +64,12 @@ public class ApplicationManagementUtil {
return getInstance(extension, ApplicationStorageManager.class); 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> T getInstance(Extension extension, Class<T> cls) throws InvalidConfigurationException { private static <T> T getInstance(Extension extension, Class<T> cls) throws InvalidConfigurationException {
try { try {
Class theClass = Class.forName(extension.getClassName()); Class theClass = Class.forName(extension.getClassName());

@ -25,7 +25,8 @@ public class LifecycleManagementTest {
ConfigurationManager configurationManager = ConfigurationManager.getInstance(); ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Configuration configuration = configurationManager.getConfiguration(); Configuration configuration = configurationManager.getConfiguration();
lifecycleStates = configuration.getLifecycleStates(); lifecycleStates = configuration.getLifecycleStates();
lifecycleStateManger = new LifecycleStateManger(lifecycleStates); lifecycleStateManger = new LifecycleStateManger();
lifecycleStateManger.init(lifecycleStates);
} }
@Test @Test

Loading…
Cancel
Save