Refactor edit apps functionality

4.x.x
Chatura Dilan 8 years ago
parent 58eab35123
commit d3f87a30ed

@ -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;
}
}

@ -42,4 +42,7 @@ public interface PlatformDAO {
Platform getPlatform(String tenantDomain, String platformIdentifier) throws PlatformManagementDAOException;
Platform getPlatform(int tenantId, String identifier) throws PlatformManagementDAOException;
}

@ -150,7 +150,12 @@ 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 += "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 = ?";
@ -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) {

@ -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);
}
}
}

@ -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,14 +149,13 @@ 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");
}
}
}

Loading…
Cancel
Save