From 6792c212106a05ae2173e93347a5559428032f2b Mon Sep 17 00:00:00 2001 From: lasantha Date: Thu, 15 Feb 2018 10:26:48 +0530 Subject: [PATCH] Rmoved the lifecycle managemt Removed the lifecycle management core and formatted the source --- .../services/LifecycleStateManager.java | 35 ---- .../core/impl/LifecycleStateManagerImpl.java | 184 ------------------ .../mgt/core/internal/DataHolder.java | 11 -- .../mgt/core/internal/ServiceComponent.java | 5 - .../core/util/ApplicationManagementUtil.java | 7 - .../core/util/ValidateApplicationUtil.java | 78 -------- .../mgt/publisher/api/APIUtil.java | 19 -- .../impl/ApplicationManagementAPIImpl.java | 34 ++-- .../impl/LifecycleManagementAPIImpl.java | 9 +- .../application/mgt/store/api/APIUtil.java | 14 -- 10 files changed, 19 insertions(+), 377 deletions(-) delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/LifecycleStateManager.java delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/LifecycleStateManagerImpl.java delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ValidateApplicationUtil.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/LifecycleStateManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/LifecycleStateManager.java deleted file mode 100644 index 712a58ac57..0000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/LifecycleStateManager.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.device.application.mgt.common.services; - -import org.wso2.carbon.device.application.mgt.common.LifecycleState; -import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; - -import java.util.List; - -/** - * This interface manages all the operations related with lifecycle state. - */ -public interface LifecycleStateManager { - - LifecycleState getLifecycleState(int appReleaseId, String applicationUuid) throws LifecycleManagementException; - - void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws LifecycleManagementException; - -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/LifecycleStateManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/LifecycleStateManagerImpl.java deleted file mode 100644 index 3ab87b902e..0000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/LifecycleStateManagerImpl.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.device.application.mgt.core.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.application.mgt.common.AppLifecycleState; -import org.wso2.carbon.device.application.mgt.common.Application; -import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; -import org.wso2.carbon.device.application.mgt.common.LifecycleState; -import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; -import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; -import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; -import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; -import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO; -import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; -import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; -import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException; -import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; -import org.wso2.carbon.device.application.mgt.core.util.ValidateApplicationUtil; - -import java.util.ArrayList; -import java.util.List; - -/** - * Concrete implementation of Lifecycle state management. - */ -public class LifecycleStateManagerImpl implements LifecycleStateManager { - - private static final Log log = LogFactory.getLog(LifecycleStateManagerImpl.class); - - @Override - public LifecycleState getLifecycleState(int applicationId, String applicationUuid) throws LifecycleManagementException { - LifecycleState lifecycleState; - try { - ConnectionManagerUtil.openDBConnection(); - LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); - Application application = ValidateApplicationUtil.validateApplication(applicationId); - //todo applicationUuid and applicationId should be passed and util method has to be changed - ApplicationRelease applicationRelease = ValidateApplicationUtil.validateApplicationRelease(applicationUuid); - lifecycleState = lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); - lifecycleState.setNextStates(getNextLifecycleStates(lifecycleState.getCurrentState())); - } catch (ApplicationManagementDAOException e) { - throw new LifecycleManagementException("Failed to get lifecycle state", e); - } catch (DBConnectionException e) { - throw new LifecycleManagementException("Failed to connect with Database", e); - } catch (ApplicationManagementException e) { - throw new LifecycleManagementException("Failed to get application and application management", e); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } - return lifecycleState; - } - - @Override - public void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws LifecycleManagementException { - try { - ConnectionManagerUtil.openDBConnection(); - Application application = ValidateApplicationUtil.validateApplication(applicationId); - //todo applicationUuid and applicationId should be passed and util method has to be changed - ApplicationRelease applicationRelease = ValidateApplicationUtil.validateApplicationRelease(applicationUuid); - LifecycleStateDAO lifecycleStateDAO; - - if (application != null) { - state.setAppId(applicationId); - } - if (applicationRelease != null) { - state.setReleaseId(applicationRelease.getId()); - } - if (state.getCurrentState() != null && state.getPreviousState() != null && state.getUpdatedBy() != null) { - validateLifecycleState(state); - lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO(); - lifecycleStateDAO.addLifecycleState(state); - } - } catch (LifeCycleManagementDAOException | DBConnectionException e) { - throw new LifecycleManagementException("Failed to add lifecycle state", e); - } catch (ApplicationManagementException e) { - throw new LifecycleManagementException("Lifecycle State Validation failed", e); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } - } - - private List getNextLifecycleStates(String currentLifecycleState) { - List nextLifecycleStates = new ArrayList<>(); - if (AppLifecycleState.CREATED.toString().equals(currentLifecycleState)) { - nextLifecycleStates.add(AppLifecycleState.IN_REVIEW.toString()); - } - if (AppLifecycleState.IN_REVIEW.toString().equals(currentLifecycleState)) { - nextLifecycleStates.add(AppLifecycleState.APPROVED.toString()); - nextLifecycleStates.add(AppLifecycleState.REJECTED.toString()); - } - if (AppLifecycleState.REJECTED.toString().equals(currentLifecycleState)) { - nextLifecycleStates.add(AppLifecycleState.IN_REVIEW.toString()); - nextLifecycleStates.add(AppLifecycleState.REMOVED.toString()); - } - if (AppLifecycleState.APPROVED.toString().equals(currentLifecycleState)) { - nextLifecycleStates.add(AppLifecycleState.PUBLISHED.toString()); - } - if (AppLifecycleState.PUBLISHED.toString().equals(currentLifecycleState)) { - nextLifecycleStates.add(AppLifecycleState.UNPUBLISHED.toString()); - nextLifecycleStates.add(AppLifecycleState.DEPRECATED.toString()); - } - if (AppLifecycleState.UNPUBLISHED.toString().equals(currentLifecycleState)) { - nextLifecycleStates.add(AppLifecycleState.PUBLISHED.toString()); - nextLifecycleStates.add(AppLifecycleState.REMOVED.toString()); - } - if (AppLifecycleState.DEPRECATED.toString().equals(currentLifecycleState)) { - nextLifecycleStates.add(AppLifecycleState.REMOVED.toString()); - } - return nextLifecycleStates; - } - - private void validateLifecycleState(LifecycleState state) throws LifecycleManagementException { - - if (AppLifecycleState.CREATED.toString().equals(state.getCurrentState())) { - throw new LifecycleManagementException("Current State Couldn't be " + state.getCurrentState()); - } - if (AppLifecycleState.IN_REVIEW.toString().equals(state.getCurrentState())) { - if (!AppLifecycleState.CREATED.toString().equals(state.getPreviousState()) && - !AppLifecycleState.REJECTED.toString().equals(state.getPreviousState())) { - throw new LifecycleManagementException("If Current State is " + state.getCurrentState() + - "Previous State should be either " + AppLifecycleState.CREATED.toString() + " or " + - AppLifecycleState.REJECTED.toString()); - } - } - if (AppLifecycleState.APPROVED.toString().equals(state.getCurrentState())) { - if (!AppLifecycleState.IN_REVIEW.toString().equals(state.getPreviousState())) { - throw new LifecycleManagementException("If Current State is " + state.getCurrentState() + - "Previous State should be " + AppLifecycleState.IN_REVIEW.toString()); - } - } - if (AppLifecycleState.PUBLISHED.toString().equals(state.getCurrentState())) { - if (!AppLifecycleState.APPROVED.toString().equals(state.getPreviousState()) && - !AppLifecycleState.UNPUBLISHED.toString().equals(state.getPreviousState())) { - throw new LifecycleManagementException("If Current State is " + state.getCurrentState() + - "Previous State should be either " + AppLifecycleState.APPROVED.toString() + " or " + - AppLifecycleState.UNPUBLISHED.toString()); - } - } - if (AppLifecycleState.UNPUBLISHED.toString().equals(state.getCurrentState())) { - if (!AppLifecycleState.PUBLISHED.toString().equals(state.getPreviousState())) { - throw new LifecycleManagementException("If Current State is " + state.getCurrentState() + - "Previous State should be " + AppLifecycleState.PUBLISHED.toString()); - } - } - if (AppLifecycleState.REJECTED.toString().equals(state.getCurrentState())) { - if (!AppLifecycleState.IN_REVIEW.toString().equals(state.getPreviousState())) { - throw new LifecycleManagementException("If Current State is " + state.getCurrentState() + - "Previous State should be " + AppLifecycleState.IN_REVIEW.toString()); - } - } - if (AppLifecycleState.DEPRECATED.toString().equals(state.getCurrentState())) { - if (!AppLifecycleState.PUBLISHED.toString().equals(state.getPreviousState())) { - throw new LifecycleManagementException("If Current State is " + state.getCurrentState() + - "Previous State should be " + AppLifecycleState.PUBLISHED.toString()); - } - } - if (AppLifecycleState.REMOVED.toString().equals(state.getCurrentState())) { - if (!AppLifecycleState.DEPRECATED.toString().equals(state.getPreviousState()) && - !AppLifecycleState.REJECTED.toString().equals(state.getPreviousState()) && - !AppLifecycleState.UNPUBLISHED.toString().equals(state.getPreviousState())) { - throw new LifecycleManagementException("If Current State is " + state.getCurrentState() + - "Previous State should be either " + AppLifecycleState.DEPRECATED.toString() + " or " + - AppLifecycleState.REJECTED.toString() + " or " + AppLifecycleState.UNPUBLISHED.toString()); - } - } - } -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java index 8088293c28..56fd36b438 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java @@ -22,7 +22,6 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; -import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; @@ -43,8 +42,6 @@ public class DataHolder { private CommentsManager commentsManager; - private LifecycleStateManager lifecycleStateManager; - private SubscriptionManager subscriptionManager; private UnrestrictedRoleManager unrestrictedRoleManager; @@ -93,14 +90,6 @@ public class DataHolder { this.commentsManager = commentsManager; } - public LifecycleStateManager getLifecycleStateManager() { - return lifecycleStateManager; - } - - public void setLifecycleStateManager(LifecycleStateManager lifecycleStateManager) { - this.lifecycleStateManager = lifecycleStateManager; - } - public SubscriptionManager getSubscriptionManager() { return subscriptionManager; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java index c7a7ad0317..faf8fe191c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java @@ -27,7 +27,6 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; -import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; @@ -85,10 +84,6 @@ public class ServiceComponent { DataHolder.getInstance().setCommentsManager(commentsManager); bundleContext.registerService(CommentsManager.class.getName(), commentsManager, null); - LifecycleStateManager lifecycleStateManager = ApplicationManagementUtil.getLifecycleStateManagerInstance(); - DataHolder.getInstance().setLifecycleStateManager(lifecycleStateManager); - bundleContext.registerService(LifecycleStateManager.class.getName(), lifecycleStateManager, null); - SubscriptionManager subscriptionManager = ApplicationManagementUtil.getSubscriptionManagerInstance(); DataHolder.getInstance().setSubscriptionManager(subscriptionManager); bundleContext.registerService(SubscriptionManager.class.getName(), subscriptionManager, 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 72f2407dcb..c7b0f61b55 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 @@ -25,7 +25,6 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; -import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; @@ -60,12 +59,6 @@ public class ApplicationManagementUtil { return getInstance(extension, CommentsManager.class); } - public static LifecycleStateManager getLifecycleStateManagerInstance() throws InvalidConfigurationException { - ConfigurationManager configurationManager = ConfigurationManager.getInstance(); - Extension extension = configurationManager.getExtension(Extension.Name.LifecycleStateManager); - return getInstance(extension, LifecycleStateManager.class); - } - public static UnrestrictedRoleManager getVisibilityManagerInstance() throws InvalidConfigurationException { ConfigurationManager configurationManager = ConfigurationManager.getInstance(); Extension extension = configurationManager.getExtension(Extension.Name.VisibilityManager); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ValidateApplicationUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ValidateApplicationUtil.java deleted file mode 100644 index af041d772e..0000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ValidateApplicationUtil.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.device.application.mgt.core.util; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.application.mgt.common.Application; -import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; -import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; -import org.wso2.carbon.device.application.mgt.common.exception.InvalidConfigurationException; -import org.wso2.carbon.device.application.mgt.common.services.*; -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.exception.NotFoundException; -import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; - -import java.lang.reflect.Constructor; - -/** - * This Util class is responsible for making sure single instance of each Extension Manager is used throughout for - * all the tasks. - */ -public class ValidateApplicationUtil { - - /** - * To validate the pre-request of the ApplicationRelease. - * - * @param applicationID ID of the Application. - * @return Application related with the UUID - */ - public static Application validateApplication(int applicationID) throws ApplicationManagementException { - if (applicationID <= 0) { - throw new ApplicationManagementException("Application UUID is null. Application UUID is a required " - + "parameter to get the relevant application."); - } - Application application = DataHolder.getInstance().getApplicationManager().getApplicationById(applicationID); - if (application == null) { - throw new NotFoundException("Application of the " + applicationID + " does not exist."); - } - return application; - } - - /** - * To validate the pre-request of the ApplicationRelease. - * - * @param applicationUuid UUID of the Application. - * @return Application related with the UUID - */ - public static ApplicationRelease validateApplicationRelease(String applicationUuid) throws ApplicationManagementException { - if (applicationUuid == null) { - throw new ApplicationManagementException("Application UUID is null. Application UUID is a required " - + "parameter to get the relevant application."); - } - ApplicationRelease applicationRelease = DataHolder.getInstance().getApplicationReleaseManager() - .getReleaseByUuid(applicationUuid); - if (applicationRelease == null) { - throw new NotFoundException( - "Application with UUID " + applicationUuid + " does not exist."); - } - return applicationRelease; - } -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/APIUtil.java index 0e399d2d07..dbf9723208 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/APIUtil.java @@ -35,7 +35,6 @@ public class APIUtil { private static Log log = LogFactory.getLog(APIUtil.class); private static ApplicationManager applicationManager; - private static LifecycleStateManager lifecycleStateManager; private static ApplicationReleaseManager applicationReleaseManager; private static ApplicationStorageManager applicationStorageManager; private static SubscriptionManager subscriptionManager; @@ -61,24 +60,6 @@ public class APIUtil { return applicationManager; } - public static LifecycleStateManager getLifecycleStateManager() { - if (lifecycleStateManager == null) { - synchronized (APIUtil.class) { - if (lifecycleStateManager == null) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - lifecycleStateManager = - (LifecycleStateManager) ctx.getOSGiService(LifecycleStateManager.class, null); - if (lifecycleStateManager == null) { - String msg = "Lifecycle Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - } - } - } - return lifecycleStateManager; - } - /** * To get the Application Release Manager from the osgi context. * diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java index 8a8fe3a1e4..10744febb9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java @@ -22,29 +22,22 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Multipart; -import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; import org.wso2.carbon.device.application.mgt.publisher.api.APIUtil; -import org.wso2.carbon.device.application.mgt.publisher.api.FileStreamingOutput; import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementAPI; import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.Filter; -import org.wso2.carbon.device.application.mgt.common.ImageArtifact; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; -import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; -import org.wso2.carbon.device.application.mgt.core.util.Constants; -import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.UUID; import javax.validation.Valid; @@ -57,7 +50,6 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; /** @@ -142,22 +134,26 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { if (iconFile == null) { throw new ApplicationManagementException( "Icon file is not uploaded for the application release of " + application.getName() + - " of application type " + application.getType()); } + " of application type " + application.getType()); + } if (bannerFile == null) { throw new ApplicationManagementException( "Banner file is not uploaded for the application release of " + application.getName() + - " of application type " + application.getType()); } + " of application type " + application.getType()); + } if (attachmentList == null || attachmentList.isEmpty()) { throw new ApplicationManagementException( "Screenshots are not uploaded for the application release of " + application.getName() + - " of application type " + application.getType()); } + " of application type " + application.getType()); + } - if (binaryFile == null){ + if (binaryFile == null) { throw new ApplicationManagementException( "Binary file is not uploaded for the application release of " + application.getName() + - " of application type " + application.getType()); } + " of application type " + application.getType()); + } iconFileStream = iconFile.getDataHandler().getInputStream(); @@ -170,7 +166,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { applicationRelease = applicationStorageManager.uploadReleaseArtifacts(applicationRelease, binaryFile.getDataHandler().getInputStream()); - if(applicationRelease.getAppStoredLoc() == null || applicationRelease.getAppHashValue() == null){ + if (applicationRelease.getAppStoredLoc() == null || applicationRelease.getAppHashValue() == null) { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } applicationRelease = applicationStorageManager.uploadImageArtifacts(applicationRelease, iconFileStream, @@ -179,13 +175,13 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { applicationRelease.setUuid(UUID.randomUUID().toString()); Application createdApplication = applicationManager.createApplication(application); - if (application != null){ + if (application != null) { return Response.status(Response.Status.CREATED).entity(createdApplication).build(); - }else{ + } else { log.error("Given device type is not matched with existing device types"); - return Response.status(Response.Status.BAD_REQUEST).build(); + return Response.status(Response.Status.BAD_REQUEST).build(); } - }catch (ApplicationManagementException e) { + } catch (ApplicationManagementException e) { String msg = "Error occurred while creating the application"; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).build(); @@ -305,7 +301,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { } catch (NotFoundException e) { return APIUtil.getResponse(e, Response.Status.NOT_FOUND); } catch (ApplicationManagementException e) { - String msg = "Error occurred while modifying the application"; + String msg = "Error occurred while modifying the application"; log.error(msg, e); return APIUtil.getResponse(e, Response.Status.BAD_REQUEST); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/LifecycleManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/LifecycleManagementAPIImpl.java index c348ebdecc..7b27467770 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/LifecycleManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/LifecycleManagementAPIImpl.java @@ -27,7 +27,6 @@ import org.wso2.carbon.device.application.mgt.publisher.api.APIUtil; import org.wso2.carbon.device.application.mgt.publisher.api.services.LifecycleManagementAPI; import org.wso2.carbon.device.application.mgt.common.LifecycleState; import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException; -import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; import java.util.Arrays; import javax.ws.rs.*; @@ -47,9 +46,9 @@ public class LifecycleManagementAPIImpl implements LifecycleManagementAPI { @PathParam("appId") int applicationId, @PathParam("uuid") String applicationUuid) { LifecycleState lifecycleState; - LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager(); + ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { - lifecycleState = lifecycleStateManager.getLifecycleState(applicationId, applicationUuid); + lifecycleState = applicationManager.getLifecycleState(applicationId, applicationUuid); } catch (LifecycleManagementException e) { String msg = "Error occurred while getting lifecycle state."; log.error(msg, e); @@ -65,9 +64,9 @@ public class LifecycleManagementAPIImpl implements LifecycleManagementAPI { @PathParam("appId") int applicationId, @PathParam("uuid") String applicationUuid, LifecycleState state) { - LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager(); + ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { - lifecycleStateManager.addLifecycleState(applicationId, applicationUuid, state); + applicationManager.addLifecycleState(applicationId, applicationUuid, state); } catch (LifecycleManagementException e) { String msg = "Error occurred while adding lifecycle state."; log.error(msg, e); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java index 0f824e3ea2..af5a584f73 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/APIUtil.java @@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; -import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; @@ -39,7 +38,6 @@ public class APIUtil { private static Log log = LogFactory.getLog(APIUtil.class); private static ApplicationManager applicationManager; - private static LifecycleStateManager lifecycleStateManager; private static ApplicationReleaseManager applicationReleaseManager; private static ApplicationStorageManager applicationStorageManager; private static SubscriptionManager subscriptionManager; @@ -55,18 +53,6 @@ public class APIUtil { return applicationManager; } - public static LifecycleStateManager getLifecycleStateManager() { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - LifecycleStateManager lifecycleStateManager = (LifecycleStateManager) ctx - .getOSGiService(LifecycleStateManager.class, null); - if (lifecycleStateManager == null) { - String msg = "Lifecycle Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - return lifecycleStateManager; - } - /** * To get the Application Release Manager from the osgi context. *