From 756999a1e7fc108e450afb65f24ed6360f68b55d Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Thu, 20 Jun 2019 00:56:24 +0530 Subject: [PATCH] Fix APPM deadlock issue in review management --- .../mgt/core/impl/ReviewManagerImpl.java | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java index 01f384d288d..48260b269a7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java @@ -284,11 +284,6 @@ public class ReviewManagerImpl implements ReviewManager { if (reviewDTO.getRootParentId() == -1 && reviewDTO.getImmediateParentId() == -1) { 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); @@ -304,17 +299,35 @@ public class ReviewManagerImpl implements ReviewManager { } reviewDTO.setContent(updatingReview.getContent()); } - return updateReviewInDB(reviewDTO, uuid, reviewId, isActiveReview, tenantId); + + if (updateReviewInDB(reviewDTO, reviewId, isActiveReview, tenantId)) { + if (!isActiveReview) { + if (addReview(updatingReview, uuid, true)) { + return true; + } else { + if (updateReviewInDB(reviewDTO, reviewId, true, tenantId)) { + return false; + } else { + String msg = "Review Updating Status: Adding new Review for application release which has UUID: " + + "" + uuid + " is failed and the old review restoring is also failed."; + log.error(msg); + throw new ApplicationManagementException(msg); + } + } + } + return true; + } else { + String msg = "Review Updating is failed. Hence please contact the administrator."; + log.error(msg); + throw new ApplicationManagementException(msg); + } } - private boolean updateReviewInDB(ReviewDTO reviewDTO, String uuid, int reviewId, boolean isActiveReview, + private boolean updateReviewInDB(ReviewDTO reviewDTO, 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(); return true; }