mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Improve review management
This commit is contained in:
parent
56048907e6
commit
3e16ec96b9
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common.exception;
|
||||
|
||||
public class ReviewDoesNotExistException extends Exception {
|
||||
private String message;
|
||||
|
||||
public ReviewDoesNotExistException(String message, Throwable throwable) {
|
||||
super(message, throwable);
|
||||
setMessage(message);
|
||||
}
|
||||
|
||||
public ReviewDoesNotExistException(String message) {
|
||||
super(message);
|
||||
setMessage(message);
|
||||
}
|
||||
|
||||
public ReviewDoesNotExistException() {
|
||||
|
||||
}
|
||||
|
||||
@Override public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@ -22,25 +22,29 @@ 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.PaginationRequest;
|
||||
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.ReviewManagementException;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* ReviewManager is responsible for handling all the add/update/delete/get operations related with
|
||||
*/
|
||||
public interface ReviewManager {
|
||||
|
||||
/**
|
||||
* To add a review to a application
|
||||
* To add a review to an application release
|
||||
*
|
||||
* @param review review of the application.
|
||||
* @param uuid uuid of the application release.
|
||||
* @return {@link Review} Review added
|
||||
* @throws ReviewManagementException Exceptions of the review management.
|
||||
*/
|
||||
boolean addReview(Review review, String uuid) throws ReviewManagementException;
|
||||
boolean addReview(Review review, String uuid) throws ReviewManagementException, RequestValidatingException;
|
||||
|
||||
/**
|
||||
* Get all comments to pagination
|
||||
* Get all review with pagination
|
||||
*
|
||||
* @param request Pagination request {@link PaginationRequest}
|
||||
* @param uuid uuid of the application release
|
||||
@ -49,15 +53,6 @@ public interface ReviewManager {
|
||||
*/
|
||||
PaginationResult getAllReviews(PaginationRequest request, String uuid) throws ReviewManagementException;
|
||||
|
||||
/**
|
||||
* To get the comment with id.
|
||||
*
|
||||
* @param commentId id of the comment
|
||||
* @return {@link Review}Review of the comment id
|
||||
* @throws ReviewManagementException Exceptions of the comment management.
|
||||
*/
|
||||
Review getReview(int commentId) throws ReviewManagementException;
|
||||
|
||||
/**
|
||||
* To delete review using review id.
|
||||
*
|
||||
@ -66,7 +61,8 @@ public interface ReviewManager {
|
||||
* @return If review is successfully deleted return true, otherwise returns false
|
||||
* @throws ReviewManagementException Exceptions of the comment management
|
||||
*/
|
||||
boolean deleteReview(String uuid, int commentId) throws ReviewManagementException;
|
||||
boolean deleteReview(String uuid, int commentId)
|
||||
throws ReviewManagementException, ReviewDoesNotExistException;
|
||||
|
||||
/**
|
||||
* To update a review.
|
||||
@ -74,12 +70,13 @@ public interface ReviewManager {
|
||||
* @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
|
||||
* @param existingReview Pass existing review when same user adding a review for same application release,
|
||||
* otherwise pass null
|
||||
* @return {@link Review}updated review
|
||||
* @throws ReviewManagementException Exceptions of the review management
|
||||
*/
|
||||
boolean updateReview(Review review, int reviewId, String uuid, boolean checkExistence)
|
||||
throws ReviewManagementException;
|
||||
boolean updateReview(Review review, int reviewId, String uuid, Review existingReview)
|
||||
throws ReviewManagementException, RequestValidatingException;
|
||||
|
||||
/**
|
||||
* To get the overall rating for a application release
|
||||
|
||||
@ -81,19 +81,21 @@ public interface ApplicationReleaseDAO {
|
||||
|
||||
/**
|
||||
* To update an Application release.
|
||||
* @param id id of the ApplicationRelease that need to be updated.
|
||||
* @param uuid UUID of the ApplicationRelease that need to be updated.
|
||||
* @param rating given stars for the application.
|
||||
* @param ratedUsers number of users who has rated for the application release.
|
||||
* @throws ApplicationManagementDAOException Application Management DAO Exception
|
||||
*/
|
||||
int updateRatingValue(int id, double rating, int ratedUsers) throws ApplicationManagementDAOException;
|
||||
void updateRatingValue(String uuid, double rating, int ratedUsers) throws ApplicationManagementDAOException;
|
||||
|
||||
/**
|
||||
* To retrieve rating of an application release.
|
||||
*
|
||||
* @param uuid UUID of the application Release.
|
||||
* @param tenantId Tenant Id
|
||||
* @throws ApplicationManagementDAOException Application Management DAO Exception.
|
||||
*/
|
||||
Rating getRating(String uuid) throws ApplicationManagementDAOException;
|
||||
Rating getRating(String uuid, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -45,7 +45,7 @@ import java.util.List;
|
||||
boolean addReview(Review review, String uuid, int tenantId) throws ReviewManagementDAOException;
|
||||
|
||||
/**
|
||||
* To verify whether review is exists or not.
|
||||
* To verify whether user has already commented for the application release or not.
|
||||
*
|
||||
* @param uuid UUID of the application release.
|
||||
* @param username username of the logged in user.
|
||||
@ -58,33 +58,33 @@ import java.util.List;
|
||||
/**
|
||||
* To update already added comment.
|
||||
*
|
||||
* @return {@link Review}Updated comment
|
||||
* @throws ReviewManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception
|
||||
* @throws SQLException sql exception
|
||||
* @param review Updating review
|
||||
* @param reviewId id of the updating review
|
||||
* @param username review owner
|
||||
* @param tenantId tenant id
|
||||
* @return row count if updating is succeed otherwise 0
|
||||
* @throws ReviewManagementDAOException Exceptions of the review management.
|
||||
*/
|
||||
boolean updateReview(Review review, int reviewId, int tenantId)
|
||||
throws ReviewManagementException, DBConnectionException, SQLException;
|
||||
int updateReview(Review review, int reviewId, String username, int tenantId)
|
||||
throws ReviewManagementDAOException;
|
||||
|
||||
|
||||
/**
|
||||
* To get the comment with id.
|
||||
*
|
||||
* @param commentId id of the comment
|
||||
* @param reviewId id of the review
|
||||
* @return {@link Review}Review
|
||||
* @throws ReviewManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception
|
||||
* @throws SQLException sql exception
|
||||
* @throws ReviewManagementDAOException Exceptions of the review management DAO.
|
||||
*/
|
||||
Review getReview(int commentId) throws ReviewManagementException, SQLException, DBConnectionException;
|
||||
Review getReview(int reviewId) throws ReviewManagementDAOException;
|
||||
|
||||
/**
|
||||
* To get all the comments
|
||||
* To get all reviews
|
||||
*
|
||||
* @param uuid uuid of the application
|
||||
* @param request {@link PaginationRequest}pagination request with offSet and limit
|
||||
* @param tenantId Tenant id
|
||||
* @return {@link List}List of all the comments in an application
|
||||
* @return {@link List}List of all reviews for the application release
|
||||
* @throws ReviewManagementDAOException Review management DAO exception
|
||||
**/
|
||||
List<Review> getAllReviews(String uuid, PaginationRequest request, int tenantId)
|
||||
@ -92,11 +92,12 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* To get list of comments using release id and application id.
|
||||
*
|
||||
* @param uuid UUID of the application release
|
||||
* @param tenantId tenant id
|
||||
* @return {@link List}List of comments
|
||||
* @throws ReviewManagementException Exceptions of the comment management.
|
||||
* @throws ReviewManagementDAOException Exceptions of the review management DAO.
|
||||
*/
|
||||
List<Integer> getAllRatingValues(String uuid)throws SQLException, DBConnectionException;
|
||||
List<Integer> getAllRatingValues(String uuid, int tenantId) throws ReviewManagementDAOException;
|
||||
|
||||
/**
|
||||
* To get count of comments by application details.
|
||||
@ -122,15 +123,6 @@ import java.util.List;
|
||||
*/
|
||||
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.
|
||||
*
|
||||
@ -142,12 +134,11 @@ import java.util.List;
|
||||
void deleteReviews(String appType, String appName, String version) throws ReviewManagementException;
|
||||
|
||||
/**
|
||||
* To get comment count for pagination
|
||||
* To get review count for a specific application release
|
||||
*
|
||||
* @param request pagination request
|
||||
* @param uuid uuid of the application release
|
||||
* @return Review count
|
||||
* @throws ReviewManagementException
|
||||
* @throws ReviewManagementDAOException Review management DAO exception
|
||||
*/
|
||||
int getReviewCount(PaginationRequest request, String uuid) throws ReviewManagementException;
|
||||
int getReviewCount(String uuid) throws ReviewManagementDAOException;
|
||||
}
|
||||
@ -23,7 +23,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.UnsupportedDatabaseEngineException;
|
||||
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.*;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.impl.Comment.ReviewDAOImpl;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.impl.Review.ReviewDAOImpl;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.GenericApplicationReleaseDAOImpl;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.OracleApplicationDAOImpl;
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.core.dao.impl.Comment;
|
||||
package org.wso2.carbon.device.application.mgt.core.dao.impl.Review;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@ -28,7 +28,6 @@ import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionExcep
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.ReviewDAO;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAOException;
|
||||
|
||||
import java.sql.SQLException;
|
||||
@ -48,14 +47,13 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
private String sql;
|
||||
|
||||
@Override
|
||||
public boolean addReview(Review review, String uuid, int tenantId)
|
||||
throws ReviewManagementDAOException {
|
||||
public boolean addReview(Review review, String uuid, int tenantId) throws ReviewManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to add review for application release. Application UUID: " + uuid);
|
||||
}
|
||||
PreparedStatement statement = null;
|
||||
ResultSet rs = null;
|
||||
sql = "INSERT INTO AP_APP_Review (TENANT_ID, COMMENT, PARENT_ID, USERNAME, AP_APP_RELEASE_ID, AP_APP_ID) "
|
||||
sql = "INSERT INTO AP_APP_REVIEW (TENANT_ID, COMMENT, PARENT_ID, USERNAME, 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=?));";
|
||||
try {
|
||||
@ -102,7 +100,6 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
statement.setString(1, uuid);
|
||||
statement.setString(2, username);
|
||||
statement.setInt(3, tenantId);
|
||||
|
||||
rs = statement.executeQuery();
|
||||
if (rs.next()){
|
||||
review = new Review();
|
||||
@ -128,7 +125,8 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateReview(Review review, int reviewId, int tenantId) throws ReviewManagementException, DBConnectionException, SQLException {
|
||||
public int updateReview(Review review, int reviewId, String username, int tenantId)
|
||||
throws ReviewManagementDAOException {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to update the comment with ID (" + reviewId + ")");
|
||||
@ -136,55 +134,59 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
Connection connection;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet rs = null;
|
||||
sql = "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?, MODEFIED_BY=? WHERE ID=?;";
|
||||
sql = "UPDATE AP_APP_REVIEW SET COMMENT=?, RATING=? WHERE ID=? AND USERNAME=? AND TENANT_ID=?;";
|
||||
try {
|
||||
connection = this.getDBConnection();
|
||||
statement = connection.prepareStatement(sql);
|
||||
// statement.setString(1, updatedComment);
|
||||
// statement.setString(2, modifiedBy);
|
||||
statement.setString(1, review.getComment());
|
||||
statement.setInt(2, review.getRating());
|
||||
statement.setInt(3, reviewId);
|
||||
statement.executeUpdate();
|
||||
rs = statement.executeQuery();
|
||||
statement.setString(4, username);
|
||||
statement.setInt(5, tenantId);
|
||||
return statement.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new ReviewManagementDAOException("Error occurred while executing review updating query");
|
||||
} catch (DBConnectionException e) {
|
||||
throw new ReviewManagementDAOException("Error occured while getting the db connection to update review");
|
||||
} finally {
|
||||
Util.cleanupResources(statement, rs);
|
||||
}
|
||||
// todo
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Review getReview(int commentId) throws ReviewManagementException {
|
||||
public Review getReview(int reviewId) throws ReviewManagementDAOException {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Getting review with the review id(" + commentId + ") from the database");
|
||||
log.debug("Getting review with the review id(" + reviewId + ") from the database");
|
||||
}
|
||||
Connection conn;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet rs;
|
||||
ResultSet rs = null;
|
||||
Review review = new Review();
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
sql = "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE ID=?;";
|
||||
sql = "SELECT ID, COMMENT, CREATED_AT, MODIFIED_AT, RATING, USERNAME FROM AP_APP_REVIEWE WHERE ID=?;";
|
||||
statement = conn.prepareStatement(sql);
|
||||
statement.setInt(1, commentId);
|
||||
statement.setInt(1, reviewId);
|
||||
rs = statement.executeQuery();
|
||||
if (rs.next()) {
|
||||
review.setId(rs.getInt("ID"));
|
||||
// review.setTenantId(rs.getInt("TENANT_ID"));
|
||||
review.setComment(rs.getString("COMMENT_TEXT"));
|
||||
review.setComment(rs.getString("COMMENT"));
|
||||
review.setCreatedAt(rs.getTimestamp("CREATED_AT"));
|
||||
review.setUsername(rs.getString("CREATED_BY"));
|
||||
review.setModifiedAt(rs.getTimestamp("MODEFIED_AT"));
|
||||
Util.cleanupResources(statement, rs);
|
||||
review.setModifiedAt(rs.getTimestamp("MODIFIED_AT"));
|
||||
review.setRating(rs.getInt("RATING"));
|
||||
review.setUsername(rs.getString("USERNAME"));
|
||||
return review;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new ReviewManagementException(
|
||||
"SQL Error occurred while retrieving information of the review " + commentId, e);
|
||||
throw new ReviewManagementDAOException(
|
||||
"SQL Error occurred while retrieving information of the review " + reviewId, e);
|
||||
} catch (DBConnectionException e) {
|
||||
log.error("DB Connection Exception occurred while retrieving information of the review " + commentId, e);
|
||||
throw new ReviewManagementDAOException(
|
||||
"DB Connection Exception occurred while retrieving information of the review " + reviewId, e);
|
||||
} finally {
|
||||
Util.cleanupResources(statement, null);
|
||||
Util.cleanupResources(statement, rs);
|
||||
}
|
||||
return review;
|
||||
}
|
||||
@ -202,11 +204,11 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
List<Review> reviews = new ArrayList<>();
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
sql = "SELECT AP_APP_COMMENT.ID AS ID, AP_APP_COMMENT.COMMENT_TEXT AS COMMENT_TEXT, "
|
||||
+ "AP_APP_COMMENT.CREATED_BY AS CREATED_BY, AP_APP_COMMENT.MODIFIED_BY AS MODIFIED_BY, "
|
||||
+ "AP_APP_COMMENT.PARENT_ID AS PARENT_ID FROM AP_APP_COMMENT, AP_APP_RELEASE WHERE "
|
||||
+ "AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_RELEASE.UUID =? AND "
|
||||
+ "AP_APP_COMMENT.TENANT_ID = ? AND AP_APP_COMMENT.TENANT_ID = AP_APP_RELEASE.TENANT_ID "
|
||||
sql = "SELECT AP_APP_REVIEW.ID AS ID, AP_APP_REVIEW.COMMENT AS COMMENT, "
|
||||
+ "AP_APP_REVIEW.CREATED_BY AS CREATED_BY, AP_APP_REVIEW.MODIFIED_BY AS MODIFIED_BY, "
|
||||
+ "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_RELEASE.UUID =? AND "
|
||||
+ "AP_APP_REVIEW.TENANT_ID = ? AND AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID "
|
||||
+ "LIMIT ? OFFSET ?;";
|
||||
statement = conn.prepareStatement(sql);
|
||||
statement.setString(1, uuid);
|
||||
@ -233,7 +235,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getAllRatingValues(String uuid)throws SQLException, DBConnectionException {
|
||||
public List<Integer> getAllRatingValues(String uuid, int tenantId) throws ReviewManagementDAOException {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Getting comment of the application release (" + uuid + ") from the database");
|
||||
@ -244,18 +246,24 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
List<Integer> reviews = new ArrayList<>();
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
// todo
|
||||
sql = "SELECT AP_APP_COMMENT.ID AS ID, AP_APP_COMMENT.COMMENT_TEXT AS "
|
||||
+ "COMMENT_TEXT, AP_APP_COMMENT.CREATED_BY AS CREATED_BY, AP_APP_COMMENT.MODIFIED_BY AS "
|
||||
+ "MODIFIED_BY, AP_APP_COMMENT.PARENT_ID AS PARENT_ID FROM AP_APP_COMMENT, AP_APP_RELEASE WHERE "
|
||||
+ "AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_RELEASE.UUID =? AND "
|
||||
+ "AP_APP_COMMENT.TENANT_ID = ? AND AP_APP_COMMENT.TENANT_ID = AP_APP_RELEASE.TENANT_ID;";
|
||||
sql = "SELECT AP_APP_COMMENT.RATING AS RATING FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE "
|
||||
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_RELEASE.UUID =? AND "
|
||||
+ "AP_APP_COMMENT.TENANT_ID = AP_APP_RELEASE.TENANT_ID AND AP_APP_COMMENT.TENANT_ID = ?;";
|
||||
statement = conn.prepareStatement(sql);
|
||||
statement.setString(1, uuid);
|
||||
statement.setInt(2, tenantId);
|
||||
rs = statement.executeQuery();
|
||||
while (rs.next()) {
|
||||
reviews.add(rs.getInt("RATING"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new ReviewManagementDAOException(
|
||||
"Error occured while getting all rating values for the application release. App release UUID: "
|
||||
+ uuid, e);
|
||||
} catch (DBConnectionException e) {
|
||||
throw new ReviewManagementDAOException(
|
||||
"Error occured while getting DB connection to retrieve all rating values for the application release. App release UUID: "
|
||||
+ uuid, e);
|
||||
} finally {
|
||||
Util.cleanupResources(statement, rs);
|
||||
}
|
||||
@ -263,7 +271,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getReviewCount(PaginationRequest request, String uuid) throws ReviewManagementException {
|
||||
public int getReviewCount(String uuid) throws ReviewManagementDAOException {
|
||||
|
||||
int commentCount = 0;
|
||||
Connection conn;
|
||||
@ -276,20 +284,20 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
isUuidProvided = true;
|
||||
}
|
||||
if (isUuidProvided) {
|
||||
sql = "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE "
|
||||
+ "WHERE AP_APP_COMMENT.AP_APP_RELEASE_ID= AP_APP_RELEASE.ID AND "
|
||||
+ "AP_APP_COMMENT.AP_APP_ID= AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;";
|
||||
sql = "SELECT COUNT(AP_APP_REVIEW.ID) AS REVIEW_COUNT FROM AP_APP_REVIEW,AP_APP_RELEASE "
|
||||
+ "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID= AP_APP_RELEASE.ID AND "
|
||||
+ "AP_APP_REVIEW.AP_APP_ID= AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;";
|
||||
statement = conn.prepareStatement(sql);
|
||||
statement.setString(1, uuid);
|
||||
rs = statement.executeQuery();
|
||||
if (rs.next()) {
|
||||
commentCount = rs.getInt("COMMENTS_COUNT");
|
||||
commentCount = rs.getInt("REVIEW_COUNT");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new ReviewManagementException("SQL Error occurred while retrieving count of comments", e);
|
||||
throw new ReviewManagementDAOException("SQL Error occurred while retrieving review counts", e);
|
||||
} catch (DBConnectionException e) {
|
||||
log.error("DB Connection Exception occurred while retrieving count of comments", e);
|
||||
throw new ReviewManagementDAOException("DB Connection Exception occurred while retrieving review counts", e);
|
||||
} finally {
|
||||
Util.cleanupResources(statement, rs);
|
||||
}
|
||||
@ -302,8 +310,10 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet rs = null;
|
||||
int commentCount = 0;
|
||||
try {
|
||||
//todo need to reconstruct the query
|
||||
conn = this.getDBConnection();
|
||||
sql = "SELECT COUNT(ID) AS COMMENT_COUNT FROM AP_APP_COMMENT C, "
|
||||
+ "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=? )R,"
|
||||
@ -313,12 +323,12 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
statement.setString(1, version);
|
||||
statement.setString(2, appName);
|
||||
statement.setString(3, appType);
|
||||
ResultSet rs = statement.executeQuery();
|
||||
rs = statement.executeQuery();
|
||||
if (rs.next()) {
|
||||
commentCount = rs.getInt("COMMENT_COUNT");
|
||||
}
|
||||
} finally {
|
||||
Util.cleanupResources(statement, null);
|
||||
Util.cleanupResources(statement, rs);
|
||||
}
|
||||
return commentCount;
|
||||
}
|
||||
@ -345,33 +355,13 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
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 {
|
||||
public void deleteReviews(String appType, String appName, String version) throws ReviewManagementException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
//todo need to reconstruct the query,
|
||||
sql = "DELETE FROM AP_APP_COMMENT WHERE "
|
||||
+ "(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND "
|
||||
+ "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND "
|
||||
@ -279,28 +279,28 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
|
||||
/**
|
||||
* To Update starts of an application release.
|
||||
*
|
||||
* @param id Id of the application Release.
|
||||
* @param uuid UUID of the application Release.
|
||||
* @param rating given stars for the application release.
|
||||
* @throws ApplicationManagementDAOException Application Management DAO Exception.
|
||||
*/
|
||||
@Override
|
||||
public int updateRatingValue(int id, double rating, int ratedUsers) throws ApplicationManagementDAOException {
|
||||
public void updateRatingValue(String uuid, double rating, int ratedUsers) throws ApplicationManagementDAOException {
|
||||
Connection connection;
|
||||
PreparedStatement statement = null;
|
||||
String sql = "UPDATE AP_APP_RELEASE SET RATING = ? AND RATED_USERS = ? WHERE ID = ?;";
|
||||
String sql = "UPDATE AP_APP_RELEASE SET RATING = ? AND RATED_USERS = ? WHERE UUID = ?;";
|
||||
try {
|
||||
connection = this.getDBConnection();
|
||||
statement = connection.prepareStatement(sql);
|
||||
statement.setDouble(1, rating);
|
||||
statement.setInt(2, ratedUsers);
|
||||
statement.setInt(2, id);
|
||||
return statement.executeUpdate();
|
||||
statement.setString(3, uuid);
|
||||
statement.executeUpdate();
|
||||
} catch (DBConnectionException e) {
|
||||
throw new ApplicationManagementDAOException(
|
||||
"Database connection exception while trying to update the application release", e);
|
||||
"Database connection exception while trying to update the application release rating value", e);
|
||||
} catch (SQLException e) {
|
||||
throw new ApplicationManagementDAOException(
|
||||
"SQL exception while updating the release ,while executing the query " + sql, e);
|
||||
"SQL exception while updating the release rating value ,while executing the query " + sql, e);
|
||||
} finally {
|
||||
Util.cleanupResources(statement, null);
|
||||
}
|
||||
@ -313,16 +313,17 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
|
||||
* @throws ApplicationManagementDAOException Application Management DAO Exception.
|
||||
*/
|
||||
@Override
|
||||
public Rating getRating(String uuid) throws ApplicationManagementDAOException {
|
||||
public Rating getRating(String uuid, int tenantId) throws ApplicationManagementDAOException {
|
||||
Connection connection;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet resultSet = null;
|
||||
Rating rating = null;
|
||||
String sql = "SELECT RATING, RATED_USERS FROM AP_APP_RELEASE WHERE UUID = ?;";
|
||||
String sql = "SELECT RATING, RATED_USERS FROM AP_APP_RELEASE WHERE UUID = ? AND TENANT_D=?;";
|
||||
try {
|
||||
connection = this.getDBConnection();
|
||||
statement = connection.prepareStatement(sql);
|
||||
statement.setString(1, uuid);
|
||||
statement.setInt(2, tenantId);
|
||||
resultSet = statement.executeQuery();
|
||||
|
||||
if (resultSet.next()){
|
||||
|
||||
@ -25,6 +25,8 @@ 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.PaginationRequest;
|
||||
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.ReviewManagementException;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.TransactionManagementException;
|
||||
@ -41,7 +43,6 @@ import org.wso2.carbon.user.api.UserRealm;
|
||||
import org.wso2.carbon.user.api.UserStoreException;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
@ -64,35 +65,30 @@ public class ReviewManagerImpl implements ReviewManager {
|
||||
this.applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO();
|
||||
}
|
||||
|
||||
@Override public boolean addReview(Review review, String uuid) throws ReviewManagementException {
|
||||
@Override public boolean addReview(Review review, String uuid)
|
||||
throws ReviewManagementException, RequestValidatingException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
boolean isSuccess;
|
||||
boolean isSuccess = false;
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
Review existingReview = reviewDAO.haveUerCommented(uuid, username, tenantId);
|
||||
if (existingReview != null && review.getRating() > 0 && review.getRating() != existingReview.getRating()) {
|
||||
if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId)
|
||||
&& review.getRating() > 0 && review.getRating() != existingReview.getRating()) {
|
||||
Runnable task = () -> calculateRating(review.getRating(), existingReview.getRating(), uuid);
|
||||
new Thread(task).start();
|
||||
isSuccess = updateReview(review, existingReview.getId(),uuid, false);
|
||||
if (isSuccess) {
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} else {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
}
|
||||
} else {
|
||||
if (review.getRating() > 0) {
|
||||
isSuccess = updateReview(review, existingReview.getId(), uuid, existingReview);
|
||||
} else if (review.getRating() > 0) {
|
||||
Runnable task = () -> calculateRating(review.getRating(), -12345, uuid);
|
||||
new Thread(task).start();
|
||||
}
|
||||
review.setUsername(username);
|
||||
isSuccess = this.reviewDAO.addReview(review, uuid, tenantId);
|
||||
}
|
||||
if (isSuccess) {
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} else {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
}
|
||||
}
|
||||
return isSuccess;
|
||||
} catch (DBConnectionException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
@ -103,49 +99,54 @@ public class ReviewManagerImpl implements ReviewManager {
|
||||
throw new ReviewManagementException(
|
||||
"Transaction Management Exception occurs,Review for application release with UUID:" + uuid +
|
||||
" is failed ", e);
|
||||
} catch (UserStoreException e) {
|
||||
throw new ReviewManagementException("Error occured while verifying user's permission to update the review.",
|
||||
e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateReview(Review review, int reviewId, String uuid, boolean checkExistence)
|
||||
public boolean updateReview(Review review, int reviewId, String uuid, Review existingReview)
|
||||
throws ReviewManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
Review existingReview;
|
||||
boolean isSuccess;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Review updating request is received for the review id " + reviewId);
|
||||
}
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
// todo
|
||||
if (!username.equals(review.getUsername())) {
|
||||
throw new ReviewManagementException(
|
||||
"User " + review.getUsername() + "doesn't match with the logged in user: " + username);
|
||||
}
|
||||
if (checkExistence) {
|
||||
if (existingReview == null) {
|
||||
existingReview = this.reviewDAO.getReview(reviewId);
|
||||
if (existingReview != null) {
|
||||
if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId)) {
|
||||
if (review.getRating() > 0 && review.getRating() != existingReview.getRating()) {
|
||||
Runnable task = () -> calculateRating(review.getRating(), existingReview.getRating(), uuid);
|
||||
Review finalExistingReview = existingReview;
|
||||
Runnable task = () -> calculateRating(review.getRating(), finalExistingReview.getRating(),
|
||||
uuid);
|
||||
new Thread(task).start();
|
||||
}
|
||||
} else {
|
||||
throw new ReviewManagementException("Couldn't find a review for review id: " + reviewId);
|
||||
throw new ReviewManagementException(
|
||||
"Please check the existence of the review, Review-Id: " + reviewId
|
||||
+ " or permission of the " + username + " to update the review.");
|
||||
}
|
||||
}
|
||||
if (review.getComment().isEmpty()) {
|
||||
review.setComment(existingReview.getComment());
|
||||
}
|
||||
if (review.getRating() == 0) {
|
||||
review.setRating(existingReview.getRating());
|
||||
}
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
isSuccess = this.reviewDAO.updateReview(review, reviewId, tenantId);
|
||||
if (isSuccess) {
|
||||
if (this.reviewDAO.updateReview(review, reviewId, username, tenantId) == 1) {
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} else {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
return true;
|
||||
}
|
||||
return isSuccess;
|
||||
} catch (SQLException e) {
|
||||
throw new ReviewManagementException("SQL Error occurs updating review with review id " + reviewId + ".",
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
return false;
|
||||
} catch (ReviewManagementDAOException e) {
|
||||
throw new ReviewManagementException("Error occured while updating review with review id " + reviewId + ".",
|
||||
e);
|
||||
} catch (DBConnectionException e) {
|
||||
throw new ReviewManagementException(
|
||||
@ -153,6 +154,10 @@ public class ReviewManagerImpl implements ReviewManager {
|
||||
} catch (TransactionManagementException e) {
|
||||
throw new ReviewManagementException(
|
||||
"Transaction management error occurs when updating review with review id " + reviewId + ".", e);
|
||||
} catch (UserStoreException e) {
|
||||
throw new ReviewManagementException(
|
||||
"Error occured while verifying user's permission to update the review. review id: " + reviewId
|
||||
+ ".", e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
@ -203,55 +208,28 @@ public class ReviewManagerImpl implements ReviewManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public Review getReview(int commentId) throws ReviewManagementException {
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
Review review;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Review retrieval request is received for the review id " + commentId);
|
||||
}
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
review = this.reviewDAO.getReview(commentId);
|
||||
} catch (DBConnectionException e) {
|
||||
throw new ReviewManagementException(
|
||||
"DB Connection error occurs ,Review with review id " + commentId + "cannot get.", e);
|
||||
} catch (SQLException e) {
|
||||
throw new ReviewManagementException(
|
||||
"SQL Exception occurs,Review with review id " + commentId + "cannot get.", e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
return review;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteReview(String uuid, int reviewId) throws ReviewManagementException {
|
||||
public boolean deleteReview(String uuid, int reviewId)
|
||||
throws ReviewManagementException, ReviewDoesNotExistException {
|
||||
Review existingReview;
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
int isReviewDeleted;
|
||||
try {
|
||||
existingReview = getReview(reviewId);
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
existingReview = this.reviewDAO.getReview(reviewId);
|
||||
if (existingReview == null) {
|
||||
throw new ReviewManagementException(
|
||||
throw new ReviewDoesNotExistException(
|
||||
"Cannot delete a non-existing review for the application with review id" + reviewId);
|
||||
}
|
||||
Runnable task = () -> calculateRating(0, existingReview.getRating(), uuid);
|
||||
new Thread(task).start();
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
if (isAdminUser(username, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
|
||||
isReviewDeleted = this.reviewDAO.deleteReviewByAdmin(reviewId);
|
||||
if (isReviewDeleted == 1) {
|
||||
if (isAuthorizedUser(username, existingReview.getUsername(), tenantId)
|
||||
&& this.reviewDAO.deleteReview(username, reviewId) == 1) {
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
isReviewDeleted = this.reviewDAO.deleteReview(username, reviewId);
|
||||
if (isReviewDeleted == 1) {
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
return false;
|
||||
} catch (DBConnectionException e) {
|
||||
throw new ReviewManagementException(
|
||||
@ -272,17 +250,17 @@ public class ReviewManagerImpl implements ReviewManager {
|
||||
}
|
||||
|
||||
@Override public Rating getRating(String appReleaseUuuid) throws ReviewManagementException {
|
||||
//todo
|
||||
int appReleaseId = 0;
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
Rating rating = this.applicationReleaseDAO.getRating(appReleaseUuuid);
|
||||
Rating rating = this.applicationReleaseDAO.getRating(appReleaseUuuid, tenantId);
|
||||
if (rating == null) {
|
||||
throw new ReviewManagementException("Couldn't find rating for application release id: " + appReleaseId
|
||||
+ ". Please check the existence of the application relese");
|
||||
throw new ReviewManagementException(
|
||||
"Couldn't find rating for application release UUID: " + appReleaseUuuid
|
||||
+ ". Please check the existence of the application release");
|
||||
}
|
||||
|
||||
List<Integer> ratingValues = this.reviewDAO.getAllRatingValues(appReleaseUuuid);
|
||||
List<Integer> ratingValues = this.reviewDAO.getAllRatingValues(appReleaseUuuid, tenantId);
|
||||
TreeMap<Integer, Integer> ratingVariety = rating.getRatingVariety();
|
||||
for (Integer ratingVal : ratingValues) {
|
||||
if (ratingVariety.containsKey(ratingVal)) {
|
||||
@ -296,62 +274,59 @@ public class ReviewManagerImpl implements ReviewManager {
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new ReviewManagementException(
|
||||
"Error occured while updated the rating value of the application release id: " + appReleaseId
|
||||
+ " can not get.", e);
|
||||
"Error occured while getting the rating value of the application release uuid: " + appReleaseUuuid,
|
||||
e);
|
||||
} catch (DBConnectionException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new ReviewManagementException(
|
||||
"DB Connection error occured while updated the rating value of the application release id: "
|
||||
+ appReleaseId + " can not get.", e);
|
||||
} catch (SQLException e) {
|
||||
"DB Connection error occured while getting the rating value of the application release uuid: "
|
||||
+ appReleaseUuuid, e);
|
||||
} catch (ReviewManagementDAOException e) {
|
||||
throw new ReviewManagementException(
|
||||
"DB Connection error occured while updated the rating value of the application release id: "
|
||||
+ appReleaseId + " can not get.", e);
|
||||
"Error occured while getting all rating values for the application release UUID: "
|
||||
+ appReleaseUuuid, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateRating(int newRatingVal, int oldRatingVal, String uuid) {
|
||||
// todo need to pass app release id
|
||||
int appReleaseId = 0;
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
Rating rating = this.applicationReleaseDAO.getRating(uuid);
|
||||
Rating rating = this.applicationReleaseDAO.getRating(uuid, tenantId);
|
||||
if (rating == null) {
|
||||
log.error("Couldn't find rating for application release id: " + appReleaseId);
|
||||
log.error("Couldn't find rating for application release uuid: " + uuid);
|
||||
} else {
|
||||
double updatedRating;
|
||||
int numOfUsers = rating.getNoOfUsers();
|
||||
double currentRating = rating.getRatingValue() * numOfUsers;
|
||||
if (oldRatingVal == -12345) {
|
||||
updatedRating = (currentRating + newRatingVal) / (numOfUsers + 1);
|
||||
this.applicationReleaseDAO.updateRatingValue(appReleaseId, updatedRating, numOfUsers + 1);
|
||||
this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers + 1);
|
||||
} else if (newRatingVal == 0) {
|
||||
updatedRating = (currentRating - newRatingVal) / (numOfUsers - 1);
|
||||
this.applicationReleaseDAO.updateRatingValue(appReleaseId, updatedRating, numOfUsers - 1);
|
||||
this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers - 1);
|
||||
} else {
|
||||
double tmpVal;
|
||||
tmpVal = currentRating - oldRatingVal;
|
||||
updatedRating = (tmpVal + newRatingVal) / numOfUsers;
|
||||
this.applicationReleaseDAO.updateRatingValue(appReleaseId, updatedRating, numOfUsers);
|
||||
this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers);
|
||||
}
|
||||
}
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
log.error("Error occured while updated the rating value of the application release id: " + appReleaseId
|
||||
+ " can not get.");
|
||||
log.error("Error occured while updated the rating value of the application release UUID: " + uuid);
|
||||
} catch (TransactionManagementException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
log.error(
|
||||
"Transaction Management Exception occured while updated the rating value of the application release id: "
|
||||
+ appReleaseId + " can not get.");
|
||||
|
||||
"Transaction Management Exception occured while updated the rating value of the application release UUID: "
|
||||
+ uuid);
|
||||
} catch (DBConnectionException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
log.error("DB Connection error occured while updated the rating value of the application release id: "
|
||||
+ appReleaseId + " can not get.");
|
||||
log.error("DB Connection error occured while updated the rating value of the application release UUID: "
|
||||
+ uuid + " can not get.");
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
@ -372,4 +347,20 @@ public class ReviewManagerImpl implements ReviewManager {
|
||||
.isUserAuthorized(MultitenantUtils.getTenantAwareUsername(username), permission,
|
||||
CarbonConstants.UI_PERMISSION_ACTION);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To check whether logged in user is authorized user to do an specific action.
|
||||
*
|
||||
* @param loggedInUser username of the loggedin user.
|
||||
* @param reviewOwner username of the review owner.
|
||||
* @param tenantId ID of the tenant.
|
||||
* @return true if the current user has the permission, otherwise false.
|
||||
* @throws UserStoreException UserStoreException
|
||||
*/
|
||||
private boolean isAuthorizedUser(String loggedInUser, String reviewOwner, int tenantId) throws UserStoreException {
|
||||
return loggedInUser.equals(reviewOwner) || isAdminUser(loggedInUser, tenantId,
|
||||
CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION);
|
||||
}
|
||||
|
||||
}
|
||||
@ -30,6 +30,7 @@ import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||
import org.wso2.carbon.device.application.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse;
|
||||
import org.wso2.carbon.device.application.mgt.common.Review;
|
||||
import javax.validation.Valid;
|
||||
@ -47,7 +48,7 @@ import javax.ws.rs.core.Response;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* APIs to handle comment management related tasks.
|
||||
* APIs to handle review management related tasks.
|
||||
*/
|
||||
|
||||
@SwaggerDefinition(
|
||||
@ -56,51 +57,36 @@ import java.util.List;
|
||||
title = "Store Management Service",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = "name", value = "CommentManagementService"),
|
||||
@ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/comments"),
|
||||
@ExtensionProperty(name = "name", value = "ReviewManagementService"),
|
||||
@ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/review"),
|
||||
})
|
||||
}
|
||||
),
|
||||
tags = {
|
||||
@Tag(name = "store_management", description = "Review Management related "
|
||||
+ "APIs")
|
||||
@Tag(name = "store_management", description = "Review Management related APIs")
|
||||
}
|
||||
)
|
||||
@Scopes(
|
||||
scopes = {
|
||||
@Scope(
|
||||
name = "Get Comments Details",
|
||||
description = "Get comments details",
|
||||
key = "perm:comment:get",
|
||||
permissions = {"/device-mgt/comment/get"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Add a Review",
|
||||
description = "Add a comment",
|
||||
key = "perm:comment:add",
|
||||
permissions = {"/device-mgt/comment/add"}
|
||||
name = "Get Review Details",
|
||||
description = "Get review details",
|
||||
key = "perm:app:review:view",
|
||||
permissions = {"/device-mgt/review/view"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Update a Review",
|
||||
description = "Update a Review",
|
||||
key = "perm:comment:update",
|
||||
permissions = {"/device-mgt/comment/update"}
|
||||
),
|
||||
|
||||
@Scope(
|
||||
name = "Delete a Review",
|
||||
description = "Delete a comment",
|
||||
key = "perm:comment:delete",
|
||||
permissions = {"/device-mgt/comment/delete"}
|
||||
description = "Update a comment",
|
||||
key = "perm:app:review:update",
|
||||
permissions = {"/device-mgt/review/update"}
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
@Path("/review")
|
||||
@Api(value = "Comments Management", description = "This API carries all comments management related operations " +
|
||||
"such as get all the comments, add comment, etc.")
|
||||
@Api(value = "Review Management", description = "This API carries all review management related operations such as get "
|
||||
+ "all the reviews, add review, etc.")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
|
||||
public interface ReviewManagementAPI {
|
||||
String SCOPE = "scope";
|
||||
|
||||
@ -110,12 +96,12 @@ public interface ReviewManagementAPI {
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "get comments",
|
||||
notes = "Get all comments",
|
||||
value = "get reviews",
|
||||
notes = "Get all reviews",
|
||||
tags = "Store Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:store:get")
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:review:view")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ -125,12 +111,8 @@ public interface ReviewManagementAPI {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully retrieved comments.",
|
||||
response = List.class,
|
||||
responseContainer = "List"),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not Found. \n No activity found with the given ID.",
|
||||
response = ErrorResponse.class),
|
||||
response = PaginationResult.class,
|
||||
responseContainer = "PaginationResult"),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error occurred while getting the comment list.",
|
||||
@ -146,14 +128,12 @@ public interface ReviewManagementAPI {
|
||||
String uuid,
|
||||
@ApiParam(
|
||||
name="offSet",
|
||||
value="Starting comment number.",defaultValue = "1",
|
||||
required = false)
|
||||
value="Starting comment number.",defaultValue = "0")
|
||||
@QueryParam("offSet")
|
||||
int offSet,
|
||||
@ApiParam(
|
||||
name="limit",
|
||||
value = "Limit of paginated comments",defaultValue = "20",
|
||||
required = false)
|
||||
value = "Limit of paginated comments",defaultValue = "20")
|
||||
@QueryParam("limit")
|
||||
int limit);
|
||||
|
||||
@ -170,7 +150,7 @@ public interface ReviewManagementAPI {
|
||||
tags = "Store Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:store:add")
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:review:update")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ -215,7 +195,7 @@ public interface ReviewManagementAPI {
|
||||
tags = "Store Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:store:edit")
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:review:update")
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
@ -25,6 +25,8 @@ import org.wso2.carbon.device.application.mgt.common.Application;
|
||||
import org.wso2.carbon.device.application.mgt.common.PaginationResult;
|
||||
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.exception.RequestValidatingException;
|
||||
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.ReviewManager;
|
||||
import org.wso2.carbon.device.application.mgt.store.api.APIUtil;
|
||||
@ -106,6 +108,10 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
|
||||
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) {
|
||||
String msg = "Error occurred while adding for application release. UUID of the application release: " + uuid;
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,7 +125,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
|
||||
@PathParam("reviewId") int reviewId) {
|
||||
ReviewManager reviewManager = APIUtil.getReviewManager();
|
||||
try {
|
||||
if (reviewManager.updateReview(review, reviewId, uuid, true)) {
|
||||
if (reviewManager.updateReview(review, reviewId, uuid, null)) {
|
||||
return Response.status(Response.Status.OK).entity(review).build();
|
||||
} else {
|
||||
String msg = "Review updating failed. Please contact the administrator";
|
||||
@ -130,6 +136,10 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
|
||||
String msg = "Error occurred while retrieving comments.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (RequestValidatingException e) {
|
||||
String msg = "Error occurred while updating review. Review id: " + reviewId;
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,9 +152,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
|
||||
|
||||
ReviewManager reviewManager = APIUtil.getReviewManager();
|
||||
try {
|
||||
if (reviewId == 0) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("Review not found").build();
|
||||
} else if (reviewManager.deleteReview(uuid, reviewId)) {
|
||||
if (reviewManager.deleteReview(uuid, reviewId)) {
|
||||
return Response.status(Response.Status.OK).entity("Review is deleted successfully.").build();
|
||||
} else {
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Review deleting is failed.")
|
||||
@ -154,6 +162,10 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
|
||||
String msg = "Error occurred while deleting the comment.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (ReviewDoesNotExistException e) {
|
||||
String msg = "Couldn't find a review for review-id: " + reviewId + " to delete.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user