diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java index a77e238dd5..0d21468ddc 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java @@ -35,7 +35,7 @@ public interface ApplicationReleaseDAO { * @return Unique ID of the relevant release. * @throws ApplicationManagementDAOException Application Management DAO Exception. */ - ApplicationRelease createRelease(ApplicationRelease applicationRelease, int appId) throws + ApplicationRelease createRelease(ApplicationRelease applicationRelease, int appId, int tenantId) throws ApplicationManagementDAOException; /** @@ -67,11 +67,15 @@ public interface ApplicationReleaseDAO { /** * To update an Application release. + * * @param applicationRelease ApplicationRelease that need to be updated. + * @param applicationId Id of the application. + * @param tenantId Id of the tenant * @return the updated Application Release * @throws ApplicationManagementDAOException Application Management DAO Exception */ - ApplicationRelease updateRelease(ApplicationRelease applicationRelease) throws ApplicationManagementDAOException; + ApplicationRelease updateRelease(int applicationId, ApplicationRelease applicationRelease, int tenantId) throws + ApplicationManagementDAOException; /** * To update an Application release. 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 5c48f38486..8edab08af3 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 @@ -45,7 +45,7 @@ public class Util { /** * To create application object from the result set retrieved from the Database. * - * @param rs ResultSet + * @param rs ResultSet * @return List of Applications that is retrieved from the Database. * @throws SQLException SQL Exception * @throws JSONException JSONException. @@ -53,13 +53,13 @@ public class Util { public static List loadApplications(ResultSet rs) throws SQLException, JSONException { List applications = new ArrayList<>(); - Application application = null ; + Application application = null; int applicatioId = -1; - while (rs.next()){ - if (applicatioId != rs.getInt("APP_ID")){ + while (rs.next()) { + if (applicatioId != rs.getInt("APP_ID")) { - if( application != null){ + if (application != null) { applications.add(application); } applicatioId = rs.getInt("APP_ID"); @@ -82,20 +82,20 @@ public class Util { unrestrictedRole.setRole(rs.getString("ROLE")); unrestrictedRoles.add(unrestrictedRole); application.setUnrestrictedRoles(unrestrictedRoles); - }else{ + } else { Tag tag = new Tag(); tag.setTagName(rs.getString("APP_TAG")); UnrestrictedRole unrestrictedRole = new UnrestrictedRole(); unrestrictedRole.setRole(rs.getString("ROLE")); - if (application != null && application.getTags().contains(tag)){ + if (application != null && application.getTags().contains(tag)) { application.getTags().add(tag); } - if (application != null && application.getUnrestrictedRoles().contains(unrestrictedRole)){ + if (application != null && application.getUnrestrictedRoles().contains(unrestrictedRole)) { application.getUnrestrictedRoles().add(unrestrictedRole); } } - if(rs.last()){ + if (rs.last()) { applications.add(application); } } @@ -108,7 +108,7 @@ public class Util { /** * To create application object from the result set retrieved from the Database. * - * @param rs ResultSet + * @param rs ResultSet * @return Application that is retrieved from the Database. * @throws SQLException SQL Exception * @throws JSONException JSONException. @@ -116,11 +116,11 @@ public class Util { public static Application loadApplication(ResultSet rs) throws SQLException, JSONException { Application application = null; - int applicatioId = -1; + int applicatioId; int iteration = 0; - while (rs.next()){ - if (iteration == 0){ + while (rs.next()) { + if (iteration == 0) { application = new Application(); applicatioId = rs.getInt("APP_ID"); application.setId(applicatioId); @@ -135,10 +135,10 @@ public class Util { tag.setTagName(rs.getString("APP_TAG")); UnrestrictedRole unrestrictedRole = new UnrestrictedRole(); unrestrictedRole.setRole(rs.getString("ROLE")); - if (application.getTags().contains(tag)){ + if (application.getTags().contains(tag)) { application.getTags().add(tag); } - if (application.getUnrestrictedRoles().contains(unrestrictedRole)){ + if (application.getUnrestrictedRoles().contains(unrestrictedRole)) { application.getUnrestrictedRoles().add(unrestrictedRole); } iteration++; @@ -159,7 +159,6 @@ public class Util { appRelease.setId(rs.getInt("RELEASE_ID")); appRelease.setVersion(rs.getString("VERSION")); - appRelease.setTenantId(rs.getString("TENANT_ID")); appRelease.setUuid(rs.getString("UUID")); appRelease.setReleaseType(rs.getString("RELEASE_TYPE")); appRelease.setPrice(rs.getDouble("APP_PRICE")); @@ -179,6 +178,7 @@ public class Util { return appRelease; } + /** * Cleans up the statement and resultset after executing the query * @@ -203,14 +203,15 @@ public class Util { } public static PaginationRequest validateCommentListPageSize(PaginationRequest paginationRequest) throws - CommentManagementException{ + CommentManagementException { if (paginationRequest.getLimit() == 0) { Configuration commentManagementConfig = ConfigurationManager.getInstance().getConfiguration(); if (commentManagementConfig != null) { - paginationRequest.setLimit(commentManagementConfig.getPaginationConfiguration().getCommentListPageSize()); + paginationRequest.setLimit( + commentManagementConfig.getPaginationConfiguration().getCommentListPageSize()); } else { throw new CommentManagementException("Device-Mgt configuration has not initialized. Please check the " + - "cdm-config.xml file."); + "cdm-config.xml file."); } } return paginationRequest; 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 19d7da56e8..270ad8dd3f 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 @@ -57,7 +57,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic log.debug("Request received in DAO Layer to create an application"); log.debug("Application Details : "); log.debug("App Name : " + application.getName() + " App Type : " - + application.getType() + " User Name : " + application.getUser().getUserName()); + + application.getType() + " User Name : " + application.getUser().getUserName()); } Connection conn; PreparedStatement stmt = null; @@ -66,8 +66,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic try { conn = this.getDBConnection(); stmt = conn.prepareStatement("INSERT INTO AP_APP (NAME, TYPE, APP_CATEGORY, " - + "IS_FREE, PAYMENT_CURRENCY, RESTRICTED, TENANT_ID) VALUES " - + "(?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS); + + "IS_FREE, PAYMENT_CURRENCY, RESTRICTED, TENANT_ID) VALUES " + + "(?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS); stmt.setString(1, application.getName()); stmt.setString(2, application.getType()); stmt.setString(3, application.getAppCategory()); @@ -84,7 +84,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic return applicationId; } catch (DBConnectionException e) { - throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection when application creation", e); + throw new ApplicationManagementDAOException( + "Error occurred while obtaining the DB connection when application creation", e); } catch (SQLException e) { throw new ApplicationManagementDAOException("Error occurred while adding the application", e); } finally { @@ -113,7 +114,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic stmt.executeBatch(); } catch (DBConnectionException e) { - throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection when adding tags", e); + throw new ApplicationManagementDAOException( + "Error occurred while obtaining the DB connection when adding tags", e); } catch (SQLException e) { throw new ApplicationManagementDAOException("Error occurred while adding tags", e); } finally { @@ -131,7 +133,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic ResultSet rs = null; int isExist = 0; String sql = "SELECT * FROM AP_APP WHERE NAME = ? AND TYPE = ? AND TENANT_ID = ?"; - try{ + try { conn = this.getDBConnection(); conn.setAutoCommit(false); stmt = conn.prepareStatement(sql); @@ -146,7 +148,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic return isExist; } catch (DBConnectionException e) { - throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection when verifying application existence", e); + throw new ApplicationManagementDAOException( + "Error occurred while obtaining the DB connection when verifying application existence", e); } catch (SQLException e) { throw new ApplicationManagementDAOException("Error occurred while adding unrestricted roles", e); } finally { @@ -167,7 +170,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic ApplicationList applicationList = new ApplicationList(); Pagination pagination = new Pagination(); String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY" - + " AS APP_CATEGORY, AP_APP.IS_FREE, AP_APP.RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLES.ROLE " + + + " AS APP_CATEGORY, AP_APP.IS_FREE, AP_APP.RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, " + + "AP_UNRESTRICTED_ROLES.ROLE " + "AS APP_UNRESTRICTED_ROLES FROM ((AP_APP LEFT JOIN AP_APP_TAG ON AP_APP.ID = AP_APP_TAG.AP_APP_ID) " + "LEFT JOIN AP_UNRESTRICTED_ROLES ON AP_APP.ID = AP_UNRESTRICTED_ROLES.AP_APP_ID) " + "WHERE AP_APP.TENANT_ID = ?"; @@ -221,10 +226,11 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } catch (SQLException e) { throw new ApplicationManagementDAOException("Error occurred while getting application list for the tenant" - + " " + tenantId + ". While executing " + sql, e); + + " " + tenantId + ". While executing " + sql, e); } catch (DBConnectionException e) { throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection while " - + "getting application list for the tenant " + tenantId, e); + + "getting application list for the tenant " + tenantId, + e); } catch (JSONException e) { throw new ApplicationManagementDAOException("Error occurred while parsing JSON ", e); } finally { @@ -262,7 +268,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic throw new ApplicationManagementDAOException("Error occurred while getting uuid of latest app release", e); } catch (DBConnectionException e) { throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection for " - + "getting app release id", e); + + "getting app release id", e); } finally { Util.cleanupResources(stmt, rs); } @@ -315,20 +321,24 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic @Override public Application getApplication(String appName, String appType, int tenantId) throws - ApplicationManagementDAOException { + ApplicationManagementDAOException { if (log.isDebugEnabled()) { log.debug("Getting application with the type(" + appType + " and Name " + appName + - " ) from the database"); + " ) from the database"); } Connection conn; PreparedStatement stmt = null; ResultSet rs = null; try { conn = this.getDBConnection(); - String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " - + "AS APP_CATEGORY, AP_APP.IS_FREE AS IS_FREE, AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS " + - "APP_TAG, AP_UNRESTRICTED_ROLES.ROLE AS AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES " + - "WHERE AP_APP.NAME=? AND AP_APP.TYPE= ? AND AP_APP.TENANT_ID=?;"; + String sql = + "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " + + + "AS APP_CATEGORY, AP_APP.IS_FREE AS IS_FREE, AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG" + + ".TAG AS " + + "APP_TAG, AP_UNRESTRICTED_ROLES.ROLE AS AS ROLE FROM AP_APP, AP_APP_TAG, " + + "AP_UNRESTRICTED_ROLES " + + "WHERE AP_APP.NAME=? AND AP_APP.TYPE= ? AND AP_APP.TENANT_ID=?;"; stmt = conn.prepareStatement(sql); stmt.setString(1, appName); @@ -338,14 +348,15 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic if (log.isDebugEnabled()) { log.debug("Successfully retrieved basic details of the application with the type " - + appType + "and app name " + appName); + + appType + "and app name " + appName); } return Util.loadApplication(rs); } catch (SQLException e) { throw new ApplicationManagementDAOException( - "Error occurred while getting application details with app name " + appName + " While executing query ", e); + "Error occurred while getting application details with app name " + appName + + " While executing query ", e); } catch (JSONException e) { throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e); } catch (DBConnectionException e) { @@ -357,7 +368,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic @Override public Application getApplicationById(int applicationId, int tenantId) throws - ApplicationManagementDAOException { + ApplicationManagementDAOException { if (log.isDebugEnabled()) { log.debug("Getting application with the id (" + applicationId + ") from the database"); } @@ -366,10 +377,14 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic ResultSet rs = null; try { conn = this.getDBConnection(); - String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " + - "AS APP_CATEGORY, AP_APP.IS_FREE AS IS_FREE, AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, " + - "AP_UNRESTRICTED_ROLES.ROLE AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.ID=?" + - " AND AP_APP.TENANT_ID=?;"; + String sql = + "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP" + + ".APP_CATEGORY " + + "AS APP_CATEGORY, AP_APP.IS_FREE AS IS_FREE, AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG" + + ".TAG AS APP_TAG, " + + "AP_UNRESTRICTED_ROLES.ROLE AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE " + + "AP_APP.ID=?" + + " AND AP_APP.TENANT_ID=?;"; stmt = conn.prepareStatement(sql); stmt.setInt(1, applicationId); @@ -378,14 +393,15 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic if (log.isDebugEnabled()) { log.debug("Successfully retrieved basic details of the application with the id " - + applicationId); + + applicationId); } return Util.loadApplication(rs); } catch (SQLException e) { throw new ApplicationManagementDAOException( - "Error occurred while getting application details with app id " + applicationId + " While executing query ", e); + "Error occurred while getting application details with app id " + applicationId + + " While executing query ", e); } catch (JSONException e) { throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e); } catch (DBConnectionException e) { @@ -406,9 +422,12 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic Boolean isAppExist = false; try { conn = this.getDBConnection(); - String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " - + "AS APP_CATEGORY, AP_APP.IS_FREE, AP_APP_TAG.TAG, AP_UNRESTRICTED_ROLES.ROLE AS RELESE_ID FROM " - + "AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.ID=?;"; + String sql = + "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " + + + "AS APP_CATEGORY, AP_APP.IS_FREE, AP_APP_TAG.TAG, AP_UNRESTRICTED_ROLES.ROLE AS RELESE_ID" + + " FROM " + + "AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.ID=?;"; stmt = conn.prepareStatement(sql); stmt.setInt(1, appId); @@ -426,7 +445,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } catch (SQLException e) { throw new ApplicationManagementDAOException( - "Error occurred while getting application details with app ID " + appId + " While executing query ", e); + "Error occurred while getting application details with app ID " + appId + " While executing query ", + e); } catch (DBConnectionException e) { throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); } finally { @@ -447,14 +467,14 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic conn = this.getDBConnection(); String sql = "UPDATE AP_APP SET "; - if (application.getName() != null && !application.getName().equals(existingApplication.getName())) { sql += "NAME = ?, "; } if (application.getType() != null && !application.getType().equals(existingApplication.getType())) { sql += "TYPE = ?, "; } - if (application.getAppCategory() != null && !application.getAppCategory().equals(existingApplication.getAppCategory())) { + if (application.getAppCategory() != null && !application.getAppCategory().equals( + existingApplication.getAppCategory())) { sql += "APP_CATEGORY = ?, "; } if (application.getIsRestricted() != existingApplication.getIsRestricted()) { @@ -473,7 +493,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic if (application.getType() != null && !application.getType().equals(existingApplication.getType())) { stmt.setString(2, application.getType()); } - if (application.getAppCategory() != null && !application.getAppCategory().equals(existingApplication.getAppCategory())) { + if (application.getAppCategory() != null && !application.getAppCategory().equals( + existingApplication.getAppCategory())) { stmt.setString(3, application.getAppCategory()); } if (application.getIsRestricted() != existingApplication.getIsRestricted()) { @@ -539,7 +560,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic @Override public Application getApplicationByRelease(String appReleaseUUID, int tenantId) throws ApplicationManagementDAOException { - if (log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("Getting application with the UUID (" + appReleaseUUID + ") from the database"); } Connection conn; @@ -569,7 +590,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } Application application = null; - while(rs.next()) { + while (rs.next()) { ApplicationRelease appRelease = Util.readApplicationRelease(rs); application = new Application(); @@ -595,7 +616,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic return application; } catch (SQLException e) { throw new ApplicationManagementDAOException("Error occurred while getting application details with UUID " - + appReleaseUUID + " While executing query ", e); + + appReleaseUUID + " While executing query ", e); } catch (JSONException e) { throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e); } catch (DBConnectionException e) { 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/release/GenericApplicationReleaseDAOImpl.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/release/GenericApplicationReleaseDAOImpl.java index 7055674897..cae5816b8b 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/release/GenericApplicationReleaseDAOImpl.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/release/GenericApplicationReleaseDAOImpl.java @@ -28,9 +28,11 @@ import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import java.sql.Connection; +import java.sql.Date; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; @@ -44,10 +46,11 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements * * @param appId Id of the application * @param applicationRelease Application Release the properties of which that need to be inserted. + * @param tenantId Tenant Id * @throws ApplicationManagementDAOException Application Management DAO Exception. */ @Override - public ApplicationRelease createRelease(ApplicationRelease applicationRelease, int appId) throws + public ApplicationRelease createRelease(ApplicationRelease applicationRelease, int appId, int tenantId) throws ApplicationManagementDAOException { Connection connection; PreparedStatement statement = null; @@ -64,7 +67,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements connection = this.getDBConnection(); statement = connection.prepareStatement(sql, generatedColumns); statement.setString(++index, applicationRelease.getVersion()); - statement.setString(++index, applicationRelease.getTenantId()); + statement.setInt(++index, tenantId); statement.setString(++index, applicationRelease.getUuid()); statement.setString(++index, String.valueOf(applicationRelease.getReleaseType())); statement.setDouble(++index, applicationRelease.getPrice()); @@ -267,22 +270,51 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements } } -// have to complete -//Todo /** * To insert the application release properties. * * @param applicationRelease Application Release the properties of which that need to be inserted. - * @throws SQLException SQL Exception. + * @throws ApplicationManagementDAOException Application Management DAO Exception. */ @Override - public ApplicationRelease updateRelease(ApplicationRelease applicationRelease) + public ApplicationRelease updateRelease(int applicationId, ApplicationRelease applicationRelease, int tenantId) throws ApplicationManagementDAOException { + Connection connection; + PreparedStatement statement = null; + String sql = "UPDATE AP_APP_RELEASE SET VERSION = ? AND UUID = ? AND RELEASE_TYPE = ? AND APP_PRICE = ? AND " + + "STORED_LOCATION = ? AND BANNER_LOCATION = ? AND SC_1_LOCATION = ? AND SC_2_LOCATION = ? AND " + + "SC_3_LOCATION = ? AND APP_HASH_VALUE = ? AND SHARED_WITH_ALL_TENANTS = ? AND APP_META_INFO = ? AND " + + "CREATED_BY = ? AND CREATED_AT = ? WHERE AP_APP_ID = ? AND TENANT_ID = ? AND ID = ?;"; + try { + connection = this.getDBConnection(); + statement = connection.prepareStatement(sql); + statement.setString(1, applicationRelease.getVersion()); + statement.setString(2, applicationRelease.getUuid()); + statement.setString(3, applicationRelease.getReleaseType()); + statement.setDouble(4, applicationRelease.getPrice()); + statement.setString(5, applicationRelease.getAppStoredLoc()); + statement.setString(6, applicationRelease.getBannerLoc()); + statement.setString(7, applicationRelease.getScreenshotLoc1()); + statement.setString(8, applicationRelease.getScreenshotLoc2()); + statement.setString(9, applicationRelease.getScreenshotLoc3()); + statement.setString(10, applicationRelease.getAppHashValue()); + statement.setInt(11, applicationRelease.getIsSharedWithAllTenants()); + statement.setString(12, applicationRelease.getMetaData()); + statement.setString(13, applicationRelease.getApplicationCreator()); + statement.setTimestamp(14, new Timestamp(System.currentTimeMillis())); + statement.executeUpdate(); + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException( + "Database connection exception while trying to update the application release", e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException( + "SQL exception while updating the release ,while executing the query " + sql, e); + } finally { + Util.cleanupResources(statement, null); + } return applicationRelease; } -// - /** * To delete an application release. *