Merge branch 'application-mgt-new' of https://gitlab.com/entgra/carbon-device-mgt into application-mgt-new

feature/appm-store/pbac
inoshperera 6 years ago
commit b856aa36fe

@ -0,0 +1,20 @@
image: maven:latest
variables:
MAVEN_CLI_OPTS: "--batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
cache:
paths:
- .m2/repository/
- target/
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS compile
test:
stage: test
script:
- mvn $MAVEN_CLI_OPTS test

@ -105,6 +105,10 @@ public class ApplicationRelease {
value = "Latest Lifecycle state of the application release") value = "Latest Lifecycle state of the application release")
private LifecycleState lifecycleState; private LifecycleState lifecycleState;
@ApiModelProperty(name = "packageName",
value = "Application bundle identifier")
private String packageName;
public int getRatedUsers() { public int getRatedUsers() {
return ratedUsers; return ratedUsers;
} }
@ -257,4 +261,12 @@ public class ApplicationRelease {
public void setLifecycleState(LifecycleState lifecycleState) { public void setLifecycleState(LifecycleState lifecycleState) {
this.lifecycleState = lifecycleState; this.lifecycleState = lifecycleState;
} }
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public String getPackageName() {
return packageName;
}
} }

@ -23,6 +23,6 @@ package org.wso2.carbon.device.application.mgt.common;
* Application Types. * Application Types.
*/ */
public enum ApplicationType { public enum ApplicationType {
ANDROID, IOS, WEB_CLIP ENTERPRISE, PUBLIC, WEB, WEB_CLIP
} }

@ -0,0 +1,5 @@
package org.wso2.carbon.device.application.mgt.common;
public enum DeviceType {
ANDROID, IOS
}

@ -33,12 +33,11 @@ public interface ReviewManager {
* To add a review to a application * To add a review to a application
* *
* @param review review of the application. * @param review review of the application.
* @param appId id of the application. * @param uuid uuid of the application release.
* @param appReleaseId id of the application release
* @return {@link Review} Review added * @return {@link Review} Review added
* @throws ReviewManagementException Exceptions of the review management. * @throws ReviewManagementException Exceptions of the review management.
*/ */
boolean addReview(Review review,int appId, int appReleaseId) throws ReviewManagementException; boolean addReview(Review review, String uuid) throws ReviewManagementException;
/** /**
* Get all comments to pagination * Get all comments to pagination
@ -62,20 +61,25 @@ public interface ReviewManager {
/** /**
* To delete review using review id. * To delete review using review id.
* *
* @param uuid UUID of the application release
* @param commentId id of the comment * @param commentId id of the comment
* @return If review is successfully deleted return true, otherwise returns false
* @throws ReviewManagementException Exceptions of the comment management * @throws ReviewManagementException Exceptions of the comment management
*/ */
void deleteReview(String loggedInUser, int commentId) throws ReviewManagementException; boolean deleteReview(String uuid, int commentId) throws ReviewManagementException;
/** /**
* To update a review. * To update a review.
* *
* @param review review of the application. * @param review review of the application.
* @param reviewId id of the review * @param reviewId id of the review
* @param uuid UUID of the application release
* @param checkExistence Pass true if it is required to check the existence of the review, otherwise pass false
* @return {@link Review}updated review * @return {@link Review}updated review
* @throws ReviewManagementException Exceptions of the review management * @throws ReviewManagementException Exceptions of the review management
*/ */
boolean updateReview(Review review, int reviewId, boolean checkExistence) throws ReviewManagementException; boolean updateReview(Review review, int reviewId, String uuid, boolean checkExistence)
throws ReviewManagementException;
/** /**
* To get the overall rating for a application release * To get the overall rating for a application release

@ -90,10 +90,10 @@ public interface ApplicationReleaseDAO {
/** /**
* To retrieve rating of an application release. * To retrieve rating of an application release.
* @param id Id of the application Release. * @param uuid UUID of the application Release.
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @throws ApplicationManagementDAOException Application Management DAO Exception.
*/ */
Rating getRating(int id) throws ApplicationManagementDAOException; Rating getRating(String uuid) throws ApplicationManagementDAOException;
/** /**

@ -28,24 +28,32 @@ import java.sql.SQLException;
import java.util.List; import java.util.List;
/** /**
* This interface specifies the database access operations performed for comments. * This interface specifies the database access operations performed for reviews.
*/ */
public interface ReviewDAO { public interface ReviewDAO {
/** /**
* To add a review to a application. * To add a review to an application release.
* *
* @param tenantId tenantId of the commented application. * @param tenantId tenantId.
* @param review review of the application. * @param review review of the application.
* @param uuid UUID of the application release
* @return If review is added successfully, it return true otherwise false * @return If review is added successfully, it return true otherwise false
* @throws ReviewManagementDAOException Exceptions of the review management DAO. * @throws ReviewManagementDAOException Exceptions of the review management DAO.
*/ */
boolean addReview(Review review, int appId, int appReleaseId, int tenantId) throws ReviewManagementDAOException; boolean addReview(Review review, String uuid, int tenantId) throws ReviewManagementDAOException;
Review isExistReview(int appId, int appReleaseId, String username, int tenantId) /**
throws DBConnectionException, SQLException; * To verify whether review is exists or not.
*
* @param uuid UUID of the application release.
* @param username username of the logged in user.
* @param tenantId tenantId of the commented application.
* @return If review exists, review returns
* @throws ReviewManagementDAOException Exceptions of the review management DAO.
*/
Review haveUerCommented(String uuid, String username, int tenantId) throws ReviewManagementDAOException;
/** /**
* To update already added comment. * To update already added comment.
@ -68,7 +76,7 @@ import java.util.List;
* @throws DBConnectionException db connection exception * @throws DBConnectionException db connection exception
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
Review getComment(int commentId) throws ReviewManagementException, SQLException, DBConnectionException; Review getReview(int commentId) throws ReviewManagementException, SQLException, DBConnectionException;
/** /**
* To get all the comments * To get all the comments
@ -101,18 +109,27 @@ import java.util.List;
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
int getCommentCountByApp(String appType, String appName, String version) int getReviewCountByApp(String appType, String appName, String version)
throws ReviewManagementException, DBConnectionException, SQLException; throws ReviewManagementException, DBConnectionException, SQLException;
/** /**
* To delete comment using comment id. * To delete review using review id and uuid of the application release.
* *
* @param commentId id of the comment * @param username username of the review owner
* @throws ReviewManagementException Exceptions of the comment management. * @param reviewId id of the review
* @throws DBConnectionException db connection exception. * @return If review is successfully deleted return 1, otherwise returns 0.
* @throws SQLException sql exception * @throws ReviewManagementDAOException Review management DAO exception.
*/
int deleteReview(String username, int reviewId) throws ReviewManagementDAOException;
/**
* To delete review using review id, in this case, it doesn't check whether user is review owner or not.
*
* @param reviewId id of the review
* @return If review is successfully deleted return 1, otherwise returns 0.
* @throws ReviewManagementDAOException Review management DAO exception.
*/ */
void deleteComment(int commentId) throws ReviewManagementException, DBConnectionException, SQLException; int deleteReviewByAdmin(int reviewId) throws ReviewManagementDAOException;
/** /**
* To delete comments using application details. * To delete comments using application details.
@ -122,15 +139,15 @@ import java.util.List;
* @param version version of the commented application. * @param version version of the commented application.
* @throws ReviewManagementException Exceptions of the comment management. * @throws ReviewManagementException Exceptions of the comment management.
*/ */
void deleteComments(String appType, String appName, String version) throws ReviewManagementException; void deleteReviews(String appType, String appName, String version) throws ReviewManagementException;
/** /**
* To get comment count for pagination * To get comment count for pagination
* *
* @param request * @param request pagination request
* @param uuid * @param uuid uuid of the application release
* @return Review count * @return Review count
* @throws ReviewManagementException * @throws ReviewManagementException
*/ */
int getCommentCount(PaginationRequest request, String uuid) throws ReviewManagementException; int getReviewCount(PaginationRequest request, String uuid) throws ReviewManagementException;
} }

@ -48,12 +48,10 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
private String sql; private String sql;
@Override @Override
public boolean addReview(Review review, int appId, int appReleaseId, int tenantId) public boolean addReview(Review review, String uuid, int tenantId)
throws ReviewManagementDAOException { throws ReviewManagementDAOException {
//todo
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to add review for application release. Application id: " + appId log.debug("Request received in DAO Layer to add review for application release. Application UUID: " + uuid);
+ "Application Release id: " + appReleaseId);
} }
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet rs = null; ResultSet rs = null;
@ -67,8 +65,8 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
statement.setString(2, review.getComment()); statement.setString(2, review.getComment());
statement.setInt(3, review.getParentId()); statement.setInt(3, review.getParentId());
statement.setString(4, review.getUsername()); statement.setString(4, review.getUsername());
statement.setString(5,""); statement.setString(5,uuid);
statement.setString(6,""); statement.setString(6,uuid);
statement.executeUpdate(); statement.executeUpdate();
rs = statement.getGeneratedKeys(); rs = statement.getGeneratedKeys();
return rs.next(); return rs.next();
@ -85,26 +83,25 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
} }
@Override @Override
public Review isExistReview(int appId, int appReleaseId, String username, int tenantId) public Review haveUerCommented(String uuid, String username, int tenantId) throws ReviewManagementDAOException {
throws DBConnectionException, SQLException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug( log.debug(
"Request received in DAO Layer to check whether review exist or not rein the IoTS APPM. Application id: " "Request received in DAO Layer to check whether user have already commented or not for the "
+ appId + " Application release id: " + appReleaseId + " comment owner: " + username); + "application release. Application UUID: " + uuid + " comment owner: " + username +
" tenant-id " + tenantId);
} }
Connection conn; Connection conn;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet rs = null; ResultSet rs = null;
Review review = null; Review review = null;
sql = "SELECT ID, COMMENT, CREATED_AT, MODEFIED_AT, USERNAME, PARENT_ID, RATING FROM AP_APP_REVIEW WHERE " sql = "SELECT ID, COMMENT, CREATED_AT, MODEFIED_AT, USERNAME, PARENT_ID, RATING FROM AP_APP_REVIEW WHERE "
+ "AP_APP_ID = ? AND AP_APP_RELEASE_ID = ? AND USERNAME = ? AND TENANT_ID = ?;"; + "AP_APP_RELEASE_ID = (SELECT ID FROM AP_APP_RELEASE WHERE UUID=?) AND USERNAME = ? AND TENANT_ID = ?;";
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
statement = conn.prepareStatement(sql); statement = conn.prepareStatement(sql);
statement.setInt(1, appId); statement.setString(1, uuid);
statement.setInt(2, appReleaseId); statement.setString(2, username);
statement.setString(3, username); statement.setInt(3, tenantId);
statement.setInt(4, tenantId);
rs = statement.executeQuery(); rs = statement.executeQuery();
if (rs.next()){ if (rs.next()){
@ -118,6 +115,13 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
review.setRating(rs.getInt("RATING")); review.setRating(rs.getInt("RATING"));
} }
return review; return review;
} catch (SQLException e) {
throw new ReviewManagementDAOException("Error occured while accessing the Database when checking whether "
+ "user has already commented for the application ro not", e);
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException("Error occured while getting the database connection when checking "
+ "whether user has already commented for the application ro not", e);
} finally { } finally {
Util.cleanupResources(statement, rs); Util.cleanupResources(statement, rs);
} }
@ -149,7 +153,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
} }
@Override @Override
public Review getComment(int commentId) throws ReviewManagementException { public Review getReview(int commentId) throws ReviewManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting review with the review id(" + commentId + ") from the database"); log.debug("Getting review with the review id(" + commentId + ") from the database");
@ -259,7 +263,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
} }
@Override @Override
public int getCommentCount(PaginationRequest request, String uuid) throws ReviewManagementException { public int getReviewCount(PaginationRequest request, String uuid) throws ReviewManagementException {
int commentCount = 0; int commentCount = 0;
Connection conn; Connection conn;
@ -293,7 +297,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
} }
@Override @Override
public int getCommentCountByApp(String appType, String appName, String version) public int getReviewCountByApp(String appType, String appName, String version)
throws ReviewManagementException, DBConnectionException, SQLException { throws ReviewManagementException, DBConnectionException, SQLException {
Connection conn; Connection conn;
@ -320,24 +324,48 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
} }
@Override @Override
public void deleteComment(int commentId) public int deleteReview(String username, int reviewId) throws ReviewManagementDAOException {
throws ReviewManagementException, DBConnectionException, SQLException { Connection conn;
PreparedStatement statement = null;
try {
conn = this.getDBConnection();
sql = "DELETE FROM AP_APP_REVIEW WHERE ID=? AND USERNAME = ?);";
statement = conn.prepareStatement(sql);
statement.setInt(1, reviewId);
statement.setString(2, username);
return statement.executeUpdate();
} catch (SQLException e) {
throw new ReviewManagementDAOException("Error occured while accessing the Database", e);
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException("Error occured while getting the database connection", e);
} finally {
Util.cleanupResources(statement, null);
}
}
@Override
public int deleteReviewByAdmin(int reviewId) throws ReviewManagementDAOException {
Connection conn; Connection conn;
PreparedStatement statement = null; PreparedStatement statement = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql = "DELETE FROM AP_APP_COMMENT WHERE ID=?;"; sql = "DELETE FROM AP_APP_REVIEW WHERE ID=?;";
statement = conn.prepareStatement(sql); statement = conn.prepareStatement(sql);
statement.setInt(1, commentId); statement.setInt(1, reviewId);
statement.executeUpdate(); return statement.executeUpdate();
} catch (SQLException e) {
throw new ReviewManagementDAOException("Error occured while accessing the Database", e);
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException("Error occured while getting the database connection", e);
} finally { } finally {
Util.cleanupResources(statement, null); Util.cleanupResources(statement, null);
} }
} }
@Override @Override
public void deleteComments(String appType, String appName, String version) public void deleteReviews(String appType, String appName, String version)
throws ReviewManagementException { throws ReviewManagementException {
Connection conn; Connection conn;

@ -136,9 +136,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
Pagination pagination = new Pagination(); 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" 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.SUB_TYPE AS SUB_TYPE, AP_APP.CURRENCY AS CURRENCY, " + " AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE, AP_APP.CURRENCY AS CURRENCY, "
+ "AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLES.ROLE " + "AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLE.ROLE "
+ "AS ROLE FROM ((AP_APP LEFT JOIN AP_APP_TAG ON AP_APP.ID = AP_APP_TAG.AP_APP_ID) " + "AS ROLE 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) " + "LEFT JOIN AP_UNRESTRICTED_ROLE ON AP_APP.ID = AP_UNRESTRICTED_ROLE.AP_APP_ID) "
+ "WHERE AP_APP.TENANT_ID = ? AND AP_APP.STATUS != ?"; + "WHERE AP_APP.TENANT_ID = ? AND AP_APP.STATUS != ?";
@ -299,8 +299,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
String sql = 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 " "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.SUB_TYPE AS SUB_TYPE ,AP_APP.CURRENCY AS CURRENCY," + "AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE ,AP_APP.CURRENCY AS CURRENCY,"
+ " AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLES.ROLE " + " AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLE.ROLE "
+ "AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.NAME=? AND " + "AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLE WHERE AP_APP.NAME=? AND "
+ "AP_APP.TYPE= ? AND AP_APP.TENANT_ID=?;"; + "AP_APP.TYPE= ? AND AP_APP.TENANT_ID=?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
@ -343,8 +343,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
String sql = 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 " "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.SUB_TYPE AS SUB_TYPE ,AP_APP.CURRENCY AS CURRENCY, " + "AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE ,AP_APP.CURRENCY AS CURRENCY, "
+ "AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLES.ROLE " + "AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLE.ROLE "
+ "AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.ID=? AND " + "AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLE WHERE AP_APP.ID=? AND "
+ "AP_APP.TENANT_ID=?;"; + "AP_APP.TENANT_ID=?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
@ -385,7 +385,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
String sql = 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 " "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.SUB_TYPE AS SUB_TYPE, AP_APP_TAG.TAG AS TAG, " + "AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE, AP_APP_TAG.TAG AS TAG, "
+ "AP_UNRESTRICTED_ROLES.ROLE AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES " + "AP_UNRESTRICTED_ROLE.ROLE AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLE "
+ "WHERE AP_APP.ID = ?;"; + "WHERE AP_APP.ID = ?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
@ -571,7 +571,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "AP_APP_RELEASE.STARS," + "AP_APP_RELEASE.STARS,"
+ "AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, " + "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.SUB_TYPE AS SUB_TYPE, AP_APP.CURRENCY AS CURRENCY, " + "AP_APP.APP_CATEGORY AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE, AP_APP.CURRENCY AS CURRENCY, "
+ "AP_UNRESTRICTED_ROLES.ROLE AS ROLE FROM AP_APP, AP_UNRESTRICTED_ROLES, AP_APP_RELEASE " + "AP_UNRESTRICTED_ROLE.ROLE AS ROLE FROM AP_APP, AP_UNRESTRICTED_ROLE, AP_APP_RELEASE "
+ "WHERE AP_APP_RELEASE.UUID=? AND AP_APP.TENANT_ID=?;"; + "WHERE AP_APP_RELEASE.UUID=? AND AP_APP.TENANT_ID=?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);

@ -63,10 +63,10 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
String sql = "INSERT INTO AP_APP_RELEASE (VERSION,TENANT_ID,UUID,RELEASE_TYPE,APP_PRICE,STORED_LOCATION, " String sql = "INSERT INTO AP_APP_RELEASE (VERSION,TENANT_ID,UUID,RELEASE_TYPE, PACKAGE_NAME, APP_PRICE,"
+ "BANNER_LOCATION, SC_1_LOCATION,SC_2_LOCATION,SC_3_LOCATION, APP_HASH_VALUE,SHARED_WITH_ALL_TENANTS, " + "STORED_LOCATION, BANNER_LOCATION, SC_1_LOCATION,SC_2_LOCATION,SC_3_LOCATION, APP_HASH_VALUE,"
+ "APP_META_INFO,CREATED_BY,AP_APP_ID) VALUES " + "SHARED_WITH_ALL_TENANTS, APP_META_INFO,CREATED_BY,AP_APP_ID) "
+ "(?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
int index = 0; int index = 0;
String generatedColumns[] = {"ID"}; String generatedColumns[] = {"ID"};
@ -77,6 +77,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
statement.setInt(++index, tenantId); statement.setInt(++index, tenantId);
statement.setString(++index, applicationRelease.getUuid()); statement.setString(++index, applicationRelease.getUuid());
statement.setString(++index, String.valueOf(applicationRelease.getReleaseType())); statement.setString(++index, String.valueOf(applicationRelease.getReleaseType()));
statement.setString(++index, String.valueOf(applicationRelease.getPackageName()));
statement.setDouble(++index, applicationRelease.getPrice()); statement.setDouble(++index, applicationRelease.getPrice());
statement.setString(++index, applicationRelease.getAppStoredLoc()); statement.setString(++index, applicationRelease.getAppStoredLoc());
statement.setString(++index, applicationRelease.getScreenshotLoc1()); statement.setString(++index, applicationRelease.getScreenshotLoc1());
@ -121,14 +122,15 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE," String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, "
+ " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, " + "AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE, AR.STORED_LOCATION, AR.BANNER_LOCATION, "
+ "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, " + "AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS "
+ "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, AR.PUBLISHED_BY, " + "SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, "
+ "AR.PUBLISHED_AT, AR.STARS, AL.CURRENT_STATE, AL.PREVIOUSE_STATE, AL.UPDATED_BY, AL.UPDATED_AT FROM " + "AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, AR.PUBLISHED_BY, AR.PUBLISHED_AT, AR.STARS, "
+ "AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL " + "AL.CURRENT_STATE, AL.PREVIOUSE_STATE, AL.UPDATED_BY, AL.UPDATED_AT FROM "
+ "WHERE AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE NAME=? AND TYPE=? AND TENANT_ID=?)" + "AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL WHERE "
+ " AND AR.VERSION=? AND AR.RELEASE_TYPE=? AND AL.AP_APP_RELEASE_ID=AR.ID " + "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;"; + "AND AL.TENANT_ID=AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;";
try { try {
@ -306,20 +308,20 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
/** /**
* To retrieve rating of an application release. * To retrieve rating of an application release.
* *
* @param id Id of the application Release. * @param uuid UUID of the application Release.
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @throws ApplicationManagementDAOException Application Management DAO Exception.
*/ */
@Override @Override
public Rating getRating(int id) throws ApplicationManagementDAOException { public Rating getRating(String uuid) throws ApplicationManagementDAOException {
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
Rating rating = null; Rating rating = null;
String sql = "SELECT RATING, RATED_USERS FROM AP_APP_RELEASE WHERE ID = ?;"; String sql = "SELECT RATING, RATED_USERS FROM AP_APP_RELEASE WHERE UUID = ?;";
try { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
statement.setInt(1, id); statement.setString(1, uuid);
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
if (resultSet.next()){ if (resultSet.next()){
@ -350,27 +352,29 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
String sql = "UPDATE AP_APP_RELEASE SET VERSION = ? AND UUID = ? AND RELEASE_TYPE = ? AND APP_PRICE = ? AND " + String sql = "UPDATE AP_APP_RELEASE SET VERSION = ? AND UUID = ? AND RELEASE_TYPE = ? AND PACKAGE_NAME = ? "
"STORED_LOCATION = ? AND BANNER_LOCATION = ? AND SC_1_LOCATION = ? AND SC_2_LOCATION = ? AND " + + "AND APP_PRICE = ? AND STORED_LOCATION = ? AND BANNER_LOCATION = ? AND SC_1_LOCATION = ? "
"SC_3_LOCATION = ? AND APP_HASH_VALUE = ? AND SHARED_WITH_ALL_TENANTS = ? AND APP_META_INFO = ? AND " + + "AND SC_2_LOCATION = ? AND SC_3_LOCATION = ? AND APP_HASH_VALUE = ? AND SHARED_WITH_ALL_TENANTS = ? "
"CREATED_BY = ? AND CREATED_AT = ? WHERE AP_APP_ID = ? AND TENANT_ID = ? AND ID = ?;"; + "AND APP_META_INFO = ? AND CREATED_BY = ? AND CREATED_AT = ? WHERE AP_APP_ID = ? AND TENANT_ID = ? "
+ "AND ID = ?;";
try { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
statement.setString(1, applicationRelease.getVersion()); statement.setString(1, applicationRelease.getVersion());
statement.setString(2, applicationRelease.getUuid()); statement.setString(2, applicationRelease.getUuid());
statement.setString(3, applicationRelease.getReleaseType()); statement.setString(3, applicationRelease.getReleaseType());
statement.setDouble(4, applicationRelease.getPrice()); statement.setString(4, applicationRelease.getPackageName());
statement.setString(5, applicationRelease.getAppStoredLoc()); statement.setDouble(5, applicationRelease.getPrice());
statement.setString(6, applicationRelease.getBannerLoc()); statement.setString(6, applicationRelease.getAppStoredLoc());
statement.setString(7, applicationRelease.getScreenshotLoc1()); statement.setString(7, applicationRelease.getBannerLoc());
statement.setString(8, applicationRelease.getScreenshotLoc2()); statement.setString(8, applicationRelease.getScreenshotLoc1());
statement.setString(9, applicationRelease.getScreenshotLoc3()); statement.setString(9, applicationRelease.getScreenshotLoc2());
statement.setString(10, applicationRelease.getAppHashValue()); statement.setString(10, applicationRelease.getScreenshotLoc3());
statement.setInt(11, applicationRelease.getIsSharedWithAllTenants()); statement.setString(11, applicationRelease.getAppHashValue());
statement.setString(12, applicationRelease.getMetaData()); statement.setInt(12, applicationRelease.getIsSharedWithAllTenants());
statement.setString(13, applicationRelease.getApplicationCreator()); statement.setString(13, applicationRelease.getMetaData());
statement.setTimestamp(14, new Timestamp(System.currentTimeMillis())); statement.setString(14, applicationRelease.getApplicationCreator());
statement.setTimestamp(15, new Timestamp(System.currentTimeMillis()));
statement.executeUpdate(); statement.executeUpdate();
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
@ -425,6 +429,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION")); applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION"));
applicationRelease.setUuid(resultSet.getString("UUID")); applicationRelease.setUuid(resultSet.getString("UUID"));
applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE")); applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE"));
applicationRelease.setPackageName(resultSet.getString("PACKAGE_NAME"));
applicationRelease.setPrice(resultSet.getDouble("APP_PRICE")); applicationRelease.setPrice(resultSet.getDouble("APP_PRICE"));
applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION")); applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION"));
applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION")); applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION"));

@ -49,7 +49,7 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
String sql = "INSERT INTO AP_UNRESTRICTED_ROLES (ROLE, TENANT_ID, AP_APP_ID) VALUES (?, ?, ?)"; String sql = "INSERT INTO AP_UNRESTRICTED_ROLE (ROLE, TENANT_ID, AP_APP_ID) VALUES (?, ?, ?)";
try{ try{
conn = this.getDBConnection(); conn = this.getDBConnection();
conn.setAutoCommit(false); conn.setAutoCommit(false);
@ -81,7 +81,7 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
ResultSet rs = null; ResultSet rs = null;
List<UnrestrictedRole> unrestrictedRoles = new ArrayList<>(); List<UnrestrictedRole> unrestrictedRoles = new ArrayList<>();
UnrestrictedRole unrestrictedRole; UnrestrictedRole unrestrictedRole;
String sql = "SELECT ID, ROLE FROM AP_UNRESTRICTED_ROLES WHERE AP_APP_ID = ? AND TENANT_ID = ?;"; String sql = "SELECT ID, ROLE FROM AP_UNRESTRICTED_ROLE WHERE AP_APP_ID = ? AND TENANT_ID = ?;";
try{ try{
conn = this.getDBConnection(); conn = this.getDBConnection();
conn.setAutoCommit(false); conn.setAutoCommit(false);
@ -115,7 +115,7 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
String sql = "DELETE FROM AP_UNRESTRICTED_ROLES WHERE AP_APP_ID = ? AND ROLE = ? AND TENANT_ID = ?;"; String sql = "DELETE FROM AP_UNRESTRICTED_ROLE WHERE AP_APP_ID = ? AND ROLE = ? AND TENANT_ID = ?;";
try{ try{
conn = this.getDBConnection(); conn = this.getDBConnection();
conn.setAutoCommit(false); conn.setAutoCommit(false);

@ -225,7 +225,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException( throw new ApplicationManagementException(
"Error occured while adding application release into IoTS app management Application id of the " "Error occurred while adding application release into IoTS app management Application id of the "
+ "application release: " + applicationId, e); + "application release: " + applicationId, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();

@ -32,6 +32,7 @@ import org.apache.commons.validator.routines.UrlValidator;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.ApplicationType; import org.wso2.carbon.device.application.mgt.common.ApplicationType;
import org.wso2.carbon.device.application.mgt.common.DeviceType;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException; import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
@ -200,12 +201,16 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
"application UUID " + applicationRelease.getUuid()); "application UUID " + applicationRelease.getUuid());
} }
if (ApplicationType.ANDROID.toString().equals(deviceType)) { if (DeviceType.ANDROID.toString().equals(deviceType)) {
ApkMeta apkMeta = ArtifactsParser.readAndroidManifestFile(binaryFile); ApkMeta apkMeta = ArtifactsParser.readAndroidManifestFile(binaryFile);
applicationRelease.setVersion(apkMeta.getVersionName()); applicationRelease.setVersion(apkMeta.getVersionName());
} else if (ApplicationType.IOS.toString().equals(deviceType)) { applicationRelease.setPackageName(apkMeta.getPackageName());
} else if (DeviceType.IOS.toString().equals(deviceType)) {
NSDictionary plistInfo = ArtifactsParser.readiOSManifestFile(binaryFile); NSDictionary plistInfo = ArtifactsParser.readiOSManifestFile(binaryFile);
applicationRelease.setVersion(plistInfo.objectForKey(ArtifactsParser.IPA_BUNDLE_VERSION_KEY).toString()); applicationRelease
.setVersion(plistInfo.objectForKey(ArtifactsParser.IPA_BUNDLE_VERSION_KEY).toString());
applicationRelease
.setPackageName(plistInfo.objectForKey(ArtifactsParser.IPA_BUNDLE_IDENTIFIER_KEY).toString());
} else { } else {
throw new ApplicationStorageManagementException("Application Type doesn't match with supporting " + throw new ApplicationStorageManagementException("Application Type doesn't match with supporting " +
"application types " + applicationRelease.getUuid()); "application types " + applicationRelease.getUuid());

@ -47,7 +47,7 @@ import java.util.List;
import java.util.TreeMap; import java.util.TreeMap;
/** /**
* This class is the default implementation for the Managing the comments. * This class is the default implementation for the Managing the reviews.
*/ */
public class ReviewManagerImpl implements ReviewManager { public class ReviewManagerImpl implements ReviewManager {
@ -64,17 +64,17 @@ public class ReviewManagerImpl implements ReviewManager {
this.applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO(); this.applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO();
} }
@Override public boolean addReview(Review review, int appId, int appReleaseId) throws ReviewManagementException { @Override public boolean addReview(Review review, String uuid) throws ReviewManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
boolean isSuccess; boolean isSuccess;
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
Review existingReview = reviewDAO.isExistReview(appId, appReleaseId, username, tenantId); Review existingReview = reviewDAO.haveUerCommented(uuid, username, tenantId);
if (existingReview != null && review.getRating() > 0 && review.getRating() != existingReview.getRating()) { if (existingReview != null && review.getRating() > 0 && review.getRating() != existingReview.getRating()) {
Runnable task = () -> calculateRating(review.getRating(), existingReview.getRating()); Runnable task = () -> calculateRating(review.getRating(), existingReview.getRating(), uuid);
new Thread(task).start(); new Thread(task).start();
isSuccess = updateReview(review, existingReview.getId(), false); isSuccess = updateReview(review, existingReview.getId(),uuid, false);
if (isSuccess) { if (isSuccess) {
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} else { } else {
@ -82,11 +82,11 @@ public class ReviewManagerImpl implements ReviewManager {
} }
} else { } else {
if (review.getRating() > 0) { if (review.getRating() > 0) {
Runnable task = () -> calculateRating(review.getRating(), -12345); Runnable task = () -> calculateRating(review.getRating(), -12345, uuid);
new Thread(task).start(); new Thread(task).start();
} }
review.setUsername(username); review.setUsername(username);
isSuccess = this.reviewDAO.addReview(review, appId, appReleaseId, tenantId); isSuccess = this.reviewDAO.addReview(review, uuid, tenantId);
if (isSuccess) { if (isSuccess) {
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} else { } else {
@ -97,24 +97,19 @@ public class ReviewManagerImpl implements ReviewManager {
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new ReviewManagementException( throw new ReviewManagementException(
"DB Connection error occurs ,Review for application with app id: " + appId + " and app release id: " "DB Connection error occurs ,Review for application release with UUID: " + uuid + " is failed", e);
+ appReleaseId + " is failed", e);
} catch (SQLException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw new ReviewManagementException(
"SQL Exception occurs,Review for application with app id:" + appId + " and app release id:"
+ appReleaseId + " is failed", e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new ReviewManagementException( throw new ReviewManagementException(
"Transaction Management Exception occurs,Review for application with app id:" + appId "Transaction Management Exception occurs,Review for application release with UUID:" + uuid +
+ " and app release id:" + appReleaseId + " is failed ", e); " is failed ", e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
} }
@Override public boolean updateReview(Review review, int reviewId, boolean checkExistence) @Override
public boolean updateReview(Review review, int reviewId, String uuid, boolean checkExistence)
throws ReviewManagementException { throws ReviewManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
@ -131,10 +126,10 @@ public class ReviewManagerImpl implements ReviewManager {
"User " + review.getUsername() + "doesn't match with the logged in user: " + username); "User " + review.getUsername() + "doesn't match with the logged in user: " + username);
} }
if (checkExistence) { if (checkExistence) {
existingReview = this.reviewDAO.getComment(reviewId); existingReview = this.reviewDAO.getReview(reviewId);
if (existingReview != null) { if (existingReview != null) {
if (review.getRating() > 0 && review.getRating() != existingReview.getRating()) { if (review.getRating() > 0 && review.getRating() != existingReview.getRating()) {
Runnable task = () -> calculateRating(review.getRating(), existingReview.getRating()); Runnable task = () -> calculateRating(review.getRating(), existingReview.getRating(), uuid);
new Thread(task).start(); new Thread(task).start();
} }
} else { } else {
@ -216,7 +211,7 @@ public class ReviewManagerImpl implements ReviewManager {
} }
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
review = this.reviewDAO.getComment(commentId); review = this.reviewDAO.getReview(commentId);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ReviewManagementException( throw new ReviewManagementException(
"DB Connection error occurs ,Review with review id " + commentId + "cannot get.", e); "DB Connection error occurs ,Review with review id " + commentId + "cannot get.", e);
@ -229,36 +224,44 @@ public class ReviewManagerImpl implements ReviewManager {
return review; return review;
} }
@Override public void deleteReview(String loggedInUser, int commentId) throws ReviewManagementException { @Override
public boolean deleteReview(String uuid, int reviewId) throws ReviewManagementException {
Review existingReview; Review existingReview;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
int isReviewDeleted;
try { try {
if (!loggedInUser.equals(username) && !isAdminUser(username, tenantId, existingReview = getReview(reviewId);
CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
throw new ReviewManagementException(
"You don't have permission to delete the review. Please contact the administrator. Review Id: "
+ commentId);
}
existingReview = getReview(commentId);
if (existingReview == null) { if (existingReview == null) {
throw new ReviewManagementException( throw new ReviewManagementException(
"Cannot delete a non-existing review for the application with review id" + commentId); "Cannot delete a non-existing review for the application with review id" + reviewId);
} }
Runnable task = () -> calculateRating(0, existingReview.getRating()); Runnable task = () -> calculateRating(0, existingReview.getRating(), uuid);
new Thread(task).start(); new Thread(task).start();
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
this.reviewDAO.deleteComment(commentId); if (isAdminUser(username, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
isReviewDeleted = this.reviewDAO.deleteReviewByAdmin(reviewId);
if (isReviewDeleted == 1) {
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return true;
}
} else {
isReviewDeleted = this.reviewDAO.deleteReview(username, reviewId);
if (isReviewDeleted == 1) {
ConnectionManagerUtil.commitDBTransaction();
return true;
}
}
return false;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ReviewManagementException( throw new ReviewManagementException(
"DB Connection error occurs deleting review with review id " + commentId + ".", e); "DB Connection error occurs deleting review with review id " + reviewId + ".", e);
} catch (SQLException e) { } catch (ReviewManagementDAOException e) {
throw new ReviewManagementException("SQL error occurs deleting review with review id " + commentId + ".", throw new ReviewManagementException("Error occured while deleting review with review id " + reviewId + ".",
e); e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
throw new ReviewManagementException( throw new ReviewManagementException(
"Transaction Management Exception occurs deleting review with review id " + commentId + ".", e); "Transaction Management Exception occurs deleting review with review id " + reviewId + ".", e);
} catch (UserStoreException e) { } catch (UserStoreException e) {
throw new ReviewManagementException( throw new ReviewManagementException(
"User-store exception while checking whether the user " + username + " of tenant " + tenantId "User-store exception while checking whether the user " + username + " of tenant " + tenantId
@ -273,7 +276,7 @@ public class ReviewManagerImpl implements ReviewManager {
int appReleaseId = 0; int appReleaseId = 0;
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
Rating rating = this.applicationReleaseDAO.getRating(appReleaseId); Rating rating = this.applicationReleaseDAO.getRating(appReleaseUuuid);
if (rating == null) { if (rating == null) {
throw new ReviewManagementException("Couldn't find rating for application release id: " + appReleaseId throw new ReviewManagementException("Couldn't find rating for application release id: " + appReleaseId
+ ". Please check the existence of the application relese"); + ". Please check the existence of the application relese");
@ -309,12 +312,12 @@ public class ReviewManagerImpl implements ReviewManager {
} }
} }
private void calculateRating(int newRatingVal, int oldRatingVal) { private void calculateRating(int newRatingVal, int oldRatingVal, String uuid) {
// todo need to pass app release id // todo need to pass app release id
int appReleaseId = 0; int appReleaseId = 0;
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
Rating rating = this.applicationReleaseDAO.getRating(appReleaseId); Rating rating = this.applicationReleaseDAO.getRating(uuid);
if (rating == null) { if (rating == null) {
log.error("Couldn't find rating for application release id: " + appReleaseId); log.error("Couldn't find rating for application release id: " + appReleaseId);
} else { } else {

@ -124,7 +124,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
if (!isValidAppCreatingRequest(binaryFile, iconFile, bannerFile, attachmentList, application)) { if (!isValidAppCreatingRequest(binaryFile, iconFile, bannerFile, attachmentList, application)) {
return Response.status(Response.Status.BAD_REQUEST).build(); return Response.status(Response.Status.BAD_REQUEST).build();
} }
if (ApplicationType.WEB_CLIP.toString().equals(application.getType())) { if (!ApplicationType.ENTERPRISE.toString().equals(application.getType())) {
applicationRelease = application.getApplicationReleases().get(0); applicationRelease = application.getApplicationReleases().get(0);
applicationRelease = applicationStorageManager applicationRelease = applicationStorageManager
.uploadReleaseArtifact(applicationRelease, application.getType(), application.getDeviceType(), .uploadReleaseArtifact(applicationRelease, application.getType(), application.getDeviceType(),
@ -173,7 +173,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
return APIUtil.getResponse(new ApplicationManagementException(errorMessage, e), return APIUtil.getResponse(new ApplicationManagementException(errorMessage, e),
Response.Status.INTERNAL_SERVER_ERROR); Response.Status.INTERNAL_SERVER_ERROR);
} catch (RequestValidatingException e) { } catch (RequestValidatingException e) {
log.error("Error occured while handling the application creating request"); log.error("Error occurred while handling the application creating request");
return APIUtil.getResponse(e, Response.Status.BAD_REQUEST); return APIUtil.getResponse(e, Response.Status.BAD_REQUEST);
} }
} }
@ -486,7 +486,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
return false; return false;
} }
if (binaryFile == null && !ApplicationType.WEB_CLIP.toString().equals(application.getType())) { if (binaryFile == null && ApplicationType.ENTERPRISE.toString().equals(application.getType())) {
log.error("Binary file is not found for the application release. Application name: " log.error("Binary file is not found for the application release. Application name: "
+ application.getName() + " Application type: " + application.getType()); + application.getName() + " Application type: " + application.getType());
return false; return false;

@ -255,7 +255,7 @@ public interface ReviewManagementAPI {
@PathParam("reviewId") int reviewId); @PathParam("reviewId") int reviewId);
@DELETE @DELETE
@Path("/{commentId}") @Path("/{uuid}/{reviewId}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
@ -287,18 +287,17 @@ public interface ReviewManagementAPI {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response deleteComment( Response deleteReview(
@ApiParam( @ApiParam(
name="commentId", name="uuid",
value="Id of the comment.", value="UUID of the application release.",
required = true) required = true)
@PathParam("commentId") @PathParam("uuid") String uuid,
int commentId,
@ApiParam( @ApiParam(
name="username", name="reviewId",
value="logged in username", value="Id of the review.",
required = true) required = true)
@QueryParam("username") String username); @PathParam("reviewId") int reviewId);
@GET @GET
@Path("/{uuid}/{stars}") @Path("/{uuid}/{stars}")

@ -90,8 +90,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
String msg = "Found more than one application release for the UUID: " + uuid; String msg = "Found more than one application release for the UUID: " + uuid;
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
boolean isReviewCreated = reviewManager boolean isReviewCreated = reviewManager.addReview(review, uuid);
.addReview(review, application.getId(), application.getApplicationReleases().get(0).getId());
if (isReviewCreated) { if (isReviewCreated) {
return Response.status(Response.Status.CREATED).entity(review).build(); return Response.status(Response.Status.CREATED).entity(review).build();
} else { } else {
@ -120,7 +119,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
@PathParam("reviewId") int reviewId) { @PathParam("reviewId") int reviewId) {
ReviewManager reviewManager = APIUtil.getReviewManager(); ReviewManager reviewManager = APIUtil.getReviewManager();
try { try {
if (reviewManager.updateReview(review, reviewId, true)) { if (reviewManager.updateReview(review, reviewId, uuid, true)) {
return Response.status(Response.Status.OK).entity(review).build(); return Response.status(Response.Status.OK).entity(review).build();
} else { } else {
String msg = "Review updating failed. Please contact the administrator"; String msg = "Review updating failed. Please contact the administrator";
@ -136,25 +135,26 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
@Override @Override
@DELETE @DELETE
@Path("/{commentId}") @Path("/{uuid}/{reviewId}")
public Response deleteComment( public Response deleteReview(
@PathParam("commentId") int commentId, @PathParam("uuid") String uuid,
@QueryParam("username") String username) { @PathParam("reviewId") int reviewId) {
ReviewManager reviewManager = APIUtil.getReviewManager(); ReviewManager reviewManager = APIUtil.getReviewManager();
try { try {
if (commentId == 0) { if (reviewId == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("Review not found").build(); return Response.status(Response.Status.NOT_FOUND).entity("Review not found").build();
} else if (reviewManager.deleteReview(uuid, reviewId)) {
return Response.status(Response.Status.OK).entity("Review is deleted successfully.").build();
} else { } else {
reviewManager.deleteReview(username, commentId); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Review deleting is failed.")
.build();
} }
} catch (ReviewManagementException e) { } catch (ReviewManagementException e) {
String msg = "Error occurred while deleting the comment."; String msg = "Error occurred while deleting the comment.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg) return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
.build();
} }
return Response.status(Response.Status.OK).entity("Review is deleted successfully.").build();
} }
@Override @Override

@ -56,186 +56,186 @@ import static org.mockito.MockitoAnnotations.initMocks;
private ReviewManagementAPI commentManagementAPI; private ReviewManagementAPI commentManagementAPI;
private ReviewManager reviewManager; private ReviewManager reviewManager;
//
@ObjectFactory // @ObjectFactory
public IObjectFactory getObjectFactory() { // public IObjectFactory getObjectFactory() {
return new org.powermock.modules.testng.PowerMockObjectFactory(); // return new org.powermock.modules.testng.PowerMockObjectFactory();
} // }
//
@BeforeClass // @BeforeClass
void init() throws ReviewManagementException { // void init() throws ReviewManagementException {
//
log.info("Initializing ReviewManagementAPI tests"); // log.info("Initializing ReviewManagementAPI tests");
initMocks(this); // initMocks(this);
this.reviewManager = Mockito.mock(ReviewManager.class, Mockito.RETURNS_DEFAULTS); // this.reviewManager = Mockito.mock(ReviewManager.class, Mockito.RETURNS_DEFAULTS);
this.commentManagementAPI = new ReviewManagementAPIImpl(); // this.commentManagementAPI = new ReviewManagementAPIImpl();
} // }
//
@Test // @Test
public void testGetAllCommentsWithValidDetails() throws Exception { // public void testGetAllCommentsWithValidDetails() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.getAllReviews("a", 1, 2); // Response response = this.commentManagementAPI.getAllReviews("a", 1, 2);
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The response status should be 200."); // "The response status should be 200.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
//
@Test // @Test
public void testGetAllCommentsInternalError() throws Exception { // public void testGetAllCommentsInternalError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager) // Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager)
.getAllReviews(Mockito.any(), Mockito.anyString()); // .getAllReviews(Mockito.any(), Mockito.anyString());
Response response = this.commentManagementAPI.getAllReviews("a", 1, 4); // Response response = this.commentManagementAPI.getAllReviews("a", 1, 4);
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500."); // "The response status should be 500.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
//
@Test // @Test
public void testGetAllCommentsNotFoundError() throws Exception { // public void testGetAllCommentsNotFoundError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.getAllReviews(null, 1, 3); // Response response = this.commentManagementAPI.getAllReviews(null, 1, 3);
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
"The response status should be 404."); // "The response status should be 404.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
//
@Test // @Test
public void testAddComments() throws Exception { // public void testAddComments() throws Exception {
Review review = CommentMgtTestHelper.getDummyComment("a", "a"); // Review review = CommentMgtTestHelper.getDummyComment("a", "a");
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.addReview(review, "a"); // Response response = this.commentManagementAPI.addReview(review, "a");
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(),
"The response status should be 201."); // "The response status should be 201.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
//
@Test // @Test
public void testAddNullComment() throws Exception { // public void testAddNullComment() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.addReview(null, "a"); // Response response = this.commentManagementAPI.addReview(null, "a");
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400."); // "The response status should be 400.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
//
@Test // @Test
public void testAddCommentsInternalError() throws Exception { // public void testAddCommentsInternalError() throws Exception {
Review review = CommentMgtTestHelper.getDummyComment("a", "a"); // Review review = CommentMgtTestHelper.getDummyComment("a", "a");
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Mockito.when(this.commentManagementAPI.addReview(Mockito.any(), Mockito.anyString())) // Mockito.when(this.commentManagementAPI.addReview(Mockito.any(), Mockito.anyString()))
.thenThrow(new ReviewManagementException()); // .thenThrow(new ReviewManagementException());
Response response = this.commentManagementAPI.addReview(review, null); // Response response = this.commentManagementAPI.addReview(review, null);
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500."); // "The response status should be 500.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
//
@Test // @Test
public void testUpdateComment() throws Exception { // public void testUpdateComment() throws Exception {
Review review = CommentMgtTestHelper.getDummyComment("a", "a"); // Review review = CommentMgtTestHelper.getDummyComment("a", "a");
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.updateReview(review, 1); // Response response = this.commentManagementAPI.updateReview(review, 1);
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The response status should be 200."); // "The response status should be 200.");
} // }
//
@Test // @Test
public void testUpdateNullComment() throws Exception { // public void testUpdateNullComment() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.updateReview(null, 1); // Response response = this.commentManagementAPI.updateReview(null, 1);
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400."); // "The response status should be 400.");
} // }
//
@Test // @Test
public void testUpdateCommentWhenNullCommentId() throws Exception { // public void testUpdateCommentWhenNullCommentId() throws Exception {
Review review = CommentMgtTestHelper.getDummyComment("a", "a"); // Review review = CommentMgtTestHelper.getDummyComment("a", "a");
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.updateReview(review, 0); // Response response = this.commentManagementAPI.updateReview(review, 0);
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
"The response status should be 404."); // "The response status should be 404.");
} // }
//
@Test // @Test
public void testUpdateCommentInternalServerError() throws Exception { // public void testUpdateCommentInternalServerError() throws Exception {
Review review = CommentMgtTestHelper.getDummyComment("a", "a"); // Review review = CommentMgtTestHelper.getDummyComment("a", "a");
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager).updateReview(review, 9, true); // Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager).updateReview(review, 9, true);
Response response = this.commentManagementAPI.updateReview(review, 9); // Response response = this.commentManagementAPI.updateReview(review, 9);
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500."); // "The response status should be 500.");
} // }
//
@Test // @Test
public void testDeleteComment() throws Exception { // public void testDeleteComment() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.deleteComment(1,""); // Response response = this.commentManagementAPI.deleteReview(1,"");
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The response status should be 200."); // "The response status should be 200.");
} // }
//
@Test // @Test
public void testDeleteCommentInternalError() throws Exception { // public void testDeleteCommentInternalError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Mockito.when(this.commentManagementAPI.deleteComment(1,"")).thenThrow(new ReviewManagementException()); // Mockito.when(this.commentManagementAPI.deleteReview(1,"")).thenThrow(new ReviewManagementException());
Response response = this.commentManagementAPI.deleteComment(1,""); // Response response = this.commentManagementAPI.deleteReview(1,"");
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500."); // "The response status should be 500.");
} // }
//
@Test // @Test
public void testDeleteCommentNotFoundError() throws Exception { // public void testDeleteCommentNotFoundError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.deleteComment(0,""); // Response response = this.commentManagementAPI.deleteReview(0,"");
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
"The response status should be 404."); // "The response status should be 404.");
} // }
//
@Test // @Test
public void testGetStars() throws Exception { // public void testGetStars() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.getRating("a"); // Response response = this.commentManagementAPI.getRating("a");
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The response status should be 200."); // "The response status should be 200.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
//
@Test // @Test
public void testGetStarsCommentError() throws Exception { // public void testGetStarsCommentError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString())) // Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString()))
.thenThrow(new ReviewManagementException()); // .thenThrow(new ReviewManagementException());
Response response = this.commentManagementAPI.getRating("a"); // Response response = this.commentManagementAPI.getRating("a");
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500."); // "The response status should be 500.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
//
@Test // @Test
public void testGetStarsApplicationError() throws Exception { // public void testGetStarsApplicationError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString())) // Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString()))
.thenThrow(new ApplicationManagementException()); // .thenThrow(new ApplicationManagementException());
Response response = this.commentManagementAPI.getRating("a"); // Response response = this.commentManagementAPI.getRating("a");
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500."); // "The response status should be 500.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
} }
Loading…
Cancel
Save