From a1806eb87e722d89ef63df87b9583001348c9fc4 Mon Sep 17 00:00:00 2001 From: megala21 Date: Mon, 9 Oct 2017 21:15:03 +0530 Subject: [PATCH] Refactoring --- .../application/mgt/core/dao/common/DAOFactory.java | 8 +++++++- .../mgt/core/impl/ApplicationManagerImpl.java | 9 +-------- .../application/mgt/core/impl/CategoryManagerImpl.java | 5 ++--- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java index fa2e94b45d..88e7bb9f1e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java @@ -22,7 +22,13 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.application.mgt.common.exception.UnsupportedDatabaseEngineException; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; -import org.wso2.carbon.device.application.mgt.core.dao.*; +import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; +import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; +import org.wso2.carbon.device.application.mgt.core.dao.CategoryDAO; +import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO; +import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO; +import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO; +import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.GenericApplicationReleaseDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.OracleApplicationDAOImpl; 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 f5e7c84f3c..a9d5117942 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 @@ -73,11 +73,10 @@ public class ApplicationManagerImpl implements ApplicationManager { application.setModifiedAt(new Date()); Platform platform = DataHolder.getInstance().getPlatformManager() .getPlatform(application.getUser().getTenantId(), application.getPlatform().getIdentifier()); - if (platform == null) { throw new NotFoundException("Invalid platform is provided for the application " + application.getUuid()); } - + application.setPlatform(platform); Category category = DataHolder.getInstance().getCategoryManager() .getCategory(application.getCategory().getName()); if (category == null) { @@ -86,9 +85,6 @@ public class ApplicationManagerImpl implements ApplicationManager { application.setCategory(category); try { ConnectionManagerUtil.beginDBTransaction(); - - // Validating the platform - application.setPlatform(platform); if (log.isDebugEnabled()) { log.debug("Application creation pre-conditions are met and the platform mentioned by identifier " + platform.getIdentifier() + " is found"); @@ -104,7 +100,6 @@ public class ApplicationManagerImpl implements ApplicationManager { lifecycle.setLifecycleStateModifiedAt(new Date()); lifecycle.setGetLifecycleStateModifiedBy(application.getUser().getUserName()); application.setCurrentLifecycle(lifecycle); - application = DAOFactory.getApplicationDAO().createApplication(application); DataHolder.getInstance().getVisibilityManager().put(application.getId(), application.getVisibility()); ConnectionManagerUtil.commitDBTransaction(); @@ -142,7 +137,6 @@ public class ApplicationManagerImpl implements ApplicationManager { + " is not found. Please give a valid platform identifier."); } application.setPlatform(platform); - if (application.getCategory() != null) { String applicationCategoryName = application.getCategory().getName(); if (applicationCategoryName == null || applicationCategoryName.isEmpty()) { @@ -158,7 +152,6 @@ public class ApplicationManagerImpl implements ApplicationManager { } application.setCategory(category); } - try { ConnectionManagerUtil.beginDBTransaction(); ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CategoryManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CategoryManagerImpl.java index 632ac600e6..2d547b7bb8 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CategoryManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CategoryManagerImpl.java @@ -44,9 +44,8 @@ public class CategoryManagerImpl implements CategoryManager { "Application category name cannot be null. Application category creation failed."); } if (getCategory(category.getName()) != null) { - throw new ApplicationCategoryManagementException( - "Application category wth the name " + category.getName() + " " - + "exists already. Please select a different name"); + throw new ApplicationCategoryManagementException("Application category wth the name " + category.getName() + + "exists already. Please select a different name"); } try { ConnectionManagerUtil.beginDBTransaction();