Refactoring

4.x.x
megala21 7 years ago
parent d8ff31b628
commit a1806eb87e

@ -22,7 +22,13 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.exception.UnsupportedDatabaseEngineException; 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.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.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.GenericApplicationReleaseDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.OracleApplicationDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.OracleApplicationDAOImpl;

@ -73,11 +73,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
application.setModifiedAt(new Date()); application.setModifiedAt(new Date());
Platform platform = DataHolder.getInstance().getPlatformManager() Platform platform = DataHolder.getInstance().getPlatformManager()
.getPlatform(application.getUser().getTenantId(), application.getPlatform().getIdentifier()); .getPlatform(application.getUser().getTenantId(), application.getPlatform().getIdentifier());
if (platform == null) { if (platform == null) {
throw new NotFoundException("Invalid platform is provided for the application " + application.getUuid()); throw new NotFoundException("Invalid platform is provided for the application " + application.getUuid());
} }
application.setPlatform(platform);
Category category = DataHolder.getInstance().getCategoryManager() Category category = DataHolder.getInstance().getCategoryManager()
.getCategory(application.getCategory().getName()); .getCategory(application.getCategory().getName());
if (category == null) { if (category == null) {
@ -86,9 +85,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
application.setCategory(category); application.setCategory(category);
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
// Validating the platform
application.setPlatform(platform);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Application creation pre-conditions are met and the platform mentioned by identifier " log.debug("Application creation pre-conditions are met and the platform mentioned by identifier "
+ platform.getIdentifier() + " is found"); + platform.getIdentifier() + " is found");
@ -104,7 +100,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
lifecycle.setLifecycleStateModifiedAt(new Date()); lifecycle.setLifecycleStateModifiedAt(new Date());
lifecycle.setGetLifecycleStateModifiedBy(application.getUser().getUserName()); lifecycle.setGetLifecycleStateModifiedBy(application.getUser().getUserName());
application.setCurrentLifecycle(lifecycle); application.setCurrentLifecycle(lifecycle);
application = DAOFactory.getApplicationDAO().createApplication(application); application = DAOFactory.getApplicationDAO().createApplication(application);
DataHolder.getInstance().getVisibilityManager().put(application.getId(), application.getVisibility()); DataHolder.getInstance().getVisibilityManager().put(application.getId(), application.getVisibility());
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
@ -142,7 +137,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ " is not found. Please give a valid platform identifier."); + " is not found. Please give a valid platform identifier.");
} }
application.setPlatform(platform); application.setPlatform(platform);
if (application.getCategory() != null) { if (application.getCategory() != null) {
String applicationCategoryName = application.getCategory().getName(); String applicationCategoryName = application.getCategory().getName();
if (applicationCategoryName == null || applicationCategoryName.isEmpty()) { if (applicationCategoryName == null || applicationCategoryName.isEmpty()) {
@ -158,7 +152,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
application.setCategory(category); application.setCategory(category);
} }
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();

@ -44,9 +44,8 @@ public class CategoryManagerImpl implements CategoryManager {
"Application category name cannot be null. Application category creation failed."); "Application category name cannot be null. Application category creation failed.");
} }
if (getCategory(category.getName()) != null) { if (getCategory(category.getName()) != null) {
throw new ApplicationCategoryManagementException( throw new ApplicationCategoryManagementException("Application category wth the name " + category.getName()
"Application category wth the name " + category.getName() + " " + "exists already. Please select a different name");
+ "exists already. Please select a different name");
} }
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();

Loading…
Cancel
Save