mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'application-mgt-new' of https://gitlab.com/entgra/carbon-device-mgt into application-mgt-new
This commit is contained in:
commit
b856aa36fe
20
.gitlab-ci.yml
Normal file
20
.gitlab-ci.yml
Normal file
@ -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")
|
||||
private LifecycleState lifecycleState;
|
||||
|
||||
@ApiModelProperty(name = "packageName",
|
||||
value = "Application bundle identifier")
|
||||
private String packageName;
|
||||
|
||||
public int getRatedUsers() {
|
||||
return ratedUsers;
|
||||
}
|
||||
@ -257,4 +261,12 @@ public class ApplicationRelease {
|
||||
public void setLifecycleState(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.
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @param review review of the application.
|
||||
* @param appId id of the application.
|
||||
* @param appReleaseId id of the application release
|
||||
* @param uuid uuid of the application release.
|
||||
* @return {@link Review} Review added
|
||||
* @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
|
||||
@ -62,20 +61,25 @@ public interface ReviewManager {
|
||||
/**
|
||||
* To delete review using review id.
|
||||
*
|
||||
* @param uuid UUID of the application release
|
||||
* @param commentId id of the comment
|
||||
* @return If review is successfully deleted return true, otherwise returns false
|
||||
* @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.
|
||||
*
|
||||
* @param review review of the application.
|
||||
* @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
|
||||
* @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
|
||||
|
||||
@ -90,10 +90,10 @@ public interface ApplicationReleaseDAO {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
Rating getRating(int id) throws ApplicationManagementDAOException;
|
||||
Rating getRating(String uuid) throws ApplicationManagementDAOException;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -28,24 +28,32 @@ import java.sql.SQLException;
|
||||
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 {
|
||||
|
||||
/**
|
||||
* 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 uuid UUID of the application release
|
||||
* @return If review is added successfully, it return true otherwise false
|
||||
* @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.
|
||||
@ -68,7 +76,7 @@ import java.util.List;
|
||||
* @throws DBConnectionException db connection 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
|
||||
@ -101,18 +109,27 @@ import java.util.List;
|
||||
* @throws DBConnectionException db connection 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;
|
||||
|
||||
/**
|
||||
* To delete comment using comment id.
|
||||
* To delete review using review id and uuid of the application release.
|
||||
*
|
||||
* @param commentId id of the comment
|
||||
* @throws ReviewManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
* @param username username of the review owner
|
||||
* @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 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.
|
||||
*/
|
||||
int deleteReviewByAdmin(int reviewId) throws ReviewManagementDAOException;
|
||||
|
||||
/**
|
||||
* To delete comments using application details.
|
||||
@ -122,15 +139,15 @@ import java.util.List;
|
||||
* @param version version of the commented application.
|
||||
* @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
|
||||
*
|
||||
* @param request
|
||||
* @param uuid
|
||||
* @param request pagination request
|
||||
* @param uuid uuid of the application release
|
||||
* @return Review count
|
||||
* @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;
|
||||
|
||||
@Override
|
||||
public boolean addReview(Review review, int appId, int appReleaseId, int tenantId)
|
||||
public boolean addReview(Review review, String uuid, int tenantId)
|
||||
throws ReviewManagementDAOException {
|
||||
//todo
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to add review for application release. Application id: " + appId
|
||||
+ "Application Release id: " + appReleaseId);
|
||||
log.debug("Request received in DAO Layer to add review for application release. Application UUID: " + uuid);
|
||||
}
|
||||
PreparedStatement statement = null;
|
||||
ResultSet rs = null;
|
||||
@ -67,8 +65,8 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
statement.setString(2, review.getComment());
|
||||
statement.setInt(3, review.getParentId());
|
||||
statement.setString(4, review.getUsername());
|
||||
statement.setString(5,"");
|
||||
statement.setString(6,"");
|
||||
statement.setString(5,uuid);
|
||||
statement.setString(6,uuid);
|
||||
statement.executeUpdate();
|
||||
rs = statement.getGeneratedKeys();
|
||||
return rs.next();
|
||||
@ -85,26 +83,25 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Review isExistReview(int appId, int appReleaseId, String username, int tenantId)
|
||||
throws DBConnectionException, SQLException {
|
||||
public Review haveUerCommented(String uuid, String username, int tenantId) throws ReviewManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(
|
||||
"Request received in DAO Layer to check whether review exist or not rein the IoTS APPM. Application id: "
|
||||
+ appId + " Application release id: " + appReleaseId + " comment owner: " + username);
|
||||
"Request received in DAO Layer to check whether user have already commented or not for the "
|
||||
+ "application release. Application UUID: " + uuid + " comment owner: " + username +
|
||||
" tenant-id " + tenantId);
|
||||
}
|
||||
Connection conn;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet rs = null;
|
||||
Review review = null;
|
||||
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 {
|
||||
conn = this.getDBConnection();
|
||||
statement = conn.prepareStatement(sql);
|
||||
statement.setInt(1, appId);
|
||||
statement.setInt(2, appReleaseId);
|
||||
statement.setString(3, username);
|
||||
statement.setInt(4, tenantId);
|
||||
statement.setString(1, uuid);
|
||||
statement.setString(2, username);
|
||||
statement.setInt(3, tenantId);
|
||||
|
||||
rs = statement.executeQuery();
|
||||
if (rs.next()){
|
||||
@ -118,6 +115,13 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
review.setRating(rs.getInt("RATING"));
|
||||
}
|
||||
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 {
|
||||
Util.cleanupResources(statement, rs);
|
||||
}
|
||||
@ -149,7 +153,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Review getComment(int commentId) throws ReviewManagementException {
|
||||
public Review getReview(int commentId) throws ReviewManagementException {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Getting review with the review id(" + commentId + ") from the database");
|
||||
@ -259,7 +263,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCommentCount(PaginationRequest request, String uuid) throws ReviewManagementException {
|
||||
public int getReviewCount(PaginationRequest request, String uuid) throws ReviewManagementException {
|
||||
|
||||
int commentCount = 0;
|
||||
Connection conn;
|
||||
@ -293,7 +297,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCommentCountByApp(String appType, String appName, String version)
|
||||
public int getReviewCountByApp(String appType, String appName, String version)
|
||||
throws ReviewManagementException, DBConnectionException, SQLException {
|
||||
|
||||
Connection conn;
|
||||
@ -320,24 +324,48 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteComment(int commentId)
|
||||
throws ReviewManagementException, DBConnectionException, SQLException {
|
||||
|
||||
public int deleteReview(String username, int reviewId) throws ReviewManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
sql = "DELETE FROM AP_APP_COMMENT WHERE ID=?;";
|
||||
sql = "DELETE FROM AP_APP_REVIEW WHERE ID=? AND USERNAME = ?);";
|
||||
statement = conn.prepareStatement(sql);
|
||||
statement.setInt(1, commentId);
|
||||
statement.executeUpdate();
|
||||
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 void deleteComments(String appType, String appName, String version)
|
||||
public int deleteReviewByAdmin(int reviewId) throws ReviewManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
sql = "DELETE FROM AP_APP_REVIEW WHERE ID=?;";
|
||||
statement = conn.prepareStatement(sql);
|
||||
statement.setInt(1, reviewId);
|
||||
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 void deleteReviews(String appType, String appName, String version)
|
||||
throws ReviewManagementException {
|
||||
|
||||
Connection conn;
|
||||
|
||||
@ -136,9 +136,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
Pagination pagination = new Pagination();
|
||||
String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY"
|
||||
+ " AS APP_CATEGORY, AP_APP.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) "
|
||||
+ "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 != ?";
|
||||
|
||||
|
||||
@ -299,8 +299,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
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,"
|
||||
+ " AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLES.ROLE "
|
||||
+ "AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.NAME=? AND "
|
||||
+ " 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_ROLE WHERE AP_APP.NAME=? AND "
|
||||
+ "AP_APP.TYPE= ? AND AP_APP.TENANT_ID=?;";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
@ -343,8 +343,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
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, "
|
||||
+ "AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLES.ROLE "
|
||||
+ "AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.ID=? AND "
|
||||
+ "AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLE.ROLE "
|
||||
+ "AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLE WHERE AP_APP.ID=? AND "
|
||||
+ "AP_APP.TENANT_ID=?;";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
@ -385,7 +385,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
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_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 = ?;";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
@ -571,7 +571,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
+ "AP_APP_RELEASE.STARS,"
|
||||
+ "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_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=?;";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
|
||||
@ -63,10 +63,10 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
|
||||
PreparedStatement statement = null;
|
||||
ResultSet resultSet = null;
|
||||
|
||||
String sql = "INSERT INTO AP_APP_RELEASE (VERSION,TENANT_ID,UUID,RELEASE_TYPE,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 "
|
||||
+ "(?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
|
||||
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 (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
|
||||
|
||||
int index = 0;
|
||||
String generatedColumns[] = {"ID"};
|
||||
@ -77,6 +77,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
|
||||
statement.setInt(++index, tenantId);
|
||||
statement.setString(++index, applicationRelease.getUuid());
|
||||
statement.setString(++index, String.valueOf(applicationRelease.getReleaseType()));
|
||||
statement.setString(++index, String.valueOf(applicationRelease.getPackageName()));
|
||||
statement.setDouble(++index, applicationRelease.getPrice());
|
||||
statement.setString(++index, applicationRelease.getAppStoredLoc());
|
||||
statement.setString(++index, applicationRelease.getScreenshotLoc1());
|
||||
@ -121,14 +122,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.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 "
|
||||
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;";
|
||||
|
||||
try {
|
||||
@ -306,20 +308,20 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@Override
|
||||
public Rating getRating(int id) throws ApplicationManagementDAOException {
|
||||
public Rating getRating(String uuid) throws ApplicationManagementDAOException {
|
||||
Connection connection;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet resultSet = 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 {
|
||||
connection = this.getDBConnection();
|
||||
statement = connection.prepareStatement(sql);
|
||||
statement.setInt(1, id);
|
||||
statement.setString(1, uuid);
|
||||
resultSet = statement.executeQuery();
|
||||
|
||||
if (resultSet.next()){
|
||||
@ -350,27 +352,29 @@ 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 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 = ? 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 = ?;";
|
||||
try {
|
||||
connection = this.getDBConnection();
|
||||
statement = connection.prepareStatement(sql);
|
||||
statement.setString(1, applicationRelease.getVersion());
|
||||
statement.setString(2, applicationRelease.getUuid());
|
||||
statement.setString(3, applicationRelease.getReleaseType());
|
||||
statement.setDouble(4, applicationRelease.getPrice());
|
||||
statement.setString(5, applicationRelease.getAppStoredLoc());
|
||||
statement.setString(6, applicationRelease.getBannerLoc());
|
||||
statement.setString(7, applicationRelease.getScreenshotLoc1());
|
||||
statement.setString(8, applicationRelease.getScreenshotLoc2());
|
||||
statement.setString(9, applicationRelease.getScreenshotLoc3());
|
||||
statement.setString(10, applicationRelease.getAppHashValue());
|
||||
statement.setInt(11, applicationRelease.getIsSharedWithAllTenants());
|
||||
statement.setString(12, applicationRelease.getMetaData());
|
||||
statement.setString(13, applicationRelease.getApplicationCreator());
|
||||
statement.setTimestamp(14, new Timestamp(System.currentTimeMillis()));
|
||||
statement.setString(4, applicationRelease.getPackageName());
|
||||
statement.setDouble(5, applicationRelease.getPrice());
|
||||
statement.setString(6, applicationRelease.getAppStoredLoc());
|
||||
statement.setString(7, applicationRelease.getBannerLoc());
|
||||
statement.setString(8, applicationRelease.getScreenshotLoc1());
|
||||
statement.setString(9, applicationRelease.getScreenshotLoc2());
|
||||
statement.setString(10, applicationRelease.getScreenshotLoc3());
|
||||
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.executeUpdate();
|
||||
} catch (DBConnectionException e) {
|
||||
throw new ApplicationManagementDAOException(
|
||||
@ -425,6 +429,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
|
||||
applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION"));
|
||||
applicationRelease.setUuid(resultSet.getString("UUID"));
|
||||
applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE"));
|
||||
applicationRelease.setPackageName(resultSet.getString("PACKAGE_NAME"));
|
||||
applicationRelease.setPrice(resultSet.getDouble("APP_PRICE"));
|
||||
applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION"));
|
||||
applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION"));
|
||||
|
||||
@ -49,7 +49,7 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
|
||||
Connection conn;
|
||||
PreparedStatement stmt = 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{
|
||||
conn = this.getDBConnection();
|
||||
conn.setAutoCommit(false);
|
||||
@ -81,7 +81,7 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
|
||||
ResultSet rs = null;
|
||||
List<UnrestrictedRole> unrestrictedRoles = new ArrayList<>();
|
||||
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{
|
||||
conn = this.getDBConnection();
|
||||
conn.setAutoCommit(false);
|
||||
@ -115,7 +115,7 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
|
||||
Connection conn;
|
||||
PreparedStatement stmt = 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{
|
||||
conn = this.getDBConnection();
|
||||
conn.setAutoCommit(false);
|
||||
|
||||
@ -225,7 +225,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
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);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
|
||||
@ -32,6 +32,7 @@ import org.apache.commons.validator.routines.UrlValidator;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
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.DeviceType;
|
||||
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.ResourceManagementException;
|
||||
@ -200,12 +201,16 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
||||
"application UUID " + applicationRelease.getUuid());
|
||||
}
|
||||
|
||||
if (ApplicationType.ANDROID.toString().equals(deviceType)) {
|
||||
if (DeviceType.ANDROID.toString().equals(deviceType)) {
|
||||
ApkMeta apkMeta = ArtifactsParser.readAndroidManifestFile(binaryFile);
|
||||
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);
|
||||
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 {
|
||||
throw new ApplicationStorageManagementException("Application Type doesn't match with supporting " +
|
||||
"application types " + applicationRelease.getUuid());
|
||||
|
||||
@ -47,7 +47,7 @@ import java.util.List;
|
||||
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 {
|
||||
|
||||
@ -64,17 +64,17 @@ public class ReviewManagerImpl implements ReviewManager {
|
||||
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);
|
||||
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
boolean isSuccess;
|
||||
try {
|
||||
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()) {
|
||||
Runnable task = () -> calculateRating(review.getRating(), existingReview.getRating());
|
||||
Runnable task = () -> calculateRating(review.getRating(), existingReview.getRating(), uuid);
|
||||
new Thread(task).start();
|
||||
isSuccess = updateReview(review, existingReview.getId(), false);
|
||||
isSuccess = updateReview(review, existingReview.getId(),uuid, false);
|
||||
if (isSuccess) {
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} else {
|
||||
@ -82,11 +82,11 @@ public class ReviewManagerImpl implements ReviewManager {
|
||||
}
|
||||
} else {
|
||||
if (review.getRating() > 0) {
|
||||
Runnable task = () -> calculateRating(review.getRating(), -12345);
|
||||
Runnable task = () -> calculateRating(review.getRating(), -12345, uuid);
|
||||
new Thread(task).start();
|
||||
}
|
||||
review.setUsername(username);
|
||||
isSuccess = this.reviewDAO.addReview(review, appId, appReleaseId, tenantId);
|
||||
isSuccess = this.reviewDAO.addReview(review, uuid, tenantId);
|
||||
if (isSuccess) {
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} else {
|
||||
@ -97,24 +97,19 @@ public class ReviewManagerImpl implements ReviewManager {
|
||||
} catch (DBConnectionException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new ReviewManagementException(
|
||||
"DB Connection error occurs ,Review for application with app id: " + appId + " and app release id: "
|
||||
+ 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);
|
||||
"DB Connection error occurs ,Review for application release with UUID: " + uuid + " is failed", e);
|
||||
} catch (TransactionManagementException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new ReviewManagementException(
|
||||
"Transaction Management Exception occurs,Review for application with app id:" + appId
|
||||
+ " and app release id:" + appReleaseId + " is failed ", e);
|
||||
"Transaction Management Exception occurs,Review for application release with UUID:" + uuid +
|
||||
" is failed ", e);
|
||||
} finally {
|
||||
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 {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
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);
|
||||
}
|
||||
if (checkExistence) {
|
||||
existingReview = this.reviewDAO.getComment(reviewId);
|
||||
existingReview = this.reviewDAO.getReview(reviewId);
|
||||
if (existingReview != null) {
|
||||
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();
|
||||
}
|
||||
} else {
|
||||
@ -216,7 +211,7 @@ public class ReviewManagerImpl implements ReviewManager {
|
||||
}
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
review = this.reviewDAO.getComment(commentId);
|
||||
review = this.reviewDAO.getReview(commentId);
|
||||
} catch (DBConnectionException e) {
|
||||
throw new ReviewManagementException(
|
||||
"DB Connection error occurs ,Review with review id " + commentId + "cannot get.", e);
|
||||
@ -229,36 +224,44 @@ public class ReviewManagerImpl implements ReviewManager {
|
||||
return review;
|
||||
}
|
||||
|
||||
@Override public void deleteReview(String loggedInUser, int commentId) throws ReviewManagementException {
|
||||
@Override
|
||||
public boolean deleteReview(String uuid, int reviewId) throws ReviewManagementException {
|
||||
Review existingReview;
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
int isReviewDeleted;
|
||||
try {
|
||||
if (!loggedInUser.equals(username) && !isAdminUser(username, tenantId,
|
||||
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);
|
||||
existingReview = getReview(reviewId);
|
||||
if (existingReview == null) {
|
||||
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();
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
this.reviewDAO.deleteComment(commentId);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
if (isAdminUser(username, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
|
||||
isReviewDeleted = this.reviewDAO.deleteReviewByAdmin(reviewId);
|
||||
if (isReviewDeleted == 1) {
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
isReviewDeleted = this.reviewDAO.deleteReview(username, reviewId);
|
||||
if (isReviewDeleted == 1) {
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch (DBConnectionException e) {
|
||||
throw new ReviewManagementException(
|
||||
"DB Connection error occurs deleting review with review id " + commentId + ".", e);
|
||||
} catch (SQLException e) {
|
||||
throw new ReviewManagementException("SQL error occurs deleting review with review id " + commentId + ".",
|
||||
"DB Connection error occurs deleting review with review id " + reviewId + ".", e);
|
||||
} catch (ReviewManagementDAOException e) {
|
||||
throw new ReviewManagementException("Error occured while deleting review with review id " + reviewId + ".",
|
||||
e);
|
||||
} catch (TransactionManagementException e) {
|
||||
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) {
|
||||
throw new ReviewManagementException(
|
||||
"User-store exception while checking whether the user " + username + " of tenant " + tenantId
|
||||
@ -273,7 +276,7 @@ public class ReviewManagerImpl implements ReviewManager {
|
||||
int appReleaseId = 0;
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
Rating rating = this.applicationReleaseDAO.getRating(appReleaseId);
|
||||
Rating rating = this.applicationReleaseDAO.getRating(appReleaseUuuid);
|
||||
if (rating == null) {
|
||||
throw new ReviewManagementException("Couldn't find rating for application release id: " + appReleaseId
|
||||
+ ". 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
|
||||
int appReleaseId = 0;
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
Rating rating = this.applicationReleaseDAO.getRating(appReleaseId);
|
||||
Rating rating = this.applicationReleaseDAO.getRating(uuid);
|
||||
if (rating == null) {
|
||||
log.error("Couldn't find rating for application release id: " + appReleaseId);
|
||||
} else {
|
||||
|
||||
@ -124,7 +124,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
if (!isValidAppCreatingRequest(binaryFile, iconFile, bannerFile, attachmentList, application)) {
|
||||
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 = applicationStorageManager
|
||||
.uploadReleaseArtifact(applicationRelease, application.getType(), application.getDeviceType(),
|
||||
@ -173,7 +173,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
return APIUtil.getResponse(new ApplicationManagementException(errorMessage, e),
|
||||
Response.Status.INTERNAL_SERVER_ERROR);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
@ -486,7 +486,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
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: "
|
||||
+ application.getName() + " Application type: " + application.getType());
|
||||
return false;
|
||||
|
||||
@ -255,7 +255,7 @@ public interface ReviewManagementAPI {
|
||||
@PathParam("reviewId") int reviewId);
|
||||
|
||||
@DELETE
|
||||
@Path("/{commentId}")
|
||||
@Path("/{uuid}/{reviewId}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
@ -287,18 +287,17 @@ public interface ReviewManagementAPI {
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
|
||||
Response deleteComment(
|
||||
@ApiParam(
|
||||
name="commentId",
|
||||
value="Id of the comment.",
|
||||
required = true)
|
||||
@PathParam("commentId")
|
||||
int commentId,
|
||||
Response deleteReview(
|
||||
@ApiParam(
|
||||
name="username",
|
||||
value="logged in username",
|
||||
name="uuid",
|
||||
value="UUID of the application release.",
|
||||
required = true)
|
||||
@QueryParam("username") String username);
|
||||
@PathParam("uuid") String uuid,
|
||||
@ApiParam(
|
||||
name="reviewId",
|
||||
value="Id of the review.",
|
||||
required = true)
|
||||
@PathParam("reviewId") int reviewId);
|
||||
|
||||
@GET
|
||||
@Path("/{uuid}/{stars}")
|
||||
|
||||
@ -90,8 +90,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
|
||||
String msg = "Found more than one application release for the UUID: " + uuid;
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
boolean isReviewCreated = reviewManager
|
||||
.addReview(review, application.getId(), application.getApplicationReleases().get(0).getId());
|
||||
boolean isReviewCreated = reviewManager.addReview(review, uuid);
|
||||
if (isReviewCreated) {
|
||||
return Response.status(Response.Status.CREATED).entity(review).build();
|
||||
} else {
|
||||
@ -120,7 +119,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
|
||||
@PathParam("reviewId") int reviewId) {
|
||||
ReviewManager reviewManager = APIUtil.getReviewManager();
|
||||
try {
|
||||
if (reviewManager.updateReview(review, reviewId, true)) {
|
||||
if (reviewManager.updateReview(review, reviewId, uuid, true)) {
|
||||
return Response.status(Response.Status.OK).entity(review).build();
|
||||
} else {
|
||||
String msg = "Review updating failed. Please contact the administrator";
|
||||
@ -136,25 +135,26 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
|
||||
|
||||
@Override
|
||||
@DELETE
|
||||
@Path("/{commentId}")
|
||||
public Response deleteComment(
|
||||
@PathParam("commentId") int commentId,
|
||||
@QueryParam("username") String username) {
|
||||
@Path("/{uuid}/{reviewId}")
|
||||
public Response deleteReview(
|
||||
@PathParam("uuid") String uuid,
|
||||
@PathParam("reviewId") int reviewId) {
|
||||
|
||||
ReviewManager reviewManager = APIUtil.getReviewManager();
|
||||
try {
|
||||
if (commentId == 0) {
|
||||
if (reviewId == 0) {
|
||||
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 {
|
||||
reviewManager.deleteReview(username, commentId);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Review deleting is failed.")
|
||||
.build();
|
||||
}
|
||||
} catch (ReviewManagementException e) {
|
||||
String msg = "Error occurred while deleting the comment.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg)
|
||||
.build();
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity("Review is deleted successfully.").build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -56,186 +56,186 @@ import static org.mockito.MockitoAnnotations.initMocks;
|
||||
|
||||
private ReviewManagementAPI commentManagementAPI;
|
||||
private ReviewManager reviewManager;
|
||||
|
||||
@ObjectFactory
|
||||
public IObjectFactory getObjectFactory() {
|
||||
return new org.powermock.modules.testng.PowerMockObjectFactory();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
void init() throws ReviewManagementException {
|
||||
|
||||
log.info("Initializing ReviewManagementAPI tests");
|
||||
initMocks(this);
|
||||
this.reviewManager = Mockito.mock(ReviewManager.class, Mockito.RETURNS_DEFAULTS);
|
||||
this.commentManagementAPI = new ReviewManagementAPIImpl();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllCommentsWithValidDetails() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.getAllReviews("a", 1, 2);
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||
"The response status should be 200.");
|
||||
Mockito.reset(reviewManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllCommentsInternalError() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager)
|
||||
.getAllReviews(Mockito.any(), Mockito.anyString());
|
||||
Response response = this.commentManagementAPI.getAllReviews("a", 1, 4);
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||
"The response status should be 500.");
|
||||
Mockito.reset(reviewManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllCommentsNotFoundError() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.getAllReviews(null, 1, 3);
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||
"The response status should be 404.");
|
||||
Mockito.reset(reviewManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddComments() throws Exception {
|
||||
Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.addReview(review, "a");
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(),
|
||||
"The response status should be 201.");
|
||||
Mockito.reset(reviewManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddNullComment() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.addReview(null, "a");
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
||||
"The response status should be 400.");
|
||||
Mockito.reset(reviewManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddCommentsInternalError() throws Exception {
|
||||
Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Mockito.when(this.commentManagementAPI.addReview(Mockito.any(), Mockito.anyString()))
|
||||
.thenThrow(new ReviewManagementException());
|
||||
Response response = this.commentManagementAPI.addReview(review, null);
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||
"The response status should be 500.");
|
||||
Mockito.reset(reviewManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateComment() throws Exception {
|
||||
Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.updateReview(review, 1);
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||
"The response status should be 200.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateNullComment() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.updateReview(null, 1);
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
||||
"The response status should be 400.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateCommentWhenNullCommentId() throws Exception {
|
||||
Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.updateReview(review, 0);
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||
"The response status should be 404.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateCommentInternalServerError() throws Exception {
|
||||
Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager).updateReview(review, 9, true);
|
||||
Response response = this.commentManagementAPI.updateReview(review, 9);
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||
"The response status should be 500.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteComment() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.deleteComment(1,"");
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||
"The response status should be 200.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCommentInternalError() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Mockito.when(this.commentManagementAPI.deleteComment(1,"")).thenThrow(new ReviewManagementException());
|
||||
Response response = this.commentManagementAPI.deleteComment(1,"");
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||
"The response status should be 500.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCommentNotFoundError() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.deleteComment(0,"");
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||
"The response status should be 404.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStars() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.getRating("a");
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||
"The response status should be 200.");
|
||||
Mockito.reset(reviewManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStarsCommentError() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString()))
|
||||
.thenThrow(new ReviewManagementException());
|
||||
Response response = this.commentManagementAPI.getRating("a");
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||
"The response status should be 500.");
|
||||
Mockito.reset(reviewManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStarsApplicationError() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString()))
|
||||
.thenThrow(new ApplicationManagementException());
|
||||
Response response = this.commentManagementAPI.getRating("a");
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||
"The response status should be 500.");
|
||||
Mockito.reset(reviewManager);
|
||||
}
|
||||
//
|
||||
// @ObjectFactory
|
||||
// public IObjectFactory getObjectFactory() {
|
||||
// return new org.powermock.modules.testng.PowerMockObjectFactory();
|
||||
// }
|
||||
//
|
||||
// @BeforeClass
|
||||
// void init() throws ReviewManagementException {
|
||||
//
|
||||
// log.info("Initializing ReviewManagementAPI tests");
|
||||
// initMocks(this);
|
||||
// this.reviewManager = Mockito.mock(ReviewManager.class, Mockito.RETURNS_DEFAULTS);
|
||||
// this.commentManagementAPI = new ReviewManagementAPIImpl();
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetAllCommentsWithValidDetails() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.getAllReviews("a", 1, 2);
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||
// "The response status should be 200.");
|
||||
// Mockito.reset(reviewManager);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetAllCommentsInternalError() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager)
|
||||
// .getAllReviews(Mockito.any(), Mockito.anyString());
|
||||
// Response response = this.commentManagementAPI.getAllReviews("a", 1, 4);
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||
// "The response status should be 500.");
|
||||
// Mockito.reset(reviewManager);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetAllCommentsNotFoundError() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.getAllReviews(null, 1, 3);
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||
// "The response status should be 404.");
|
||||
// Mockito.reset(reviewManager);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testAddComments() throws Exception {
|
||||
// Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.addReview(review, "a");
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(),
|
||||
// "The response status should be 201.");
|
||||
// Mockito.reset(reviewManager);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testAddNullComment() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.addReview(null, "a");
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
||||
// "The response status should be 400.");
|
||||
// Mockito.reset(reviewManager);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testAddCommentsInternalError() throws Exception {
|
||||
// Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Mockito.when(this.commentManagementAPI.addReview(Mockito.any(), Mockito.anyString()))
|
||||
// .thenThrow(new ReviewManagementException());
|
||||
// Response response = this.commentManagementAPI.addReview(review, null);
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||
// "The response status should be 500.");
|
||||
// Mockito.reset(reviewManager);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testUpdateComment() throws Exception {
|
||||
// Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.updateReview(review, 1);
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||
// "The response status should be 200.");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testUpdateNullComment() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.updateReview(null, 1);
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
||||
// "The response status should be 400.");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testUpdateCommentWhenNullCommentId() throws Exception {
|
||||
// Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.updateReview(review, 0);
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||
// "The response status should be 404.");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testUpdateCommentInternalServerError() throws Exception {
|
||||
// Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager).updateReview(review, 9, true);
|
||||
// Response response = this.commentManagementAPI.updateReview(review, 9);
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||
// "The response status should be 500.");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testDeleteComment() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.deleteReview(1,"");
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||
// "The response status should be 200.");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testDeleteCommentInternalError() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Mockito.when(this.commentManagementAPI.deleteReview(1,"")).thenThrow(new ReviewManagementException());
|
||||
// Response response = this.commentManagementAPI.deleteReview(1,"");
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||
// "The response status should be 500.");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testDeleteCommentNotFoundError() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.deleteReview(0,"");
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||
// "The response status should be 404.");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetStars() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.getRating("a");
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||
// "The response status should be 200.");
|
||||
// Mockito.reset(reviewManager);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetStarsCommentError() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString()))
|
||||
// .thenThrow(new ReviewManagementException());
|
||||
// Response response = this.commentManagementAPI.getRating("a");
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||
// "The response status should be 500.");
|
||||
// Mockito.reset(reviewManager);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetStarsApplicationError() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString()))
|
||||
// .thenThrow(new ApplicationManagementException());
|
||||
// Response response = this.commentManagementAPI.getRating("a");
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||
// "The response status should be 500.");
|
||||
// Mockito.reset(reviewManager);
|
||||
// }
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user