|
|
@ -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)) {
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
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) {
|
|
|
|
} 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 {
|
|
|
|