From 349c3bdb63f41e074a3e47a697c7110faefd6cc9 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Thu, 11 Aug 2016 15:56:03 +0530 Subject: [PATCH] fixing App Version not updating in portal after being initially set --- .../mgt/common/app/mgt/Application.java | 3 ++ ...ApplicationManagerProviderServiceImpl.java | 11 ++++---- .../device/mgt/core/dao/ApplicationDAO.java | 2 ++ .../mgt/core/dao/impl/ApplicationDAOImpl.java | 28 +++++++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/Application.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/Application.java index 82e3108149d..ecbafd974c2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/Application.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/Application.java @@ -150,6 +150,9 @@ public class Application implements Serializable { if (applicationIdentifier != null ? !applicationIdentifier.equals(that.applicationIdentifier) : that.applicationIdentifier != null) { return false; } + if (version != null ? !version.equals(that.version) : that.version != null) { + return false; + } return true; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index 18f61261f00..d03d7b16121 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -97,8 +97,8 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem if (deviceIds.size() > 0) { type = deviceIds.get(0).getType().toLowerCase(); } - Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider(). - addOperation(type, operation, deviceIds); + Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider(). + addOperation(type, operation, deviceIds); DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().notifyOperationToDevices (operation, deviceIds); return activity; @@ -217,13 +217,14 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem appIdsToRemove.add(installedApp.getId()); } } - + applicationMappingDAO.removeApplicationMapping(device.getId(), appIdsToRemove, tenantId); Application installedApp; List applicationIds = new ArrayList<>(); for (Application application : applications) { if (!installedAppList.contains(application)) { - installedApp = applicationDAO.getApplication(application.getApplicationIdentifier(), tenantId); + installedApp = applicationDAO.getApplication(application.getApplicationIdentifier(), + application.getVersion(), tenantId); if (installedApp == null) { appsToAdd.add(application); } else { @@ -244,7 +245,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem if (log.isDebugEnabled()) { log.debug("num of remove app Ids:" + appIdsToRemove.size()); } - applicationMappingDAO.removeApplicationMapping(device.getId(), appIdsToRemove, tenantId); + DeviceManagementDAOFactory.commitTransaction(); } catch (DeviceManagementDAOException e) { DeviceManagementDAOFactory.rollbackTransaction(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/ApplicationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/ApplicationDAO.java index 5cc8b3c7d6e..e5e91f28bc0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/ApplicationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/ApplicationDAO.java @@ -32,5 +32,7 @@ public interface ApplicationDAO { Application getApplication(String identifier, int tenantId) throws DeviceManagementDAOException; + Application getApplication(String identifier, String version,int tenantId) throws DeviceManagementDAOException; + List getInstalledApplications(int deviceId) throws DeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java index a9312623aed..c391f1057f6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java @@ -228,6 +228,34 @@ public class ApplicationDAOImpl implements ApplicationDAO { } } + @Override + public Application getApplication(String identifier, String version, int tenantId) throws DeviceManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + Application application = null; + try { + conn = this.getConnection(); + stmt = conn.prepareStatement("SELECT ID, NAME, APP_IDENTIFIER, PLATFORM, CATEGORY, VERSION, TYPE, " + + "LOCATION_URL, IMAGE_URL, APP_PROPERTIES, MEMORY_USAGE, IS_ACTIVE, TENANT_ID FROM DM_APPLICATION WHERE APP_IDENTIFIER = ? " + + "AND VERSION = ? AND TENANT_ID = ?"); + stmt.setString(1, identifier); + stmt.setString(2, version); + stmt.setInt(3, tenantId); + rs = stmt.executeQuery(); + + if (rs.next()) { + application = this.loadApplication(rs); + } + return application; + } catch (SQLException e) { + throw new DeviceManagementDAOException("Error occurred while retrieving application application '" + + identifier + "' and version '" + version + "'.", e); + } finally { + DeviceManagementDAOUtil.cleanupResources(stmt, rs); + } + } + private Connection getConnection() throws SQLException { return DeviceManagementDAOFactory.getConnection(); }