diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java index 4aedb87877b..ad8d57cfa4d 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java @@ -31,7 +31,6 @@ import org.wso2.carbon.registry.core.exceptions.RegistryException; import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.user.core.service.RealmService; -import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; @@ -45,7 +44,7 @@ public class APIUtil { private static final String DEFAULT_AGENT_API_TAG = "device_agent"; private static final String DEFAULT_CERT_API_TAG = "scep_management"; private static final String DEFAULT_APP_MGT_TAG = "application_management"; - private static final String DEFAULT_APP_MGT_LCYCLE_MGT_TAG = "lifecycle_management"; + private static final String DEFAULT_APP_MGT_REVIEW_MGT_TAG = "review_management"; private static final String DEFAULT_APP_MGT_SUB_MGT_TAG = "subscription_management"; public static final String PERMISSION_PROPERTY_NAME = "name"; @@ -112,7 +111,7 @@ public class APIUtil { allowedApisTags.add(DEFAULT_CERT_API_TAG); allowedApisTags.add(DEFAULT_AGENT_API_TAG); allowedApisTags.add(DEFAULT_APP_MGT_TAG); - allowedApisTags.add(DEFAULT_APP_MGT_LCYCLE_MGT_TAG); + allowedApisTags.add(DEFAULT_APP_MGT_REVIEW_MGT_TAG); allowedApisTags.add(DEFAULT_APP_MGT_SUB_MGT_TAG); return allowedApisTags; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java index 379ef0f691d..a2113daf165 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java @@ -60,10 +60,6 @@ public class ApplicationRelease { value = "icon file storing location") private String iconLoc; - @ApiModelProperty(name = "applicationCreator", - value = "Application release creator") - private String applicationCreator; - @ApiModelProperty(name = "releaseType", value = "Release type of the application release", required = true, @@ -229,14 +225,6 @@ public class ApplicationRelease { this.screenshotLoc3 = screenshotLoc3; } - public String getApplicationCreator() { - return applicationCreator; - } - - public void setApplicationCreator(String applicationCreator) { - this.applicationCreator = applicationCreator; - } - public String getIconLoc() { return iconLoc; } 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 41e635ef514..3ee7b01b2be 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 @@ -169,7 +169,6 @@ public class Util { appRelease.setAppHashValue(rs.getString("APP_HASH_VALUE")); appRelease.setAppStoredLoc(rs.getString("STORED_LOCATION")); appRelease.setBannerLoc(rs.getString("BANNER_LOCATION")); - appRelease.setApplicationCreator(rs.getString("CREATED_BY")); appRelease.setRating(rs.getDouble("RATING")); appRelease.setIsSharedWithAllTenants(rs.getInt("SHARED_WITH_ALL_TENANTS")); appRelease.setMetaData(rs.getString("APP_META_INFO")); 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/Review/ReviewDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Review/ReviewDAOImpl.java index 5223207374d..5d005d4837e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Review/ReviewDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Review/ReviewDAOImpl.java @@ -34,7 +34,9 @@ import java.sql.SQLException; import java.sql.ResultSet; import java.sql.Connection; import java.sql.PreparedStatement; +import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Calendar; import java.util.List; /** @@ -53,18 +55,23 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { } PreparedStatement statement = null; ResultSet rs = null; - sql = "INSERT INTO AP_APP_REVIEW (TENANT_ID, COMMENT, PARENT_ID, USERNAME, AP_APP_RELEASE_ID, AP_APP_ID) " - + "VALUES (?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?)," + sql = "INSERT INTO AP_APP_REVIEW (TENANT_ID, COMMENT, PARENT_ID, USERNAME,CREATED_AT, MODIFIES_AT," + + " AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?,?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?)," + "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));"; try { + Calendar calendar = Calendar.getInstance(); + Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); + Connection conn = this.getDBConnection(); statement = conn.prepareStatement(sql, new String[] { "id" }); statement.setInt(1, tenantId); statement.setString(2, review.getComment()); statement.setInt(3, review.getParentId()); statement.setString(4, review.getUsername()); - statement.setString(5,uuid); - statement.setString(6,uuid); + statement.setTimestamp(5,timestamp); + statement.setTimestamp(6,timestamp); + statement.setString(7,uuid); + statement.setString(8,uuid); statement.executeUpdate(); rs = statement.getGeneratedKeys(); return rs.next(); @@ -134,15 +141,19 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { Connection connection; PreparedStatement statement = null; ResultSet rs = null; - sql = "UPDATE AP_APP_REVIEW SET COMMENT=?, RATING=? WHERE ID=? AND USERNAME=? AND TENANT_ID=?;"; + sql = "UPDATE AP_APP_REVIEW SET COMMENT=?, RATING=?, MODIFIED_AT=? WHERE ID=? AND USERNAME=? AND TENANT_ID=?;"; try { + Calendar calendar = Calendar.getInstance(); + Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); + connection = this.getDBConnection(); statement = connection.prepareStatement(sql); statement.setString(1, review.getComment()); statement.setInt(2, review.getRating()); - statement.setInt(3, reviewId); - statement.setString(4, username); - statement.setInt(5, tenantId); + statement.setTimestamp(3, timestamp); + statement.setInt(4, reviewId); + statement.setString(5, username); + statement.setInt(6, tenantId); return statement.executeUpdate(); } catch (SQLException e) { throw new ReviewManagementDAOException("Error occurred while executing review updating query"); @@ -206,7 +217,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { conn = this.getDBConnection(); sql = "SELECT AP_APP_REVIEW.ID AS ID, AP_APP_REVIEW.COMMENT AS COMMENT, " + "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, " - + "AP_APP_REVIEW.USERNAME AS USERNAME AP_APP_REVIEW.PARENT_ID AS PARENT_ID " + + "AP_APP_REVIEW.USERNAME AS USERNAME, AP_APP_REVIEW.PARENT_ID AS PARENT_ID " + "FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND " + "AP_APP_RELEASE.UUID =? AND AP_APP_REVIEW.TENANT_ID = ? AND " + "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID LIMIT ? OFFSET ?;"; @@ -230,7 +241,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { throw new ReviewManagementDAOException( "Error occurred while obtaining the DB connection when verifying application existence", e); } catch (SQLException e) { - throw new ReviewManagementDAOException("Error occurred while adding unrestricted roles", e); + throw new ReviewManagementDAOException("DB connection error occurred while getting all reviews", e); }finally { Util.cleanupResources(statement, rs); } 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 ab294dc15ff..d66c7e7dc16 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 @@ -116,7 +116,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic 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); + throw new ApplicationManagementDAOException( + "DB connection error occured while checking whether application exist or not.", e); } finally { Util.cleanupResources(stmt, rs); } 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 f01753a53b7..085c6e3eb2f 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 @@ -21,22 +21,18 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.application.release import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.json.JSONException; -import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.Rating; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; -import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; @@ -65,8 +61,8 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements String sql = "INSERT INTO AP_APP_RELEASE (VERSION,TENANT_ID,UUID,RELEASE_TYPE, PACKAGE_NAME, APP_PRICE," + "STORED_LOCATION, BANNER_LOCATION, SC_1_LOCATION,SC_2_LOCATION,SC_3_LOCATION, APP_HASH_VALUE," - + "SHARED_WITH_ALL_TENANTS, APP_META_INFO,CREATED_BY,AP_APP_ID) " - + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?);"; + + "SHARED_WITH_ALL_TENANTS, APP_META_INFO,AP_APP_ID) " + + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; int index = 0; String generatedColumns[] = {"ID"}; @@ -87,7 +83,6 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements statement.setString(++index, applicationRelease.getAppHashValue()); statement.setInt(++index, applicationRelease.getIsSharedWithAllTenants()); statement.setString(++index, applicationRelease.getMetaData()); - statement.setString(++index, applicationRelease.getApplicationCreator()); statement.setInt(++index, appId); statement.executeUpdate(); resultSet = statement.getGeneratedKeys(); @@ -107,7 +102,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements } /** - * To get release details of a specific application. + * To get latest updated app release details of a specific application. * * @param applicationName Name of the application. * @param applicationType Type of the application. @@ -123,16 +118,15 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements Connection connection; PreparedStatement statement = null; ResultSet resultSet = null; - String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, " - + "AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE, AR.STORED_LOCATION, AR.BANNER_LOCATION, " - + "AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS " - + "SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, " - + "AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, AR.PUBLISHED_BY, AR.PUBLISHED_AT, AR.STARS, " - + "AL.CURRENT_STATE, AL.PREVIOUSE_STATE, AL.UPDATED_BY, AL.UPDATED_AT FROM " - + "AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL WHERE " - + "AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE NAME=? AND TYPE=? AND TENANT_ID=?) " - + "AND AR.VERSION=? AND AR.RELEASE_TYPE=? AND AL.AP_APP_RELEASE_ID=AR.ID " - + "AND AL.TENANT_ID=AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;"; + String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID AS UUID, AR.RELEASE_TYPE AS " + + "RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE AS APP_PRICE, AR.STORED_LOCATION AS " + + "STORED_LOCATION, AR.BANNER_LOCATION AS BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, " + + "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS " + + "HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO AS APP_META_INFO , " + + "AR.RATING AS RATING, AL.CURRENT_STATE, AL.PREVIOUS_STATE, AL.UPDATED_BY, AL.UPDATED_AT FROM " + + "AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL WHERE AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE " + + "NAME=? AND TYPE=? AND TENANT_ID=?) AND AR.VERSION=? AND AR.RELEASE_TYPE=? AND " + + "AL.AP_APP_RELEASE_ID=AR.ID AND AL.TENANT_ID=AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;"; try { connection = this.getDBConnection(); @@ -179,7 +173,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements + " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, " + "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS " + "HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, AR" + - ".PUBLISHED_BY, AR.PUBLISHED_AT, AR.STARS, AL.CURRENT_STATE, AL.PREVIOUSE_STATE, AL.UPDATED_BY, " + + ".PUBLISHED_BY, AR.PUBLISHED_AT, AR.STARS, AL.CURRENT_STATE, AL.PREVIOUS_STATE, AL.UPDATED_BY, " + "AL.UPDATED_AT FROM AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL WHERE " + "AR.AP_APP_ID = ? AND AR.UUID = ? AND AR.TENANT_ID = ? AND AL.AP_APP_RELEASE_ID=AR.ID AND " + "AL.TENANT_ID = AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;"; @@ -226,13 +220,13 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements PreparedStatement statement = null; ResultSet resultSet = null; List applicationReleases = new ArrayList<>(); - String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE," - + " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS " - + "SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, " - + "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, " - + "AR.PUBLISHED_BY, AR.PUBLISHED_AT, AR.STARS, AR.RATING FROM AP_APP_RELEASE AS " - + "AR where AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE NAME = ? AND TYPE = ? " - + "AND TENANT_ID = ?) AND AR.TENANT_ID = ? ;"; + String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE " + + "AS RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE, AR.STORED_LOCATION, " + + "AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, " + + "AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, " + + "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO AS APP_META_INFO, " + + "AR.RATING AS RATING FROM AP_APP_RELEASE AS AR where AR.AP_APP_ID=(SELECT ID FROM AP_APP " + + "WHERE NAME = ? AND TYPE = ? AND TENANT_ID = ?) AND AR.TENANT_ID = ?;"; try { connection = this.getDBConnection(); @@ -244,22 +238,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements resultSet = statement.executeQuery(); while (resultSet.next()) { - ApplicationRelease applicationRelease = new ApplicationRelease(); - applicationRelease.setId(resultSet.getInt("RELESE_ID")); - applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION")); - applicationRelease.setUuid(resultSet.getString("UUID")); - applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE")); - applicationRelease.setPrice(resultSet.getDouble("APP_PRICE")); - applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION")); - applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION")); - applicationRelease.setScreenshotLoc1(resultSet.getString("SCREEN_SHOT_1")); - applicationRelease.setScreenshotLoc2(resultSet.getString("SCREEN_SHOT_2")); - applicationRelease.setScreenshotLoc3(resultSet.getString("SCREEN_SHOT_3")); - applicationRelease.setAppHashValue(resultSet.getString("HASH_VALUE")); - applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED")); - applicationRelease.setMetaData(resultSet.getString("APP_META_INFO")); - applicationRelease.setApplicationCreator(resultSet.getString("CREATED_BY")); - applicationRelease.setRating(resultSet.getDouble("RATING")); + ApplicationRelease applicationRelease = constructApplicationRelease(resultSet); applicationReleases.add(applicationRelease); } @@ -287,7 +266,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements public void updateRatingValue(String uuid, double rating, int ratedUsers) throws ApplicationManagementDAOException { Connection connection; PreparedStatement statement = null; - String sql = "UPDATE AP_APP_RELEASE SET RATING = ? AND RATED_USERS = ? WHERE UUID = ?;"; + String sql = "UPDATE AP_APP_RELEASE SET RATING = ?,RATED_USERS = ? WHERE UUID = ?;"; try { connection = this.getDBConnection(); statement = connection.prepareStatement(sql); @@ -354,11 +333,10 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements throws ApplicationManagementDAOException { Connection connection; PreparedStatement statement = null; - String sql = "UPDATE AP_APP_RELEASE SET VERSION = ? AND UUID = ? AND RELEASE_TYPE = ? AND PACKAGE_NAME = ? " - + "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 = ?;"; + String sql = "UPDATE AP_APP_RELEASE SET VERSION = ?, UUID = ?, RELEASE_TYPE = ?, PACKAGE_NAME = ?," + + " APP_PRICE = ?, STORED_LOCATION = ?, BANNER_LOCATION = ?, SC_1_LOCATION = ?, SC_2_LOCATION = ?," + + " SC_3_LOCATION = ?, APP_HASH_VALUE = ?, SHARED_WITH_ALL_TENANTS = ?, APP_META_INFO = ? " + + "WHERE AP_APP_ID = ? AND TENANT_ID = ? AND ID = ?;"; try { connection = this.getDBConnection(); statement = connection.prepareStatement(sql); @@ -375,8 +353,10 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements statement.setString(11, applicationRelease.getAppHashValue()); statement.setInt(12, applicationRelease.getIsSharedWithAllTenants()); statement.setString(13, applicationRelease.getMetaData()); - statement.setString(14, applicationRelease.getApplicationCreator()); - statement.setTimestamp(15, new Timestamp(System.currentTimeMillis())); + statement.setInt(14,applicationId); + statement.setInt(15, tenantId); + statement.setInt(16, applicationRelease.getId()); + statement.executeUpdate(); } catch (DBConnectionException e) { throw new ApplicationManagementDAOException( @@ -441,7 +421,6 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements applicationRelease.setAppHashValue(resultSet.getString("HASH_VALUE")); applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED")); applicationRelease.setMetaData(resultSet.getString("APP_META_INFO")); - applicationRelease.setApplicationCreator(resultSet.getString("CREATED_BY")); applicationRelease.setRating(resultSet.getDouble("RATING")); return applicationRelease; 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/lifecyclestate/GenericLifecycleStateDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java index c9286d0ffc0..3103f2f8144 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java @@ -46,7 +46,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif ResultSet rs = null; try { conn = this.getDBConnection(); - String sql = "SELECT ID, CURRENT_STATE, PREVIOUSE_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM " + String sql = "SELECT ID, CURRENT_STATE, PREVIOUS_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM " + "AP_APP_LIFECYCLE_STATE WHERE AP_APP_RELEASE_ID=? ORDER BY UPDATED_AT DESC;"; stmt = conn.prepareStatement(sql); @@ -58,7 +58,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif lifecycleState = new LifecycleState(); lifecycleState.setId(rs.getInt("ID")); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); - lifecycleState.setPreviousState(rs.getString("PREVIOUSE_STATE")); + lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE")); lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY")); } @@ -82,7 +82,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif ResultSet rs = null; try { conn = this.getDBConnection(); - String sql = "SELECT ID, CURRENT_STATE, PREVIOUSE_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM " + String sql = "SELECT ID, CURRENT_STATE, PREVIOUS_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM " + "AP_APP_LIFECYCLE_STATE WHERE AP_APP_RELEASE_ID = ? ORDER BY UPDATED_AT ASC;"; stmt = conn.prepareStatement(sql); stmt.setInt(1,appReleaseId); @@ -91,7 +91,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif LifecycleState lifecycleState = new LifecycleState(); lifecycleState.setId(rs.getInt("ID")); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); - lifecycleState.setPreviousState(rs.getString("PREVIOUSE_STATE")); + lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE")); lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY")); lifecycleStates.add(lifecycleState); @@ -113,7 +113,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif PreparedStatement stmt = null; try { conn = this.getDBConnection(); - String sql = "INSERT INTO AP_APP_LIFECYCLE_STATE (CURRENT_STATE, PREVIOUSE_STATE, TENANT_ID, UPDATED_BY, " + String sql = "INSERT INTO AP_APP_LIFECYCLE_STATE (CURRENT_STATE, PREVIOUS_STATE, TENANT_ID, UPDATED_BY, " + "AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?, ?, ?,?,?);"; stmt = conn.prepareStatement(sql); stmt.setString(1, state.getCurrentState()); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java index b46c56eb1d7..7d116ea3914 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java @@ -70,7 +70,7 @@ public class ReviewManagerImpl implements ReviewManager { String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); boolean isSuccess = false; try { - ConnectionManagerUtil.beginDBTransaction(); + ConnectionManagerUtil.openDBConnection(); Review existingReview = reviewDAO.haveUerCommented(uuid, username, tenantId); if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId) && review.getRating() > 0 && review.getRating() != existingReview.getRating()) { @@ -81,12 +81,13 @@ public class ReviewManagerImpl implements ReviewManager { Runnable task = () -> calculateRating(review.getRating(), -12345, uuid); new Thread(task).start(); review.setUsername(username); + ConnectionManagerUtil.beginDBTransaction(); isSuccess = this.reviewDAO.addReview(review, uuid, tenantId); - } - if (isSuccess) { - ConnectionManagerUtil.commitDBTransaction(); - } else { - ConnectionManagerUtil.rollbackDBTransaction(); + if (isSuccess) { + ConnectionManagerUtil.commitDBTransaction(); + } else { + ConnectionManagerUtil.rollbackDBTransaction(); + } } return isSuccess; } catch (DBConnectionException e) { @@ -115,8 +116,8 @@ public class ReviewManagerImpl implements ReviewManager { log.debug("Review updating request is received for the review id " + reviewId); } try { - ConnectionManagerUtil.openDBConnection(); if (existingReview == null) { + ConnectionManagerUtil.openDBConnection(); existingReview = this.reviewDAO.getReview(reviewId); if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId)) { if (review.getRating() > 0 && review.getRating() != existingReview.getRating()) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java index 8aa9d305fc1..6c8852aba7e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java @@ -63,7 +63,7 @@ import java.util.List; } ), tags = { - @Tag(name = "store_management", description = "Review Management related APIs") + @Tag(name = "review_management", description = "Review Management related APIs") } ) @Scopes( diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index 710182c632b..54fe2f09605 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -51,9 +51,9 @@ CREATE TABLE IF NOT EXISTS AP_APP_REVIEW ( ID INT(11) NOT NULL AUTO_INCREMENT, TENANT_ID VARCHAR(45) NOT NULL, COMMENT VARCHAR(250) NOT NULL, - REPLY_COMMENT VARCHAR(250) NULL, - CREATED_AT TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - MODEFIED_AT TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PARENT_ID INT(11) NULL, + CREATED_AT TIMESTAMP NOT NULL, + MODEFIED_AT TIMESTAMP NOT NULL, RATING INT(11) NULL, USERNAME VARCHAR(45) NOT NULL, AP_APP_RELEASE_ID INT(11) NOT NULL, @@ -75,7 +75,7 @@ CREATE TABLE IF NOT EXISTS AP_APP_LIFECYCLE_STATE ( PREVIOUSE_STATE VARCHAR(45) NOT NULL, TENANT_ID VARCHAR(45) NOT NULL, UPDATED_BY VARCHAR(100) NOT NULL, - UPDATED_AT TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + UPDATED_AT TIMESTAMP NOT NULL, AP_APP_RELEASE_ID INT(11) NOT NULL, AP_APP_ID INT(11) NOT NULL, PRIMARY KEY (ID, AP_APP_RELEASE_ID, AP_APP_ID), @@ -109,7 +109,7 @@ CREATE TABLE IF NOT EXISTS AP_DEVICE_SUBSCRIPTION ( ID INT(11) NOT NULL AUTO_INCREMENT, TENANT_ID VARCHAR(45) NOT NULL, SUBSCRIBED_BY VARCHAR(100) NOT NULL, - SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL, UNSUBSCRIBED INT(11) NULL DEFAULT NULL, UNSUBSCRIBED_BY INT(11) NULL DEFAULT NULL, UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, @@ -131,7 +131,7 @@ CREATE TABLE IF NOT EXISTS AP_GROUP_SUBSCRIPTION ( ID INT(11) NOT NULL AUTO_INCREMENT, TENANT_ID VARCHAR(45) NOT NULL, SUBSCRIBED_BY VARCHAR(100) NOT NULL, - SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL, UNSUBSCRIBED INT(11) NULL DEFAULT NULL, UNSUBSCRIBED_BY INT(11) NULL DEFAULT NULL, UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, @@ -154,7 +154,7 @@ CREATE TABLE IF NOT EXISTS AP_ROLE_SUBSCRIPTION ( TENANT_ID VARCHAR(45) NOT NULL, ROLE_NAME VARCHAR(100) NOT NULL, SUBSCRIBED_BY VARCHAR(100) NOT NULL, - SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + SUBSCRIBED_TIMESTAMP TIMESTAMP NOT NULL, UNSUBSCRIBED INT(11) NULL DEFAULT NULL, UNSUBSCRIBED_BY INT(11) NULL DEFAULT NULL, UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, 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 641c9946600..058feaaa5f9 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 @@ -68,9 +68,9 @@ CREATE TABLE IF NOT EXISTS `AP_APP_REVIEW` ( `ID` INT(11) NOT NULL AUTO_INCREMENT, `TENANT_ID` VARCHAR(45) NOT NULL, `COMMENT` VARCHAR(250) NOT NULL, - `REPLY_COMMENT` VARCHAR(250) NULL, + `PARENT_ID` INT(11) NULL, `CREATED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `MODEFIED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `MODIFIED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `RATING` INT(11) NULL, `USERNAME` VARCHAR(45) NOT NULL, `AP_APP_RELEASE_ID` INT(11) NOT NULL, @@ -93,7 +93,7 @@ CREATE INDEX `fk_AP_APP_COMMENT_AP_APP_RELEASE1_idx` ON `AP_APP_REVIEW` (`AP_APP CREATE TABLE IF NOT EXISTS `AP_APP_LIFECYCLE_STATE` ( `ID` INT(11) NOT NULL AUTO_INCREMENT, `CURRENT_STATE` VARCHAR(45) NOT NULL, - `PREVIOUSE_STATE` VARCHAR(45) NOT NULL, + `PREVIOUS_STATE` VARCHAR(45) NOT NULL, `TENANT_ID` VARCHAR(45) NOT NULL, `UPDATED_BY` VARCHAR(100) NOT NULL, `UPDATED_AT` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,