Refactor edit apps functionality

feature/appm-store/pbac
Chatura Dilan 8 years ago
parent 58eab35123
commit d3f87a30ed

@ -22,7 +22,7 @@ public class Payment {
private String paymentCurrency; private String paymentCurrency;
private Float paymentPrice; private float paymentPrice;
public boolean isFreeApp() { public boolean isFreeApp() {
return freeApp; return freeApp;
@ -40,11 +40,11 @@ public class Payment {
this.paymentCurrency = paymentCurrency; this.paymentCurrency = paymentCurrency;
} }
public Float getPaymentPrice() { public float getPaymentPrice() {
return paymentPrice; return paymentPrice;
} }
public void setPaymentPrice(Float paymentPrice) { public void setPaymentPrice(float paymentPrice) {
this.paymentPrice = paymentPrice; this.paymentPrice = paymentPrice;
} }
} }

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

@ -150,8 +150,13 @@ public class MySQLApplicationDAOImpl extends AbstractApplicationDAOImpl {
sql += "UPDATE APPM_APPLICATION SET "; sql += "UPDATE APPM_APPLICATION SET ";
sql += "NAME = IFNULL (?, NAME), "; sql += "NAME = IFNULL (?, NAME), ";
sql += "SHORT_DESCRIPTION = IFNULL (?, SHORT_DESCRIPTION), DESCRIPTION = IFNULL (?, DESCRIPTION), "; 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 += " WHERE UUID = ?"; 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); stmt = conn.prepareStatement(sql);
@ -160,18 +165,16 @@ public class MySQLApplicationDAOImpl extends AbstractApplicationDAOImpl {
stmt.setString(3, application.getDescription()); stmt.setString(3, application.getDescription());
stmt.setString(4, application.getIconName()); stmt.setString(4, application.getIconName());
stmt.setString(5, application.getBannerName()); stmt.setString(5, application.getBannerName());
stmt.setString(6, application.getUuid()); stmt.setString(6, application.getVideoName());
// stmt.setString(7, application.getVideoName()); stmt.setString(7, JSONUtil.listToJsonArrayString(application.getScreenshots()));
// stmt.setString(8, JSONUtil.listToJsonArrayString(application.getScreenshots())); stmt.setDate(8, new Date(application.getModifiedAt().getTime()));
// stmt.setString(9, application.getUser().getUserName()); stmt.setBoolean(9, application.getPayment().isFreeApp());
// stmt.setDate(10, new Date(application.getCreatedAt().getTime())); stmt.setString(10, application.getPayment().getPaymentCurrency());
// stmt.setDate(11, new Date(application.getModifiedAt().getTime())); stmt.setFloat(11, application.getPayment().getPaymentPrice());
// stmt.setInt(12, application.getCategory().getId()); stmt.setInt(12, application.getCategory().getId());
// stmt.setInt(13, application.getPlatform().getId()); stmt.setInt(13, application.getPlatform().getId());
// stmt.setInt(14, application.getUser().getTenantId()); stmt.setInt(14, application.getUser().getTenantId());
// stmt.setInt(15, application.getCurrentLifecycle().getLifecycleState().getId()); stmt.setString(15, application.getUuid());
// stmt.setDate(16, new Date(application.getCurrentLifecycle().getLifecycleStateModifiedAt().getTime()));
// stmt.setString(17, application.getCurrentLifecycle().getGetLifecycleStateModifiedBy());
stmt.executeUpdate(); stmt.executeUpdate();
// if (application.getTags() != null && application.getTags().size() > 0) { // 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; 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.*;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; 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.DBConnectionException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; 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.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO; 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.PlatformDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory; 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.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.exception.ValidationException; 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.ConnectionManagerUtil;
import org.wso2.carbon.device.application.mgt.core.util.HelperUtil; import org.wso2.carbon.device.application.mgt.core.util.HelperUtil;
@ -68,9 +65,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
lifecycle.setGetLifecycleStateModifiedBy(application.getUser().getUserName()); lifecycle.setGetLifecycleStateModifiedBy(application.getUser().getUserName());
application.setCurrentLifecycle(lifecycle); application.setCurrentLifecycle(lifecycle);
PlatformManager platformManager = DataHolder.getInstance().getPlatformManager(); PlatformDAO platformDAO = DAOFactory.getPlatformDAO();
Platform platform = platformManager.getPlatform(PrivilegedCarbonContext.getThreadLocalCarbonContext(). Platform platform = platformDAO.getPlatform(application.getUser().getTenantId(), application.getPlatform().getIdentifier());
getTenantDomain(true), application.getPlatform().getIdentifier());
if (platform == null) { if (platform == null) {
throw new NotFoundException("Invalid platform"); throw new NotFoundException("Invalid platform");
} }
@ -87,12 +83,34 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override @Override
public Application editApplication(Application application) throws ApplicationManagementException { public Application editApplication(Application application) throws ApplicationManagementException {
validateApplication(application, true); if (application.getUuid() == null) {
throw new ValidationException("Application UUID cannot be empty");
}
try { try {
ConnectionManagerUtil.openConnection(); ConnectionManagerUtil.openConnection();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); 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()); application.setModifiedAt(new Date());
return applicationDAO.editApplication(application); return applicationDAO.editApplication(application);
@ -131,13 +149,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ValidationException("Username and tenant Id cannot be empty"); throw new ValidationException("Username and tenant Id cannot be empty");
} }
if (!isEdit) { if (application.getCategory() == null || application.getCategory().getId() == 0) {
if (application.getCategory() == null || application.getCategory().getId() == 0) { throw new ValidationException("Category id cannot be empty");
throw new ValidationException("Category id cannot be empty"); }
}
if (application.getPlatform() == null || application.getPlatform().getIdentifier() == null) { if (application.getPlatform() == null || application.getPlatform().getIdentifier() == null) {
throw new ValidationException("Platform identifier cannot be empty"); throw new ValidationException("Platform identifier cannot be empty");
}
} }

Loading…
Cancel
Save