diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Payment.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Payment.java index 8eabdef6444..e73802df1ca 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Payment.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Payment.java @@ -22,7 +22,7 @@ public class Payment { private String paymentCurrency; - private Float paymentPrice; + private float paymentPrice; public boolean isFreeApp() { return freeApp; @@ -40,11 +40,11 @@ public class Payment { this.paymentCurrency = paymentCurrency; } - public Float getPaymentPrice() { + public float getPaymentPrice() { return paymentPrice; } - public void setPaymentPrice(Float paymentPrice) { + public void setPaymentPrice(float paymentPrice) { this.paymentPrice = paymentPrice; } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/PlatformDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/PlatformDAO.java index 0a6f93809d1..8aa524f138e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/PlatformDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/PlatformDAO.java @@ -42,4 +42,7 @@ public interface PlatformDAO { Platform getPlatform(String tenantDomain, String platformIdentifier) throws PlatformManagementDAOException; + Platform getPlatform(int tenantId, String identifier) throws PlatformManagementDAOException; + + } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/MySQLApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/MySQLApplicationDAOImpl.java index a0185ed40fa..2fe6d947516 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/MySQLApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/MySQLApplicationDAOImpl.java @@ -150,8 +150,13 @@ public class MySQLApplicationDAOImpl extends AbstractApplicationDAOImpl { sql += "UPDATE APPM_APPLICATION SET "; sql += "NAME = IFNULL (?, NAME), "; sql += "SHORT_DESCRIPTION = IFNULL (?, SHORT_DESCRIPTION), DESCRIPTION = IFNULL (?, DESCRIPTION), "; - sql += "ICON_NAME = IFNULL (?, ICON_NAME), BANNER_NAME = IFNULL (?, BANNER_NAME) "; - sql += " WHERE UUID = ?"; + sql += "ICON_NAME = IFNULL (?, ICON_NAME), BANNER_NAME = IFNULL (?, BANNER_NAME), "; + sql += "VIDEO_NAME = IFNULL (?, VIDEO_NAME), SCREENSHOTS = IFNULL (?, SCREENSHOTS), "; + sql += "MODIFIED_AT = IFNULL (?, MODIFIED_AT), IS_FREE = IFNULL (?, IS_FREE), "; + sql += "PAYMENT_CURRENCY = IFNULL (?, PAYMENT_CURRENCY), PAYMENT_PRICE = IFNULL (?, PAYMENT_PRICE), "; + sql += "APPLICATION_CATEGORY_ID = IFNULL (?, APPLICATION_CATEGORY_ID), PLATFORM_ID = IFNULL (?, PLATFORM_ID), "; + sql += "TENANT_ID = IFNULL (?, TENANT_ID) "; + sql += "WHERE UUID = ?"; stmt = conn.prepareStatement(sql); @@ -160,18 +165,16 @@ public class MySQLApplicationDAOImpl extends AbstractApplicationDAOImpl { stmt.setString(3, application.getDescription()); stmt.setString(4, application.getIconName()); stmt.setString(5, application.getBannerName()); - stmt.setString(6, application.getUuid()); -// stmt.setString(7, application.getVideoName()); -// stmt.setString(8, JSONUtil.listToJsonArrayString(application.getScreenshots())); -// stmt.setString(9, application.getUser().getUserName()); -// stmt.setDate(10, new Date(application.getCreatedAt().getTime())); -// stmt.setDate(11, new Date(application.getModifiedAt().getTime())); -// stmt.setInt(12, application.getCategory().getId()); -// stmt.setInt(13, application.getPlatform().getId()); -// stmt.setInt(14, application.getUser().getTenantId()); -// stmt.setInt(15, application.getCurrentLifecycle().getLifecycleState().getId()); -// stmt.setDate(16, new Date(application.getCurrentLifecycle().getLifecycleStateModifiedAt().getTime())); -// stmt.setString(17, application.getCurrentLifecycle().getGetLifecycleStateModifiedBy()); + stmt.setString(6, application.getVideoName()); + stmt.setString(7, JSONUtil.listToJsonArrayString(application.getScreenshots())); + stmt.setDate(8, new Date(application.getModifiedAt().getTime())); + stmt.setBoolean(9, application.getPayment().isFreeApp()); + stmt.setString(10, application.getPayment().getPaymentCurrency()); + stmt.setFloat(11, application.getPayment().getPaymentPrice()); + stmt.setInt(12, application.getCategory().getId()); + stmt.setInt(13, application.getPlatform().getId()); + stmt.setInt(14, application.getUser().getTenantId()); + stmt.setString(15, application.getUuid()); stmt.executeUpdate(); // if (application.getTags() != null && application.getTags().size() > 0) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/GenericPlatformDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/GenericPlatformDAOImpl.java index ddbcf91286e..8499c0c3cff 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/GenericPlatformDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/GenericPlatformDAOImpl.java @@ -412,4 +412,39 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD } } + public Platform getPlatform(int tenantId, String identifier) throws PlatformManagementDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; + String sql = ""; + + try { + conn = this.getConnection(); + sql += "SELECT * "; + sql += "FROM APPM_PLATFORM "; + sql += "WHERE IDENTIFIER = ? "; + + stmt = conn.prepareStatement(sql); + stmt.setString(1, identifier); + rs = stmt.executeQuery(); + + Platform platform = null; + + if (rs.next()) { + platform = new Platform(); + platform.setId(rs.getInt("ID")); + platform.setName(rs.getString("NAME")); + platform.setIdentifier(rs.getString("IDENTIFIER")); + } + + return platform; + + } catch (SQLException e) { + throw new PlatformManagementDAOException("Error occurred while getting application List", e); + } catch (DBConnectionException e) { + throw new PlatformManagementDAOException("Error occurred while obtaining the DB connection.", e); + } + } + } 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 5b2e4e5f2ff..392273d0764 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 @@ -18,19 +18,16 @@ */ package org.wso2.carbon.device.application.mgt.core.impl; -import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.common.*; 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.services.ApplicationManager; -import org.wso2.carbon.device.application.mgt.common.services.PlatformManager; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; 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.common.DAOFactory; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.exception.ValidationException; -import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.HelperUtil; @@ -68,9 +65,8 @@ public class ApplicationManagerImpl implements ApplicationManager { lifecycle.setGetLifecycleStateModifiedBy(application.getUser().getUserName()); application.setCurrentLifecycle(lifecycle); - PlatformManager platformManager = DataHolder.getInstance().getPlatformManager(); - Platform platform = platformManager.getPlatform(PrivilegedCarbonContext.getThreadLocalCarbonContext(). - getTenantDomain(true), application.getPlatform().getIdentifier()); + PlatformDAO platformDAO = DAOFactory.getPlatformDAO(); + Platform platform = platformDAO.getPlatform(application.getUser().getTenantId(), application.getPlatform().getIdentifier()); if (platform == null) { throw new NotFoundException("Invalid platform"); } @@ -87,12 +83,34 @@ public class ApplicationManagerImpl implements ApplicationManager { @Override public Application editApplication(Application application) throws ApplicationManagementException { - validateApplication(application, true); + if (application.getUuid() == null) { + throw new ValidationException("Application UUID cannot be empty"); + } try { ConnectionManagerUtil.openConnection(); ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); + if (application.getCategory() == null) { + application.setCategory(new Category()); + } + + if (application.getPlatform() == null) { + application.setPlatform(new Platform()); + } else { + PlatformDAO platformDAO = DAOFactory.getPlatformDAO(); + Platform platform = platformDAO.getPlatform(application.getUser().getTenantId(), application.getPlatform() + .getIdentifier()); + application.setPlatform(platform); + if (platform == null) { + throw new NotFoundException("Invalid platform"); + } + } + + if (application.getPayment() == null) { + application.setPayment(new Payment()); + } + application.setModifiedAt(new Date()); return applicationDAO.editApplication(application); @@ -131,13 +149,12 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ValidationException("Username and tenant Id cannot be empty"); } - if (!isEdit) { - if (application.getCategory() == null || application.getCategory().getId() == 0) { - throw new ValidationException("Category id cannot be empty"); - } - if (application.getPlatform() == null || application.getPlatform().getIdentifier() == null) { - throw new ValidationException("Platform identifier cannot be empty"); - } + if (application.getCategory() == null || application.getCategory().getId() == 0) { + throw new ValidationException("Category id cannot be empty"); + } + + if (application.getPlatform() == null || application.getPlatform().getIdentifier() == null) { + throw new ValidationException("Platform identifier cannot be empty"); }