From 053008932dcaa469b2c16dca65e9721e179e8779 Mon Sep 17 00:00:00 2001 From: megala21 Date: Wed, 23 Aug 2017 16:36:11 +0530 Subject: [PATCH] Minor fixes to mysql script and refactoring --- .../services/impl/ApplicationManagementAPIImpl.java | 1 + .../common/services/ApplicationReleaseManager.java | 2 +- .../application/mgt/core/dao/common/Util.java | 1 - .../impl/application/GenericApplicationDAOImpl.java | 13 ++++++++----- .../core/impl/ApplicationStorageManagerImpl.java | 9 +++++++-- .../dbscripts/cdm/application-mgt/mysql.sql | 4 ++-- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java index 2c08e5fae7..ad968282b4 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java @@ -433,6 +433,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @Override @GET @Path("/image-artifacts/{uuid}") + @Produces(MediaType.APPLICATION_OCTET_STREAM) public Response getApplicationImageArtifacts(@PathParam("uuid") String applicationUUID, @QueryParam("name") String name, @QueryParam("count") int count) { if (name == null || name.isEmpty()) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationReleaseManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationReleaseManager.java index db1a852f9b..a97050d19f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationReleaseManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationReleaseManager.java @@ -25,7 +25,7 @@ import java.util.List; /** * ApplicationReleaseManager is responsible for handling all the operations related with - * {@link org.wso2.carbon.device.application.mgt.common.ApplicationRelease} which involving addition, updation , + * {@link org.wso2.carbon.device.application.mgt.common.ApplicationRelease} which involving addition, updating , * deletion and viewing. * */ diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java index 9354d1bddb..769e8a50ed 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java @@ -27,7 +27,6 @@ import org.wso2.carbon.device.application.mgt.common.Lifecycle; import org.wso2.carbon.device.application.mgt.common.LifecycleState; import org.wso2.carbon.device.application.mgt.common.Platform; import org.wso2.carbon.device.application.mgt.common.User; -import org.wso2.carbon.device.application.mgt.core.util.JSONUtil; import java.sql.PreparedStatement; import java.sql.ResultSet; 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/GenericApplicationDAOImpl.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/GenericApplicationDAOImpl.java index 51747a46a7..6f921a104b 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/GenericApplicationDAOImpl.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/GenericApplicationDAOImpl.java @@ -138,7 +138,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic + "LS.DESCRIPTION AS LS_DESCRIPTION FROM APPM_APPLICATION AS APP INNER JOIN APPM_PLATFORM AS " + "APL ON APP.PLATFORM_ID = APL.ID INNER JOIN APPM_APPLICATION_CATEGORY AS CAT ON " + "APP.APPLICATION_CATEGORY_ID = CAT.ID INNER JOIN APPM_LIFECYCLE_STATE AS " - + "LS ON APP.LIFECYCLE_STATE_ID = LS.ID WHERE APP.TENANT_ID = ?"; + + "LS ON APP.LIFECYCLE_STATE_ID = LS.ID WHERE APP.TENANT_ID = ? "; if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) { sql += "AND APP.NAME LIKE ? "; @@ -181,11 +181,14 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic applicationList.setApplications(applications); applicationList.setPagination(pagination); } catch (SQLException e) { - throw new ApplicationManagementDAOException("Error occurred while getting application List", e); + throw new ApplicationManagementDAOException("Error occurred while getting application list for the tenant" + + " " + tenantId + ". While executing " + sql, e); } catch (JSONException e) { - throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e); + throw new ApplicationManagementDAOException("Error occurred while parsing JSON, while getting application" + + " list for the tenant " + tenantId, e); } catch (DBConnectionException e) { - throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); + throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection while " + + "getting application list for the tenant " + tenantId, e); } finally { Util.cleanupResources(stmt, rs); } @@ -385,7 +388,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic statement.setInt(1, count); statement.setString(2, applicationUUID); statement.setInt(3, tenantId); - + statement.executeUpdate(); } catch (DBConnectionException e) { throw new ApplicationManagementDAOException("Database connection while trying to update the screen-shot " + "count for the application with UUID " + applicationUUID + " for the tenant " + tenantId); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java index 2a72e7ef55..287cd5370b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationStorageManagerImpl.java @@ -96,20 +96,25 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager } try { ConnectionManagerUtil.beginDBTransaction(); - DAOFactory.getApplicationDAO().updateScreenShotCount(applicationUUID, tenantId, count); - ConnectionManagerUtil.closeDBConnection(); + DAOFactory.getApplicationDAO().updateScreenShotCount(applicationUUID, tenantId, count - 1); + ConnectionManagerUtil.commitDBTransaction(); } catch (TransactionManagementException e) { + ConnectionManagerUtil.rollbackDBTransaction(); throw new ApplicationStorageManagementException("Transaction Management exception while trying to " + "update the screen-shot count of the application " + applicationUUID + " for the tenant " + tenantId, e); } catch (DBConnectionException e) { + ConnectionManagerUtil.rollbackDBTransaction(); throw new ApplicationStorageManagementException("Database connection management exception while " + "trying to update the screen-shot count for the application " + applicationUUID + " for the" + " tenant " + tenantId, e); } catch (ApplicationManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); throw new ApplicationStorageManagementException("Application Management DAO exception while trying to" + " update the screen-shot count for the application " + applicationUUID + " for the tenant " + tenantId, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); } } } diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index cbf35064b3..4845697026 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -305,8 +305,8 @@ CREATE TABLE IF NOT EXISTS `APPM_PLATFORM_TENANT_MAPPING` ( CONSTRAINT `fk_APPM_PLATFORM_TENANT_MAPPING_APPM_SUPPORTED_PLATFORM1` FOREIGN KEY (`PLATFORM_ID`) REFERENCES `APPM_PLATFORM` (`ID`) - ON DELETE NO ACTION - ON UPDATE NO ACTION) + ON DELETE CASCADE + ON UPDATE CASCADE ) ENGINE = InnoDB COMMENT = 'This table contains the data related relationship between application platofrm and appication mappings';