|
|
@ -24,6 +24,7 @@ import org.wso2.carbon.device.application.mgt.common.Rating;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ReviewNode;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ReviewNode;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.PaginationResult;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.PaginationResult;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.ReviewDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.ReviewDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
|
|
@ -49,6 +50,7 @@ import java.util.ArrayList;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.TreeMap;
|
|
|
|
import java.util.TreeMap;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.IntStream;
|
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -72,7 +74,7 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean addReview(ReviewWrapper reviewWrapper, String uuid)
|
|
|
|
public boolean addReview(ReviewWrapper reviewWrapper, String uuid,boolean allowMultipleReviews)
|
|
|
|
throws ReviewManagementException, ApplicationManagementException {
|
|
|
|
throws ReviewManagementException, ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
@ -82,37 +84,47 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (reviewWrapper.getRating() < 0) {
|
|
|
|
if (reviewWrapper.getRating() <= 0) {
|
|
|
|
String msg = "You are trying to add invalid rating value as rating. Therefore please verify the request "
|
|
|
|
String msg = "You are trying to add invalid rating value as rating. Therefore please verify the request "
|
|
|
|
+ "payload.";
|
|
|
|
+ "payload.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO.getReleaseByUUID(uuid, tenantId);
|
|
|
|
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(uuid, tenantId);
|
|
|
|
if (applicationReleaseDTO == null) {
|
|
|
|
if (applicationDTO == null) {
|
|
|
|
String msg = "Couldn't find application release for the application UUID: " + uuid;
|
|
|
|
String msg = "Couldn't find an application which has the application release of UUID: " + uuid;
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.reviewDAO.haveUerReviewed(applicationReleaseDTO.getId(), username, tenantId)) {
|
|
|
|
List<Integer> applicationReleaseIds = new ArrayList<>();
|
|
|
|
|
|
|
|
int associatedAppReleaseId = -1;
|
|
|
|
|
|
|
|
for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) {
|
|
|
|
|
|
|
|
if (applicationReleaseDTO.getUuid().equals(uuid)){
|
|
|
|
|
|
|
|
associatedAppReleaseId = applicationReleaseDTO.getId();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Integer id = applicationReleaseDTO.getId();
|
|
|
|
|
|
|
|
applicationReleaseIds.add(id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!allowMultipleReviews && this.reviewDAO.hasUerReviewedApp(applicationReleaseIds, username, tenantId)) {
|
|
|
|
String msg =
|
|
|
|
String msg =
|
|
|
|
"User " + username + " has already reviewed the application release which has UUID: " + uuid
|
|
|
|
"User " + username + " has already reviewed the application of app release which has UUID: "
|
|
|
|
+ ". Hence you can't add another review for same application release. But you can update "
|
|
|
|
+ uuid + ". Hence you can't add another review for same application. But if you have "
|
|
|
|
+ "the review that you have already added for ths application release.";
|
|
|
|
+ "added review for same app release you can update the review that you have already "
|
|
|
|
|
|
|
|
+ "added for ths application.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Runnable task = () -> calculateRating(reviewWrapper.getRating(), -12345, uuid, tenantId);
|
|
|
|
|
|
|
|
new Thread(task).start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ReviewDTO reviewDTO = reviewWrapperToDO(reviewWrapper);
|
|
|
|
ReviewDTO reviewDTO = reviewWrapperToDTO(reviewWrapper);
|
|
|
|
reviewDTO.setUsername(username);
|
|
|
|
reviewDTO.setUsername(username);
|
|
|
|
reviewDTO.setRootParentId(-1);
|
|
|
|
reviewDTO.setRootParentId(-1);
|
|
|
|
reviewDTO.setImmediateParentId(-1);
|
|
|
|
reviewDTO.setImmediateParentId(-1);
|
|
|
|
if (this.reviewDAO.addReview(reviewDTO, applicationReleaseDTO.getId(), tenantId)) {
|
|
|
|
if (this.reviewDAO.addReview(reviewDTO, associatedAppReleaseId, tenantId)) {
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
|
|
|
Runnable task = () -> calculateRating(reviewWrapper.getRating(), -12345, uuid, tenantId);
|
|
|
|
|
|
|
|
new Thread(task).start();
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
@ -153,22 +165,24 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ReviewDTO parentReview = getReview(parentReviewId);
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO.getReleaseByUUID(uuid, tenantId);
|
|
|
|
|
|
|
|
if (applicationReleaseDTO == null) {
|
|
|
|
|
|
|
|
String msg = "Couldn't find application release for the application UUID: " + uuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ReviewDTO parentReview = this.reviewDAO.getReview(applicationReleaseDTO.getId(), parentReviewId);
|
|
|
|
|
|
|
|
if (parentReview == null) {
|
|
|
|
if (parentReview == null) {
|
|
|
|
String msg = "Couldn't find an review which has review ID: " + parentReviewId
|
|
|
|
String msg = "Couldn't find an review which has review ID: " + parentReviewId
|
|
|
|
+ " for application release which has UUID: " + uuid;
|
|
|
|
+ " for application release which has UUID: " + uuid;
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ReviewDTO replyComment = reviewWrapperToDO(reviewWrapper);
|
|
|
|
if (!parentReview.getReleaseUuid().equals(uuid)) {
|
|
|
|
|
|
|
|
String msg =
|
|
|
|
|
|
|
|
"Bad Request. You are trying to add reply comment for application release which has UUID: " + uuid
|
|
|
|
|
|
|
|
+ "," + " but parent review is associated with application release which has UUID: "
|
|
|
|
|
|
|
|
+ parentReview.getReleaseUuid() + ". Hence can't proceed this request further.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ReviewDTO replyComment = reviewWrapperToDTO(reviewWrapper);
|
|
|
|
replyComment.setUsername(username);
|
|
|
|
replyComment.setUsername(username);
|
|
|
|
replyComment.setRating(0);
|
|
|
|
replyComment.setRating(0);
|
|
|
|
replyComment.setImmediateParentId(parentReview.getId());
|
|
|
|
replyComment.setImmediateParentId(parentReview.getId());
|
|
|
@ -177,21 +191,26 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
replyComment.setRootParentId(parentReview.getRootParentId());
|
|
|
|
replyComment.setRootParentId(parentReview.getRootParentId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO.getReleaseByUUID(uuid, tenantId);
|
|
|
|
if (this.reviewDAO.addReview(replyComment, applicationReleaseDTO.getId(), tenantId)) {
|
|
|
|
if (this.reviewDAO.addReview(replyComment, applicationReleaseDTO.getId(), tenantId)) {
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new ReviewManagementException(
|
|
|
|
throw new ReviewManagementException(
|
|
|
|
"DB Connection error occurs ,Review for application release with UUID: " + uuid + " is failed",
|
|
|
|
"DB Connection error occurs ,Review for application release with UUID: " + uuid + " is failed", e);
|
|
|
|
e);
|
|
|
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
String msg = "DB transaction error occurred when adding reply comment for comment which has comment id: "
|
|
|
|
String msg = "DB transaction error occurred when adding reply comment for comment which has comment id: "
|
|
|
|
+ parentReviewId;
|
|
|
|
+ parentReviewId;
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ReviewManagementException(msg, e);
|
|
|
|
throw new ReviewManagementException(msg, e);
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
throw new ReviewManagementException(
|
|
|
|
throw new ReviewManagementException(
|
|
|
|
"Error occured while verifying whether application release is exists or not.", e);
|
|
|
|
"Error occured while verifying whether application release is exists or not.", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
@ -199,7 +218,7 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ReviewDTO reviewWrapperToDO(ReviewWrapper reviewWrapper){
|
|
|
|
private ReviewDTO reviewWrapperToDTO(ReviewWrapper reviewWrapper){
|
|
|
|
ReviewDTO reviewDTO = new ReviewDTO();
|
|
|
|
ReviewDTO reviewDTO = new ReviewDTO();
|
|
|
|
reviewDTO.setContent(reviewWrapper.getContent());
|
|
|
|
reviewDTO.setContent(reviewWrapper.getContent());
|
|
|
|
reviewDTO.setRating(reviewWrapper.getRating());
|
|
|
|
reviewDTO.setRating(reviewWrapper.getRating());
|
|
|
@ -229,50 +248,77 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
return review;
|
|
|
|
return review;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
private ReviewDTO getReview(int reviewId) throws ReviewManagementException {
|
|
|
|
public boolean updateReview(ReviewWrapper updatingReview, int reviewId, String uuid, boolean isPriviledgedUser)
|
|
|
|
|
|
|
|
throws ReviewManagementException, ApplicationManagementException {
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Review updating request is received for the reviewTmp id " + reviewId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO.getReleaseByUUID(uuid, tenantId);
|
|
|
|
return this.reviewDAO.getReview(reviewId);
|
|
|
|
if (applicationReleaseDTO == null) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
String msg = "Couldn't found an application release for UUID: " + uuid;
|
|
|
|
String msg = "DB Connection error occurs updating reviewTmp with reviewTmp id " + reviewId + ".";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
throw new ReviewManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ReviewDTO reviewDTO = this.reviewDAO.getReview(applicationReleaseDTO.getId(), reviewId);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean updateReview(ReviewWrapper updatingReview, int reviewId, String uuid,
|
|
|
|
|
|
|
|
boolean isPrivilegedUser) throws ReviewManagementException, ApplicationManagementException {
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
|
|
|
ReviewDTO reviewDTO = getReview(reviewId);
|
|
|
|
if (reviewDTO == null) {
|
|
|
|
if (reviewDTO == null) {
|
|
|
|
String msg =
|
|
|
|
String msg = "Couldn't found a review for review ID: " + reviewId;
|
|
|
|
"Couldn't found a review for application release which has UUID: " + uuid + " and review ID: "
|
|
|
|
|
|
|
|
+ reviewId;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isPrivilegedUser && !username.equals(reviewDTO.getUsername())) {
|
|
|
|
if (!isPriviledgedUser && !username.equals(reviewDTO.getUsername())) {
|
|
|
|
|
|
|
|
String msg = "You are trying to update a review which is created by " + reviewDTO.getUsername()
|
|
|
|
String msg = "You are trying to update a review which is created by " + reviewDTO.getUsername()
|
|
|
|
+ ". Hence you are not permitted to update the review.";
|
|
|
|
+ ". Hence you are not permitted to update the review.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (reviewDTO.getRootParentId() == -1 && reviewDTO.getImmediateParentId() == -1
|
|
|
|
boolean isActiveReview = true;
|
|
|
|
&& updatingReview.getRating() > 0 && updatingReview.getRating() != reviewDTO.getRating()) {
|
|
|
|
//Handle Review
|
|
|
|
Runnable task = () -> calculateRating(updatingReview.getRating(), reviewDTO.getRating(), uuid,
|
|
|
|
if (reviewDTO.getRootParentId() == -1 && reviewDTO.getImmediateParentId() == -1) {
|
|
|
|
tenantId);
|
|
|
|
if (!reviewDTO.getReleaseUuid().equals(uuid)) {
|
|
|
|
|
|
|
|
isActiveReview = false;
|
|
|
|
|
|
|
|
if (!addReview(updatingReview, uuid, true)) {
|
|
|
|
|
|
|
|
String msg = "Review Updating Status: New review adding is failed.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (updatingReview.getRating() > 0 && updatingReview.getRating() != reviewDTO.getRating()) {
|
|
|
|
|
|
|
|
Runnable task = () -> ReviewManagerImpl.this
|
|
|
|
|
|
|
|
.calculateRating(updatingReview.getRating(), reviewDTO.getRating(), uuid, tenantId);
|
|
|
|
new Thread(task).start();
|
|
|
|
new Thread(task).start();
|
|
|
|
reviewDTO.setRating(updatingReview.getRating());
|
|
|
|
reviewDTO.setRating(updatingReview.getRating());
|
|
|
|
|
|
|
|
reviewDTO.setContent(updatingReview.getContent());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (!reviewDTO.getReleaseUuid().equals(uuid)) {
|
|
|
|
|
|
|
|
String msg = "You are trying to update reply comment, but associated application release UUID and "
|
|
|
|
|
|
|
|
+ "requested app release UUID are mismatched.";
|
|
|
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reviewDTO.setContent(updatingReview.getContent());
|
|
|
|
reviewDTO.setContent(updatingReview.getContent());
|
|
|
|
if (this.reviewDAO.updateReview(reviewDTO, reviewId, tenantId) == 1){
|
|
|
|
}
|
|
|
|
|
|
|
|
return updateReviewInDB(reviewDTO, uuid, reviewId, isActiveReview, tenantId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean updateReviewInDB(ReviewDTO reviewDTO, String uuid, int reviewId, boolean isActiveReview,
|
|
|
|
|
|
|
|
int tenantId) throws ReviewManagementException, ApplicationManagementException {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
|
|
|
if (this.reviewDAO.updateReview(reviewDTO, reviewId, isActiveReview, tenantId) == 1) {
|
|
|
|
|
|
|
|
if (!isActiveReview) {
|
|
|
|
|
|
|
|
updateAppRating(uuid, tenantId);
|
|
|
|
|
|
|
|
}
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
} catch (ReviewManagementDAOException e) {
|
|
|
|
} catch (ReviewManagementDAOException e) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
@ -283,10 +329,6 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
String msg = "DB Connection error occurs updating reviewTmp with reviewTmp id " + reviewId + ".";
|
|
|
|
String msg = "DB Connection error occurs updating reviewTmp with reviewTmp id " + reviewId + ".";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ReviewManagementException(msg, e);
|
|
|
|
throw new ReviewManagementException(msg, e);
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occured when getting application release data for application release UUID: " + uuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
String msg = "DB transaction error occurred when updating comment which has comment id: " + reviewId;
|
|
|
|
String msg = "DB transaction error occurred when updating comment which has comment id: " + reviewId;
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -297,13 +339,11 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public PaginationResult getAllReviews(PaginationRequest request, String uuid)
|
|
|
|
public PaginationResult getAllReleaseReviews(PaginationRequest request, String uuid)
|
|
|
|
throws ReviewManagementException, ApplicationManagementException {
|
|
|
|
throws ReviewManagementException, ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
PaginationResult paginationResult = new PaginationResult();
|
|
|
|
|
|
|
|
TreeMap<Integer, ReviewNode<ReviewDTO>> reviewTree = new TreeMap<>();
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Get all reviewTmps of the application release uuid: " + uuid);
|
|
|
|
log.debug("Get all release reviews of the application release uuid: " + uuid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
@ -313,7 +353,109 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<ReviewDTO> reviewDTOs= this.reviewDAO.getAllReviews(releaseDTO.getId(), request, tenantId);
|
|
|
|
return getReviewTree(this.reviewDAO.getAllActiveReleaseReviews(releaseDTO.getId(), request, tenantId));
|
|
|
|
|
|
|
|
} catch (ReviewManagementDAOException e) {
|
|
|
|
|
|
|
|
throw new ReviewManagementException("Error occured while getting all reviews for application uuid: " + uuid,
|
|
|
|
|
|
|
|
e);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
throw new ReviewManagementException("Error occured while getting the DB connection.", e);
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while getting application release details for application release UUId " + uuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public PaginationResult getAllAppReviews(PaginationRequest request, String uuid)
|
|
|
|
|
|
|
|
throws ReviewManagementException, ApplicationManagementException {
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Get all reviews of the application release uuid: " + uuid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Integer> applicationReleaseIds = getAppReleaseIdsByUUID(uuid, tenantId);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
|
|
|
return getReviewTree(this.reviewDAO.getAllActiveAppReviews(applicationReleaseIds, request, tenantId));
|
|
|
|
|
|
|
|
} catch (ReviewManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occured while getting all reviews for application which has an "
|
|
|
|
|
|
|
|
+ "application release of uuid: " + uuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
String msg = "Error occured while getting the DB connection to get app app reviews.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public PaginationResult getAllAppReviewsOfUser(PaginationRequest request, String uuid)
|
|
|
|
|
|
|
|
throws ReviewManagementException, ApplicationManagementException {
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Get all reviews of the application release uuid: " + uuid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Integer> applicationReleaseIds = getAppReleaseIdsByUUID(uuid, tenantId);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
|
|
|
List<ReviewDTO> reviewDtos = this.reviewDAO
|
|
|
|
|
|
|
|
.getAllActiveAppReviewsOfUser(applicationReleaseIds, request, username, tenantId);
|
|
|
|
|
|
|
|
if (!reviewDtos.isEmpty() && reviewDtos.size() > 1) {
|
|
|
|
|
|
|
|
String msg = "User " + username + " can't have more than active application review for application which"
|
|
|
|
|
|
|
|
+ " has application release of UUID: " + uuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return getReviewTree(reviewDtos);
|
|
|
|
|
|
|
|
} catch (ReviewManagementDAOException e) {
|
|
|
|
|
|
|
|
throw new ReviewManagementException("Error occured while getting all reviews for application which has an "
|
|
|
|
|
|
|
|
+ "application release of uuid: " + uuid,
|
|
|
|
|
|
|
|
e);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
throw new ReviewManagementException("Error occured while getting the DB connection.", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<Integer> getAppReleaseIdsByUUID(String uuid, int tenantId)
|
|
|
|
|
|
|
|
throws ReviewManagementException, ApplicationManagementException {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
|
|
|
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(uuid, tenantId);
|
|
|
|
|
|
|
|
if (applicationDTO == null) {
|
|
|
|
|
|
|
|
String msg = "Couldn't find an application which has the application release of UUID: " + uuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return applicationDTO.getApplicationReleaseDTOs().stream().map(ApplicationReleaseDTO::getId)
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
String msg = "Error occured while getting the DB connection to get application which has application release"
|
|
|
|
|
|
|
|
+ " of UUID: " + uuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while getting application release details for application which has an "
|
|
|
|
|
|
|
|
+ "application release of UUID " + uuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private PaginationResult getReviewTree(List<ReviewDTO> reviewDTOs) throws ReviewManagementException {
|
|
|
|
|
|
|
|
TreeMap<Integer, ReviewNode<ReviewDTO>> reviewTree = new TreeMap<>();
|
|
|
|
|
|
|
|
PaginationResult paginationResult = new PaginationResult();
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
try {
|
|
|
|
for (ReviewDTO reviewDTO : reviewDTOs) {
|
|
|
|
for (ReviewDTO reviewDTO : reviewDTOs) {
|
|
|
|
ReviewNode<ReviewDTO> rootNode = new ReviewNode<>(reviewDTO);
|
|
|
|
ReviewNode<ReviewDTO> rootNode = new ReviewNode<>(reviewDTO);
|
|
|
|
reviewTree.put(reviewDTO.getId(), rootNode);
|
|
|
|
reviewTree.put(reviewDTO.getId(), rootNode);
|
|
|
@ -335,16 +477,8 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
paginationResult.setRecordsTotal(numOfReviews);
|
|
|
|
paginationResult.setRecordsTotal(numOfReviews);
|
|
|
|
return paginationResult;
|
|
|
|
return paginationResult;
|
|
|
|
} catch (ReviewManagementDAOException e) {
|
|
|
|
} catch (ReviewManagementDAOException e) {
|
|
|
|
throw new ReviewManagementException("Error occured while getting all reviewTmps for application uuid: " + uuid,
|
|
|
|
throw new ReviewManagementException("Error occured while getting all reply comments for given review list",
|
|
|
|
e);
|
|
|
|
e);
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
throw new ReviewManagementException("Error occured while getting the DB connection.", e);
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while getting application release details for application release UUId " + uuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -406,19 +540,18 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO.getReleaseByUUID(uuid, tenantId);
|
|
|
|
ReviewDTO existingReview = this.reviewDAO.getReview(reviewId);
|
|
|
|
if (applicationReleaseDTO == null) {
|
|
|
|
|
|
|
|
String msg = "Couldn't found an application release for UUID: " + uuid
|
|
|
|
|
|
|
|
+ " to delete review which has review ID: " + reviewId;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ReviewDTO existingReview = this.reviewDAO.getReview(applicationReleaseDTO.getId(), reviewId);
|
|
|
|
|
|
|
|
if (existingReview == null) {
|
|
|
|
if (existingReview == null) {
|
|
|
|
String msg = "Cannot delete a non-existing review for the application with review id" + reviewId;
|
|
|
|
String msg = "Cannot delete a non-existing review for the application with review id" + reviewId;
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!existingReview.getReleaseUuid().equals(uuid)){
|
|
|
|
|
|
|
|
String msg = "You are trying to delete a review which is not associated with application release which "
|
|
|
|
|
|
|
|
+ "has UUID: " + uuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!isPriviledgedUser && !username.equals(existingReview.getUsername())) {
|
|
|
|
if (!isPriviledgedUser && !username.equals(existingReview.getUsername())) {
|
|
|
|
String msg = "You are trying to delete a comment that is owned by you. Hence you are not permitted to "
|
|
|
|
String msg = "You are trying to delete a comment that is owned by you. Hence you are not permitted to "
|
|
|
|
+ "delete the review";
|
|
|
|
+ "delete the review";
|
|
|
@ -433,7 +566,7 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
Runnable task = () -> calculateRating(0, existingReview.getRating(), uuid, tenantId);
|
|
|
|
Runnable task = () -> calculateRating(0, existingReview.getRating(), uuid, tenantId);
|
|
|
|
new Thread(task).start();
|
|
|
|
new Thread(task).start();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ReviewDTO rootReview = this.reviewDAO.getReview(existingReview.getRootParentId());
|
|
|
|
ReviewDTO rootReview = this.reviewDAO.getReview(existingReview.getRootParentId(), tenantId);
|
|
|
|
List<ReviewDTO> replyComments = this.reviewDAO.getReplyComments(rootReview.getId(), tenantId);
|
|
|
|
List<ReviewDTO> replyComments = this.reviewDAO.getReplyComments(rootReview.getId(), tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
ReviewNode<ReviewDTO> reviewNode = new ReviewNode<>(rootReview);
|
|
|
|
ReviewNode<ReviewDTO> reviewNode = new ReviewNode<>(rootReview);
|
|
|
@ -460,59 +593,97 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
String msg = "Error occurred when handleing transaction to delete application reviews.";
|
|
|
|
String msg = "Error occurred when handleing transaction to delete application reviews.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ReviewManagementException(msg, e);
|
|
|
|
throw new ReviewManagementException(msg, e);
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error Occurred when getting application release data for application release UUID: " + uuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override public Rating getRating(String appReleaseUuuid) throws ReviewManagementException, ApplicationManagementException {
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Rating getAppReleaseRating(String appReleaseUuid) throws ReviewManagementException, ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
Rating rating = this.applicationReleaseDAO.getRating(appReleaseUuuid, tenantId);
|
|
|
|
Rating rating = this.applicationReleaseDAO.getRating(appReleaseUuid, tenantId);
|
|
|
|
if (rating == null) {
|
|
|
|
if (rating == null) {
|
|
|
|
throw new NotFoundException(
|
|
|
|
throw new NotFoundException(
|
|
|
|
"Couldn't find rating for application release UUID: " + appReleaseUuuid
|
|
|
|
"Couldn't find rating for application release UUID: " + appReleaseUuid
|
|
|
|
+ ". Please check the existence of the application release");
|
|
|
|
+ ". Please check the existence of the application release");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<Integer> ratingValues = this.reviewDAO.getAllRatingValues(appReleaseUuuid, tenantId);
|
|
|
|
List<Integer> ratingValues = this.reviewDAO.getAllAppReleaseRatingValues(appReleaseUuid, tenantId);
|
|
|
|
TreeMap<Integer, Integer> ratingVariety = new TreeMap<>();
|
|
|
|
rating.setRatingVariety(constructRatingVariety(ratingValues));
|
|
|
|
ratingValues.forEach(ratingVal -> {
|
|
|
|
|
|
|
|
if (ratingVariety.containsKey(ratingVal)) {
|
|
|
|
|
|
|
|
ratingVariety.replace(ratingVal, ratingVariety.get(ratingVal) + 1);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ratingVariety.put(ratingVal, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
IntStream.rangeClosed(1, Constants.MAX_RATING).filter(i -> !ratingVariety.containsKey(i))
|
|
|
|
|
|
|
|
.forEach(i -> ratingVariety.put(i, 0));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rating.setRatingVariety(ratingVariety);
|
|
|
|
|
|
|
|
return rating;
|
|
|
|
return rating;
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
|
|
|
throw new ReviewManagementException(
|
|
|
|
throw new ReviewManagementException(
|
|
|
|
"Error occured while getting the rating value of the application release uuid: " + appReleaseUuuid,
|
|
|
|
"Error occured while getting the rating value of the application release uuid: " + appReleaseUuid,
|
|
|
|
e);
|
|
|
|
e);
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
|
|
|
throw new ReviewManagementException(
|
|
|
|
throw new ReviewManagementException(
|
|
|
|
"DB Connection error occured while getting the rating value of the application release uuid: "
|
|
|
|
"DB Connection error occured while getting the rating value of the application release uuid: "
|
|
|
|
+ appReleaseUuuid, e);
|
|
|
|
+ appReleaseUuid, e);
|
|
|
|
} catch (ReviewManagementDAOException e) {
|
|
|
|
} catch (ReviewManagementDAOException e) {
|
|
|
|
throw new ReviewManagementException(
|
|
|
|
throw new ReviewManagementException(
|
|
|
|
"Error occured while getting all rating values for the application release UUID: "
|
|
|
|
"Error occured while getting all rating values for the application release UUID: "
|
|
|
|
+ appReleaseUuuid, e);
|
|
|
|
+ appReleaseUuid, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Rating getAppRating(String appReleaseUuid) throws ReviewManagementException, ApplicationManagementException {
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
|
|
|
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(appReleaseUuid, tenantId);
|
|
|
|
|
|
|
|
if (applicationDTO == null) {
|
|
|
|
|
|
|
|
String msg = "Couldn't found an application for application release UUID: " + appReleaseUuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> uuids = applicationDTO.getApplicationReleaseDTOs().stream().map(ApplicationReleaseDTO::getUuid)
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
List<Integer> ratingValues = this.reviewDAO.getAllAppRatingValues(uuids, tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rating rating = new Rating();
|
|
|
|
|
|
|
|
rating.setRatingValue(applicationDTO.getAppRating());
|
|
|
|
|
|
|
|
rating.setNoOfUsers(ratingValues.size());
|
|
|
|
|
|
|
|
rating.setRatingVariety(constructRatingVariety(ratingValues));
|
|
|
|
|
|
|
|
return rating;
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
String msg = "DB Connection error occured while getting app rating of the application which has application "
|
|
|
|
|
|
|
|
+ "release for uuid: " + appReleaseUuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementException(msg, e);
|
|
|
|
|
|
|
|
}catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occured while getting the application DTO for the application release uuid: " + appReleaseUuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (ReviewManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg ="Error occured while getting all rating values of application which has the application release "
|
|
|
|
|
|
|
|
+ "for UUID: " + appReleaseUuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementException(msg, e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private TreeMap<Integer, Integer> constructRatingVariety(List<Integer> ratingValues) {
|
|
|
|
|
|
|
|
TreeMap<Integer, Integer> ratingVariety = new TreeMap<>();
|
|
|
|
|
|
|
|
ratingValues.forEach(ratingVal -> {
|
|
|
|
|
|
|
|
if (ratingVariety.containsKey(ratingVal)) {
|
|
|
|
|
|
|
|
ratingVariety.replace(ratingVal, ratingVariety.get(ratingVal) + 1);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ratingVariety.put(ratingVal, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
IntStream.rangeClosed(1, Constants.MAX_RATING).filter(i -> !ratingVariety.containsKey(i))
|
|
|
|
|
|
|
|
.forEach(i -> ratingVariety.put(i, 0));
|
|
|
|
|
|
|
|
return ratingVariety;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void calculateRating(int newRatingVal, int oldRatingVal, String uuid, int tenantId) {
|
|
|
|
private void calculateRating(int newRatingVal, int oldRatingVal, String uuid, int tenantId) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
@ -544,14 +715,7 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers);
|
|
|
|
this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers);
|
|
|
|
|
|
|
|
updateAppRating(uuid, tenantId);
|
|
|
|
List<Double> releaseRatings = this.applicationReleaseDAO.getReleaseRatings(uuid, tenantId);
|
|
|
|
|
|
|
|
double appAverageRatingValue = 0.0;
|
|
|
|
|
|
|
|
double sumOfRatings = releaseRatings.stream().mapToDouble(rt -> rt).sum();
|
|
|
|
|
|
|
|
if (sumOfRatings != 0.0) {
|
|
|
|
|
|
|
|
appAverageRatingValue = sumOfRatings / releaseRatings.size();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.applicationDAO.updateApplicationRating(uuid, appAverageRatingValue, tenantId);
|
|
|
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
@ -564,8 +728,31 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
log.error(
|
|
|
|
log.error(
|
|
|
|
"Transaction error occured while updated the rating value of the application release UUID: " + uuid
|
|
|
|
"Transaction error occured while updated the rating value of the application release UUID: " + uuid
|
|
|
|
+ " can not get.", e);
|
|
|
|
+ " can not get.", e);
|
|
|
|
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
|
|
|
log.error("Error occured while updating app rating value which has application release for UUID: " + uuid,
|
|
|
|
|
|
|
|
e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void updateAppRating(String uuid, int tenantId) throws ApplicationManagementException {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(uuid, tenantId);
|
|
|
|
|
|
|
|
List<String> uuids = applicationDTO.getApplicationReleaseDTOs().stream().map(ApplicationReleaseDTO::getUuid)
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
List<Integer> appRatings = this.reviewDAO.getAllAppRatingValues(uuids, tenantId);
|
|
|
|
|
|
|
|
double appAverageRatingValue = appRatings.stream().mapToDouble(x -> x).average().orElse(Double.NaN);
|
|
|
|
|
|
|
|
this.applicationDAO.updateApplicationRating(uuid, appAverageRatingValue, tenantId);
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred when getting application data or updating application rating value.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (ReviewManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred when getting application rating values";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|