Improve review management functionalities

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent ba0dec38fa
commit 4692eb5f92

@ -18,16 +18,17 @@
*/ */
package org.wso2.carbon.device.application.mgt.common.services; package org.wso2.carbon.device.application.mgt.common.services;
import javassist.NotFoundException;
import org.wso2.carbon.device.application.mgt.common.Rating; import org.wso2.carbon.device.application.mgt.common.Rating;
import org.wso2.carbon.device.application.mgt.common.Review; import org.wso2.carbon.device.application.mgt.common.Review;
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.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException; import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewDoesNotExistException; import org.wso2.carbon.device.application.mgt.common.exception.ReviewDoesNotExistException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException;
/** /**
* ReviewManager is responsible for handling all the add/update/delete/get operations related with * ReviewManager is responsible for handling all the add/update/delete/get operations related with
*/ */
@ -41,7 +42,8 @@ public interface ReviewManager {
* @return {@link Review} Review added * @return {@link Review} Review added
* @throws ReviewManagementException Exceptions of the review management. * @throws ReviewManagementException Exceptions of the review management.
*/ */
boolean addReview(Review review, String uuid) throws ReviewManagementException, RequestValidatingException; boolean addReview(Review review, String uuid)
throws ReviewManagementException, RequestValidatingException, ApplicationManagementException;
/** /**
* Get all review with pagination * Get all review with pagination

@ -139,4 +139,13 @@ public interface ApplicationReleaseDAO {
*/ */
boolean verifyReleaseExistence(int appId, String uuid, int tenantId) throws ApplicationManagementDAOException; boolean verifyReleaseExistence(int appId, String uuid, int tenantId) throws ApplicationManagementDAOException;
/**
* To verify whether application release exist or not for given application release uuid.
*
* @param uuid UUID of the application release.
* @param tenantId Tenant Id
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
boolean verifyReleaseExistenceByUuid(String uuid, int tenantId) throws ApplicationManagementDAOException;
} }

@ -55,7 +55,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
} }
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet rs = null; ResultSet rs = null;
sql = "INSERT INTO AP_APP_REVIEW (TENANT_ID, COMMENT, PARENT_ID, USERNAME,CREATED_AT, MODIFIES_AT," sql = "INSERT INTO AP_APP_REVIEW (TENANT_ID, COMMENT, PARENT_ID, USERNAME,CREATED_AT, MODIFIED_AT,"
+ " AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?,?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?)," + " AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?,?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?),"
+ "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));"; + "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));";
try { try {
@ -99,7 +99,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet rs = null; ResultSet rs = null;
Review review = null; Review review = null;
sql = "SELECT ID, COMMENT, CREATED_AT, MODEFIED_AT, USERNAME, PARENT_ID, RATING FROM AP_APP_REVIEW WHERE " sql = "SELECT ID, COMMENT, CREATED_AT, MODIFIED_AT, USERNAME, PARENT_ID, RATING FROM AP_APP_REVIEW WHERE "
+ "AP_APP_RELEASE_ID = (SELECT ID FROM AP_APP_RELEASE WHERE UUID=?) AND USERNAME = ? AND TENANT_ID = ?;"; + "AP_APP_RELEASE_ID = (SELECT ID FROM AP_APP_RELEASE WHERE UUID=?) AND USERNAME = ? AND TENANT_ID = ?;";
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
@ -217,9 +217,10 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql = "SELECT AP_APP_REVIEW.ID AS ID, AP_APP_REVIEW.COMMENT AS COMMENT, " sql = "SELECT AP_APP_REVIEW.ID AS ID, AP_APP_REVIEW.COMMENT AS COMMENT, "
+ "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, " + "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, "
+ "AP_APP_REVIEW.USERNAME AS USERNAME, AP_APP_REVIEW.PARENT_ID AS PARENT_ID " + "AP_APP_REVIEW.USERNAME AS USERNAME, AP_APP_REVIEW.PARENT_ID AS PARENT_ID, "
+ "FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND " + "AP_APP_REVIEW.RATING AS RATING FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE "
+ "AP_APP_RELEASE.UUID =? AND AP_APP_REVIEW.TENANT_ID = ? AND " + "AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_RELEASE.UUID =? "
+ "AND AP_APP_REVIEW.TENANT_ID = ? AND "
+ "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID LIMIT ? OFFSET ?;"; + "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID LIMIT ? OFFSET ?;";
statement = conn.prepareStatement(sql); statement = conn.prepareStatement(sql);
statement.setString(1, uuid); statement.setString(1, uuid);
@ -235,6 +236,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
review.setModifiedAt(rs.getTimestamp("MODIFIED_AT")); review.setModifiedAt(rs.getTimestamp("MODIFIED_AT"));
review.setParentId(rs.getInt("PARENT_ID")); review.setParentId(rs.getInt("PARENT_ID"));
review.setUsername(rs.getString("USERNAME")); review.setUsername(rs.getString("USERNAME"));
review.setRating(rs.getInt("RATING"));
reviews.add(review); reviews.add(review);
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {

@ -327,7 +327,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
Rating rating = null; Rating rating = null;
String sql = "SELECT RATING, RATED_USERS FROM AP_APP_RELEASE WHERE UUID = ? AND TENANT_D=?;"; String sql = "SELECT RATING, RATED_USERS FROM AP_APP_RELEASE WHERE UUID = ? AND TENANT_ID=?;";
try { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
@ -466,6 +466,40 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} }
} }
@Override
public boolean verifyReleaseExistenceByUuid(String uuid, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Verifying application release existence by application release uuid: " + uuid);
}
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = this.getDBConnection();
String sql =
"SELECT AR.ID AS RELEASE_ID FROM AP_APP_RELEASE AS AR WHERE AR.UUID = ? AND AR.TENANT_ID = ?;";
stmt = conn.prepareStatement(sql);
stmt.setString(1, uuid);
stmt.setInt(2, tenantId);
rs = stmt.executeQuery();
if (log.isDebugEnabled()) {
log.debug("Successfully retrieved basic details of the application release with the application UUID: "
+ uuid);
}
return rs.next();
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error occurred when executing query to get application release details for App release uuid: "
+ uuid, e);
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
/** /**
* This method is capable to construct {@link ApplicationRelease} and return the object * This method is capable to construct {@link ApplicationRelease} and return the object
* *

@ -25,7 +25,6 @@ import org.wso2.carbon.device.application.mgt.common.Rating;
import org.wso2.carbon.device.application.mgt.common.Review; import org.wso2.carbon.device.application.mgt.common.Review;
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.exception.RequestValidatingException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewDoesNotExistException; import org.wso2.carbon.device.application.mgt.common.exception.ReviewDoesNotExistException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
@ -35,6 +34,7 @@ import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
import org.wso2.carbon.device.application.mgt.core.dao.ReviewDAO; import org.wso2.carbon.device.application.mgt.core.dao.ReviewDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
@ -64,23 +64,27 @@ public class ReviewManagerImpl implements ReviewManager {
this.applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO(); this.applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO();
} }
@Override public boolean addReview(Review review, String uuid) @Override
throws ReviewManagementException, RequestValidatingException { public boolean addReview(Review review, String uuid) throws ReviewManagementException, NotFoundException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
boolean isSuccess = false; boolean isSuccess = false;
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
Review existingReview = reviewDAO.haveUerCommented(uuid, username, tenantId); if (!this.applicationReleaseDAO.verifyReleaseExistenceByUuid(uuid, tenantId)){
throw new NotFoundException("Couldn't find application release for the application UUID: " + uuid);
}
Review existingReview = this.reviewDAO.haveUerCommented(uuid, username, tenantId);
if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId) if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId)
&& review.getRating() > 0 && review.getRating() != existingReview.getRating()) { && review.getRating() > 0 && review.getRating() != existingReview.getRating()) {
Runnable task = () -> calculateRating(review.getRating(), existingReview.getRating(), uuid); Runnable task = () -> calculateRating(review.getRating(), existingReview.getRating(), uuid, tenantId);
new Thread(task).start(); new Thread(task).start();
isSuccess = updateReview(review, existingReview.getId(), uuid, existingReview); isSuccess = updateReview(review, existingReview.getId(), uuid, existingReview);
} else if (review.getRating() > 0) { } else if (review.getRating() > 0) {
Runnable task = () -> calculateRating(review.getRating(), -12345, uuid); Runnable task = () -> calculateRating(review.getRating(), -12345, uuid, tenantId);
new Thread(task).start(); new Thread(task).start();
review.setUsername(username); review.setUsername(username);
try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
isSuccess = this.reviewDAO.addReview(review, uuid, tenantId); isSuccess = this.reviewDAO.addReview(review, uuid, tenantId);
if (isSuccess) { if (isSuccess) {
@ -88,20 +92,23 @@ public class ReviewManagerImpl implements ReviewManager {
} else { } else {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
} }
} catch (TransactionManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw new ReviewManagementException(
"Transaction Management Exception occurs,Review for application release with UUID:" + uuid
+ " is failed ", e);
}
} }
return isSuccess; return isSuccess;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw new ReviewManagementException( throw new ReviewManagementException(
"DB Connection error occurs ,Review for application release with UUID: " + uuid + " 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 release with UUID:" + uuid +
" is failed ", e);
} catch (UserStoreException e) { } catch (UserStoreException e) {
throw new ReviewManagementException("Error occured while verifying user's permission to update the review.", throw new ReviewManagementException("Error occured while verifying user's permission to update the review.",
e); e);
} catch (ApplicationManagementDAOException e) {
throw new ReviewManagementException(
"Error occured while verifying whether application release is exists or not.", e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -112,18 +119,20 @@ public class ReviewManagerImpl implements ReviewManager {
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();
boolean isConnectionOpen = false;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Review updating request is received for the review id " + reviewId); log.debug("Review updating request is received for the review id " + reviewId);
} }
try { try {
if (existingReview == null) { if (existingReview == null) {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
isConnectionOpen = true;
existingReview = this.reviewDAO.getReview(reviewId); existingReview = this.reviewDAO.getReview(reviewId);
if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId)) { if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId)) {
if (review.getRating() > 0 && review.getRating() != existingReview.getRating()) { if (review.getRating() > 0 && review.getRating() != existingReview.getRating()) {
Review finalExistingReview = existingReview; Review finalExistingReview = existingReview;
Runnable task = () -> calculateRating(review.getRating(), finalExistingReview.getRating(), Runnable task = () -> calculateRating(review.getRating(), finalExistingReview.getRating(),
uuid); uuid, tenantId);
new Thread(task).start(); new Thread(task).start();
} }
} else { } else {
@ -138,6 +147,7 @@ public class ReviewManagerImpl implements ReviewManager {
if (review.getRating() == 0) { if (review.getRating() == 0) {
review.setRating(existingReview.getRating()); review.setRating(existingReview.getRating());
} }
try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
if (this.reviewDAO.updateReview(review, reviewId, username, tenantId) == 1) { if (this.reviewDAO.updateReview(review, reviewId, username, tenantId) == 1) {
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
@ -145,23 +155,32 @@ public class ReviewManagerImpl implements ReviewManager {
} }
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
return false; return false;
} catch (TransactionManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw new ReviewManagementException(
"Transaction management error occurs when updating review with review id " + reviewId + ".", e);
} catch (ReviewManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw new ReviewManagementException(
"Error occured while updating review with review id " + reviewId + ".", e);
}
} catch (ReviewManagementDAOException e) { } catch (ReviewManagementDAOException e) {
throw new ReviewManagementException("Error occured while updating review with review id " + reviewId + ".", throw new ReviewManagementException("Error occured while getting review with review id " + reviewId + ".",
e); e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ReviewManagementException( throw new ReviewManagementException(
"DB Connection error occurs updating review with review id " + reviewId + ".", e); "DB Connection error occurs updating review with review id " + reviewId + ".", e);
} catch (TransactionManagementException e) {
throw new ReviewManagementException(
"Transaction management error occurs when updating review with review id " + reviewId + ".", e);
} catch (UserStoreException e) { } catch (UserStoreException e) {
throw new ReviewManagementException( throw new ReviewManagementException(
"Error occured while verifying user's permission to update the review. review id: " + reviewId "Error occured while verifying user's permission to update the review. review id: " + reviewId
+ ".", e); + ".", e);
} finally { } finally {
if (isConnectionOpen) {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
} }
}
@Override @Override
public PaginationResult getAllReviews(PaginationRequest request, String uuid) public PaginationResult getAllReviews(PaginationRequest request, String uuid)
@ -221,7 +240,7 @@ public class ReviewManagerImpl implements ReviewManager {
throw new ReviewDoesNotExistException( throw new ReviewDoesNotExistException(
"Cannot delete a non-existing review for the application with review id" + reviewId); "Cannot delete a non-existing review for the application with review id" + reviewId);
} }
Runnable task = () -> calculateRating(0, existingReview.getRating(), uuid); Runnable task = () -> calculateRating(0, existingReview.getRating(), uuid, tenantId);
new Thread(task).start(); new Thread(task).start();
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
if (isAuthorizedUser(username, existingReview.getUsername(), tenantId) if (isAuthorizedUser(username, existingReview.getUsername(), tenantId)
@ -290,10 +309,9 @@ public class ReviewManagerImpl implements ReviewManager {
} }
} }
private void calculateRating(int newRatingVal, int oldRatingVal, String uuid) { private void calculateRating(int newRatingVal, int oldRatingVal, String uuid, int tenantId) {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.openDBConnection();
Rating rating = this.applicationReleaseDAO.getRating(uuid, tenantId); Rating rating = this.applicationReleaseDAO.getRating(uuid, tenantId);
if (rating == null) { if (rating == null) {
log.error("Couldn't find rating for application release uuid: " + uuid); log.error("Couldn't find rating for application release uuid: " + uuid);
@ -302,31 +320,36 @@ public class ReviewManagerImpl implements ReviewManager {
int numOfUsers = rating.getNoOfUsers(); int numOfUsers = rating.getNoOfUsers();
double currentRating = rating.getRatingValue() * numOfUsers; double currentRating = rating.getRatingValue() * numOfUsers;
if (oldRatingVal == -12345) { if (oldRatingVal == -12345) {
updatedRating = (currentRating + newRatingVal) / (numOfUsers + 1); numOfUsers++;
this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers + 1); updatedRating = (currentRating + newRatingVal) / numOfUsers;
} else if (newRatingVal == 0) { } else if (newRatingVal == 0) {
updatedRating = (currentRating - newRatingVal) / (numOfUsers - 1); numOfUsers--;
this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers - 1); updatedRating = (currentRating - newRatingVal) / numOfUsers;
} else { } else {
double tmpVal; double tmpVal;
tmpVal = currentRating - oldRatingVal; tmpVal = currentRating - oldRatingVal;
updatedRating = (tmpVal + newRatingVal) / numOfUsers; updatedRating = (tmpVal + newRatingVal) / numOfUsers;
this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers);
}
} }
try {
ConnectionManagerUtil.beginDBTransaction();
this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
log.error("Error occured while updated the rating value of the application release UUID: " + uuid);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
log.error( log.error(
"Transaction Management Exception occured while updated the rating value of the application release UUID: " "Transaction Management Exception occured while updated the rating value of the application release UUID: "
+ uuid); + uuid, e);
} catch (DBConnectionException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
log.error("Error occured while updated the rating value of the application release UUID: " + uuid,
e);
}
}
} catch (ApplicationManagementDAOException e) {
log.error("Error occured while getting the rating value of the application release UUID: " + uuid, e);
} catch (DBConnectionException e) {
log.error("DB Connection error occured while updated the rating value of the application release UUID: " log.error("DB Connection error occured while updated the rating value of the application release UUID: "
+ uuid + " can not get."); + uuid + " can not get.", e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }

@ -29,6 +29,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.RequestValidating
import org.wso2.carbon.device.application.mgt.common.exception.ReviewDoesNotExistException; import org.wso2.carbon.device.application.mgt.common.exception.ReviewDoesNotExistException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.ReviewManager; import org.wso2.carbon.device.application.mgt.common.services.ReviewManager;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.store.api.APIUtil; import org.wso2.carbon.device.application.mgt.store.api.APIUtil;
import org.wso2.carbon.device.application.mgt.store.api.services.ReviewManagementAPI; import org.wso2.carbon.device.application.mgt.store.api.services.ReviewManagementAPI;
import org.wso2.carbon.device.application.mgt.common.PaginationRequest; import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
@ -81,18 +82,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
@ApiParam Review review, @ApiParam Review review,
@PathParam("uuid") String uuid) { @PathParam("uuid") String uuid) {
ReviewManager reviewManager = APIUtil.getReviewManager(); ReviewManager reviewManager = APIUtil.getReviewManager();
ApplicationManager applicationManager = APIUtil.getApplicationManager();
Application application;
try { try {
application = applicationManager.getApplicationByRelease(uuid);
if (application.getApplicationReleases().isEmpty()){
String msg = "Couldn't Found an one application release for the UUID: " + uuid;
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
if (application.getApplicationReleases().size()>1){
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, uuid); boolean isReviewCreated = reviewManager.addReview(review, uuid);
if (isReviewCreated) { if (isReviewCreated) {
return Response.status(Response.Status.CREATED).entity(review).build(); return Response.status(Response.Status.CREATED).entity(review).build();
@ -101,18 +91,23 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
log.error(msg); log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} }
} catch (NotFoundException e) {
String msg = "Couldn't find an application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ReviewManagementException e) { } catch (ReviewManagementException e) {
String msg = "Error occurred while creating the review"; String msg = "Error occurred while creating the review";
log.error(msg, e); 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();
} catch (ApplicationManagementException e) {
log.error("Error occured while getting the application for application UUID: " + uuid);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("").build();
} catch (RequestValidatingException e) { } catch (RequestValidatingException e) {
String msg = "Error occurred while adding for application release. UUID of the application release: " + uuid; String msg =
"Error occurred while adding for application release. UUID of the application release: " + uuid;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occured while accessing application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
} }

Loading…
Cancel
Save