diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml index 976bbb84c7..e332baf0be 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml @@ -122,8 +122,6 @@ org.codehaus.jackson jackson-core-asl - - diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Review.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ReviewTmp.java similarity index 87% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Review.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ReviewTmp.java index e2a488ce3e..98998dbfeb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Review.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ReviewTmp.java @@ -23,8 +23,8 @@ import io.swagger.annotations.ApiModelProperty; import java.sql.Timestamp; -@ApiModel(value = "Review", description = "Review represents the user's review for an application release") -public class Review { +@ApiModel(value = "ReviewTmp", description = "ReviewTmp represents the user's review for an application release") +public class ReviewTmp { @ApiModelProperty(name = "id", value = "The Id given to the comment when it store to the App manager") @@ -55,9 +55,9 @@ public class Review { value = "Rating value of the application release") private int rating; - @ApiModelProperty(name = "replyReview", + @ApiModelProperty(name = "replyReviewTmp", value = "Replying review") - private Review replyReview; + private ReviewTmp replyReviewTmp; public int getId() { return id; @@ -115,12 +115,12 @@ public class Review { this.parentId = parentId; } - public Review getReplyReview() { - return replyReview; + public ReviewTmp getReplyReviewTmp() { + return replyReviewTmp; } - public void setReplyReview(Review replyReview) { - this.replyReview = replyReview; + public void setReplyReviewTmp(ReviewTmp replyReviewTmp) { + this.replyReviewTmp = replyReviewTmp; } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ReviewDTO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ReviewDTO.java new file mode 100644 index 0000000000..64cc3a11d2 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/dto/ReviewDTO.java @@ -0,0 +1,87 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.dto; + +import java.sql.Timestamp; + +public class ReviewDTO { + private int id; + private String content; + private String username; + private Timestamp createdAt; + private Timestamp modifiedAt; + private int rating; + private int rootParentId; + private int immediateParentId; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public Timestamp getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Timestamp createdAt) { + this.createdAt = createdAt; + } + + public Timestamp getModifiedAt() { + return modifiedAt; + } + + public void setModifiedAt(Timestamp modifiedAt) { + this.modifiedAt = modifiedAt; + } + + public int getRating() { + return rating; + } + + public void setRating(int rating) { + this.rating = rating; + } + + public int getRootParentId() { return rootParentId; } + + public void setRootParentId(int rootParentId) { this.rootParentId = rootParentId; } + + public int getImmediateParentId() { return immediateParentId; } + + public void setImmediateParentId(int immediateParentId) { this.immediateParentId = immediateParentId; } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/Review.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/Review.java new file mode 100644 index 0000000000..55140969cb --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/Review.java @@ -0,0 +1,106 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.response; + +import java.sql.Timestamp; +import java.util.TreeMap; + +public class Review { + + private int id; + private String content; + private int rootParentId; + private int immediateParentId; + private String username; + private Timestamp createdAt; + private Timestamp modifiedAt; + private int rating; + private TreeMap replyComments; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public int getRootParentId() { + return rootParentId; + } + + public void setRootParentId(int rootParentId) { + this.rootParentId = rootParentId; + } + + public int getImmediateParentId() { + return immediateParentId; + } + + public void setImmediateParentId(int immediateParentId) { + this.immediateParentId = immediateParentId; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public Timestamp getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Timestamp createdAt) { + this.createdAt = createdAt; + } + + public Timestamp getModifiedAt() { + return modifiedAt; + } + + public void setModifiedAt(Timestamp modifiedAt) { + this.modifiedAt = modifiedAt; + } + + public int getRating() { + return rating; + } + + public void setRating(int rating) { + this.rating = rating; + } + + public TreeMap getReplyComments() { + return replyComments; + } + + public void setReplyComments(TreeMap replyComments) { + this.replyComments = replyComments; + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ReviewManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ReviewManager.java index 82c751feb7..d76ab8f6c8 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ReviewManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ReviewManager.java @@ -18,16 +18,14 @@ */ 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.Review; +import org.wso2.carbon.device.application.mgt.common.ReviewTmp; 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.ApplicationManagementException; -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.wrapper.ReviewWrapper; /** * ReviewManager is responsible for handling all the add/update/delete/get operations related with @@ -35,15 +33,16 @@ import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementE public interface ReviewManager { /** - * To add a review to an application release + * To add a reviewTmp to an application release * - * @param review review of the application. + * @param reviewWrapper reviewTmp of the application. * @param uuid uuid of the application release. - * @return {@link Review} Review added - * @throws ReviewManagementException Exceptions of the review management. + * @return {@link ReviewTmp} ReviewTmp added + * @throws ReviewManagementException Exceptions of the reviewTmp management. */ - boolean addReview(Review review, String uuid) - throws ReviewManagementException, RequestValidatingException, ApplicationManagementException; + boolean addReview(ReviewWrapper reviewWrapper, String uuid) throws ReviewManagementException, ApplicationManagementException; + + boolean addReplyComment(ReviewWrapper reviewWrapper, String uuid, int parentReviewId) throws ReviewManagementException, ApplicationManagementException; /** * Get all review with pagination @@ -67,24 +66,21 @@ public interface ReviewManager { throws ReviewManagementException, ReviewDoesNotExistException; /** - * To update a review. + * To update a reviewTmp. * - * @param review review of the application. - * @param reviewId id of the review + * @param reviewId id of the reviewTmp * @param uuid UUID of the application release - * @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 + * @return {@link ReviewTmp}updated reviewTmp + * @throws ReviewManagementException Exceptions of the reviewTmp management */ - boolean updateReview(Review review, int reviewId, String uuid, Review existingReview) - throws ReviewManagementException, RequestValidatingException; + boolean updateReview(ReviewWrapper updatingReview, int reviewId, String uuid) + throws ReviewManagementException, ApplicationManagementException; /** * To get the overall rating for a application release * * @param appReleaseUuuid UUID of the application release. - * @return {@link Review}updated review + * @return {@link ReviewTmp}updated review * @throws ReviewManagementException Exceptions of the review management */ Rating getRating(String appReleaseUuuid) throws ReviewManagementException; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ReviewWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ReviewWrapper.java new file mode 100644 index 0000000000..120df8cc1b --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ReviewWrapper.java @@ -0,0 +1,39 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.wrapper; + +public class ReviewWrapper { + private String content; + private int rating; + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public int getRating() { + return rating; + } + + public void setRating(int rating) { + this.rating = rating; + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ReviewDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ReviewDAO.java index 1018bc78b2..9f705d54c9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ReviewDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ReviewDAO.java @@ -18,8 +18,9 @@ */ package org.wso2.carbon.device.application.mgt.core.dao; -import org.wso2.carbon.device.application.mgt.common.Review; +import org.wso2.carbon.device.application.mgt.common.ReviewTmp; import org.wso2.carbon.device.application.mgt.common.PaginationRequest; +import org.wso2.carbon.device.application.mgt.common.dto.ReviewDTO; 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.core.exception.ReviewManagementDAOException; @@ -34,15 +35,15 @@ import java.util.List; public interface ReviewDAO { /** - * To add a review to an application release. + * To add a reviewTmp to an application release. * * @param tenantId tenantId. - * @param review review of the application. - * @param uuid UUID of the application release - * @return If review is added successfully, it return true otherwise false - * @throws ReviewManagementDAOException Exceptions of the review management DAO. + * @param reviewDTO reviewTmp of the application. + * @param appReleaseId UUID of the application release + * @return If reviewTmp is added successfully, it return true otherwise false + * @throws ReviewManagementDAOException Exceptions of the reviewTmp management DAO. */ - boolean addReview(Review review, String uuid, int tenantId) throws ReviewManagementDAOException; + boolean addReview(ReviewDTO reviewDTO, int appReleaseId, int tenantId) throws ReviewManagementDAOException; /** * To verify whether user has already commented for the application release or not. @@ -53,19 +54,19 @@ import java.util.List; * @return If review exists, review returns * @throws ReviewManagementDAOException Exceptions of the review management DAO. */ - Review haveUerCommented(String uuid, String username, int tenantId) throws ReviewManagementDAOException; + boolean haveUerReviewed(int appReleaseId, String username, int tenantId) throws ReviewManagementDAOException; /** * To update already added comment. * - * @param review Updating review - * @param reviewId id of the updating review - * @param username review owner + * @param reviewDTO Updating reviewTmp + * @param reviewId id of the updating reviewTmp + * @param username reviewTmp owner * @param tenantId tenant id * @return row count if updating is succeed otherwise 0 - * @throws ReviewManagementDAOException Exceptions of the review management. + * @throws ReviewManagementDAOException Exceptions of the reviewTmp management. */ - int updateReview(Review review, int reviewId, String username, int tenantId) + int updateReview(ReviewDTO reviewDTO, int reviewId, int tenantId) throws ReviewManagementDAOException; @@ -73,10 +74,13 @@ import java.util.List; * To get the comment with id. * * @param reviewId id of the review - * @return {@link Review}Review + * @return {@link ReviewTmp}ReviewTmp * @throws ReviewManagementDAOException Exceptions of the review management DAO. */ - Review getReview(int reviewId) throws ReviewManagementDAOException; + ReviewDTO getReview(int reviewId) throws ReviewManagementDAOException; + + ReviewDTO getReview(int appReleaseId, int reviewId) throws ReviewManagementDAOException; + /** * To get all reviews @@ -85,9 +89,9 @@ import java.util.List; * @param request {@link PaginationRequest}pagination request with offSet and limit * @param tenantId Tenant id * @return {@link List}List of all reviews for the application release - * @throws ReviewManagementDAOException Review management DAO exception + * @throws ReviewManagementDAOException ReviewTmp management DAO exception **/ - List getAllReviews(String uuid, PaginationRequest request, int tenantId) + List getAllReviews(String uuid, PaginationRequest request, int tenantId) throws ReviewManagementDAOException; /** @@ -119,7 +123,7 @@ import java.util.List; * @param username username of the review owner * @param reviewId id of the review * @return If review is successfully deleted return 1, otherwise returns 0. - * @throws ReviewManagementDAOException Review management DAO exception. + * @throws ReviewManagementDAOException ReviewTmp management DAO exception. */ int deleteReview(String username, int reviewId) throws ReviewManagementDAOException; @@ -137,8 +141,8 @@ import java.util.List; * To get review count for a specific application release * * @param uuid uuid of the application release - * @return Review count - * @throws ReviewManagementDAOException Review management DAO exception + * @return ReviewTmp count + * @throws ReviewManagementDAOException ReviewTmp management DAO exception */ int getReviewCount(String uuid) throws ReviewManagementDAOException; } \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Review/ReviewDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Review/ReviewDAOImpl.java index c5af36b6d4..e4aa49099d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Review/ReviewDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Review/ReviewDAOImpl.java @@ -21,8 +21,9 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.Review; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.application.mgt.common.Review; +import org.wso2.carbon.device.application.mgt.common.ReviewTmp; import org.wso2.carbon.device.application.mgt.common.PaginationRequest; +import org.wso2.carbon.device.application.mgt.common.dto.ReviewDTO; 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.core.dao.ReviewDAO; @@ -49,162 +50,227 @@ 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(ReviewDTO reviewDTO, int appReleaseId, int tenantId) throws ReviewManagementDAOException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to add review for application release. ApplicationDTO UUID: " + uuid); + log.debug("Request received in DAO Layer to add review for application release. Application Release UUID: " + + appReleaseId); } - PreparedStatement statement = null; - ResultSet rs = null; - sql = "INSERT INTO AP_APP_REVIEW (TENANT_ID, COMMENT, PARENT_ID, RATING, USERNAME,CREATED_AT, MODIFIED_AT, " - + "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=?));"; + sql = "INSERT INTO AP_APP_REVIEW " + + "(TENANT_ID, " + + "COMMENT, " + + "ROOT_PARENT_ID," + + "IMMEDIATE_PARENT_ID, " + + "RATING, " + + "USERNAME, " + + "CREATED_AT, " + + "MODIFIED_AT, " + + "AP_APP_RELEASE_ID) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ? )"; try { Calendar calendar = Calendar.getInstance(); Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); Connection conn = this.getDBConnection(); - statement = conn.prepareStatement(sql, new String[] { "id" }); - statement.setInt(1, tenantId); - statement.setString(2, review.getComment()); - statement.setInt(3, review.getParentId()); - statement.setInt(4, review.getRating()); - statement.setString(5, review.getUsername()); - statement.setTimestamp(6, timestamp); - statement.setTimestamp(7,timestamp); - statement.setString(8,uuid); - statement.setString(9,uuid); - statement.executeUpdate(); - rs = statement.getGeneratedKeys(); - return rs.next(); - } - catch (DBConnectionException e) { + try (PreparedStatement statement = conn.prepareStatement(sql, new String[] { "id" });) { + statement.setInt(1, tenantId); + statement.setString(2, reviewDTO.getContent()); + statement.setInt(3, reviewDTO.getRootParentId()); + statement.setInt(4, reviewDTO.getImmediateParentId()); + statement.setInt(5, reviewDTO.getRating()); + statement.setString(6, reviewDTO.getUsername()); + statement.setTimestamp(7, timestamp); + statement.setTimestamp(8, timestamp); + statement.setInt(9, appReleaseId); + statement.executeUpdate(); + try (ResultSet rs = statement.getGeneratedKeys()) { + return rs.next(); + } + } + } catch (DBConnectionException e) { throw new ReviewManagementDAOException("Error occurred while obtaining the DB connection while " - + "adding review for application UUID: "+ "Tenant Id: " + tenantId, e); - }catch (SQLException e) { - throw new ReviewManagementDAOException("Error occurred while getting application list for the tenant" - + " " + tenantId + ". While executing " + sql, e); - } finally { - Util.cleanupResources(statement, rs); + + "adding review for application release which has ID: "+ appReleaseId + "Tenant Id: " + tenantId, e); + } catch (SQLException e) { + throw new ReviewManagementDAOException( + "Error occurred while executing SQL statement to add application review. Application ID: " + + appReleaseId + " tenant " + tenantId, e); } } @Override - public Review haveUerCommented(String uuid, String username, int tenantId) throws ReviewManagementDAOException { + public boolean haveUerReviewed(int appReleaseId, String username, int tenantId) throws ReviewManagementDAOException { if (log.isDebugEnabled()) { - log.debug( - "Request received in DAO Layer to check whether user have already commented or not for the " - + "application release. ApplicationDTO UUID: " + uuid + " comment owner: " + username + - " tenant-id " + tenantId); + log.debug("Request received in DAO Layer to check whether user have already reviewed or not for the " + + "application release. Commenting user: " + username + " and tenant-id: " + tenantId); } Connection conn; - PreparedStatement statement = null; - ResultSet rs = null; - Review review = null; - 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 = ?;"; + sql = "SELECT " + + "rv.ID " + + "FROM AP_APP_REVIEW rv " + + "WHERE " + + "rv.AP_APP_RELEASE_ID = ? AND " + + "rv.USERNAME = ? AND " + + "rv.TENANT_ID = ?"; try { conn = this.getDBConnection(); - statement = conn.prepareStatement(sql); - statement.setString(1, uuid); - statement.setString(2, username); - statement.setInt(3, tenantId); - rs = statement.executeQuery(); - if (rs.next()){ - review = new Review(); - review.setId(rs.getInt("ID")); - review.setComment(rs.getString("COMMENT")); - review.setParentId(rs.getInt("PARENT_ID")); - review.setCreatedAt(rs.getTimestamp("CREATED_AT")); - review.setModifiedAt(rs.getTimestamp("MODIFIED_AT")); - review.setUsername(rs.getString("USERNAME")); - review.setRating(rs.getInt("RATING")); + try (PreparedStatement statement = conn.prepareStatement(sql)) { + statement.setInt(1, appReleaseId); + statement.setString(2, username); + statement.setInt(3, tenantId); + try (ResultSet rs = statement.executeQuery()) { + return rs.next(); + + } } - return review; } catch (SQLException e) { throw new ReviewManagementDAOException("Error occured while accessing the Database when checking whether " + "user has already commented for the application ro not", e); } catch (DBConnectionException e) { throw new ReviewManagementDAOException("Error occured while getting the database connection when checking " + "whether user has already commented for the application ro not", e); - - } finally { - Util.cleanupResources(statement, rs); } } @Override - public int updateReview(Review review, int reviewId, String username, int tenantId) + public int updateReview(ReviewDTO reviewDTO, int reviewId, int tenantId) throws ReviewManagementDAOException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to update the comment with ID (" + reviewId + ")"); + log.debug("Request received in DAO Layer to update the Review with ID (" + reviewId + ")"); } Connection connection; PreparedStatement statement = null; ResultSet rs = null; - sql = "UPDATE AP_APP_REVIEW SET COMMENT=?, RATING=?, MODIFIED_AT=? WHERE ID=? AND USERNAME=? AND TENANT_ID=?;"; + sql = "UPDATE " + + "AP_APP_REVIEW " + + "SET " + + "COMMENT = ?, " + + "RATING = ?, " + + "MODIFIED_AT = ? " + + "WHERE ID = ? AND " + + "TENANT_ID = ?"; try { Calendar calendar = Calendar.getInstance(); Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); connection = this.getDBConnection(); statement = connection.prepareStatement(sql); - statement.setString(1, review.getComment()); - statement.setInt(2, review.getRating()); + statement.setString(1, reviewDTO.getContent()); + statement.setInt(2, reviewDTO.getRating()); statement.setTimestamp(3, timestamp); statement.setInt(4, reviewId); - statement.setString(5, username); - statement.setInt(6, tenantId); + statement.setInt(5, tenantId); return statement.executeUpdate(); } catch (SQLException e) { - throw new ReviewManagementDAOException("Error occurred while executing review updating query"); + throw new ReviewManagementDAOException("Error occurred while executing reviewTmp updating query"); } catch (DBConnectionException e) { - throw new ReviewManagementDAOException("Error occured while getting the db connection to update review"); + throw new ReviewManagementDAOException("Error occured while getting the db connection to update reviewTmp"); } finally { Util.cleanupResources(statement, rs); } } @Override - public Review getReview(int reviewId) throws ReviewManagementDAOException { + public ReviewDTO getReview(int reviewId) throws ReviewManagementDAOException { if (log.isDebugEnabled()) { - log.debug("Getting review with the review id(" + reviewId + ") from the database"); + log.debug("Getting reviewDTO with the review id(" + reviewId + ") from the database"); } Connection conn; PreparedStatement statement = null; ResultSet rs = null; - Review review = null; try { conn = this.getDBConnection(); - sql = "SELECT ID, COMMENT, CREATED_AT, MODIFIED_AT, RATING, USERNAME FROM AP_APP_REVIEW WHERE ID=?;"; + sql = "SELECT " + + "ID, " + + "COMMENT," + + "ROOT_PARENT_ID," + + "IMMEDIATE_PARENT_ID, " + + "CREATED_AT, " + + "MODIFIED_AT, " + + "RATING, " + + "USERNAME " + + "FROM AP_APP_REVIEW " + + "WHERE ID = ?"; statement = conn.prepareStatement(sql); statement.setInt(1, reviewId); rs = statement.executeQuery(); if (rs.next()) { - review = new Review(); - review.setId(rs.getInt("ID")); - review.setComment(rs.getString("COMMENT")); - review.setCreatedAt(rs.getTimestamp("CREATED_AT")); - review.setModifiedAt(rs.getTimestamp("MODIFIED_AT")); - review.setRating(rs.getInt("RATING")); - review.setUsername(rs.getString("USERNAME")); - return review; + ReviewDTO reviewDTO = new ReviewDTO(); + reviewDTO.setId(rs.getInt("ID")); + reviewDTO.setContent(rs.getString("COMMENT")); + reviewDTO.setCreatedAt(rs.getTimestamp("CREATED_AT")); + reviewDTO.setModifiedAt(rs.getTimestamp("MODIFIED_AT")); + reviewDTO.setRating(rs.getInt("RATING")); + reviewDTO.setRootParentId(rs.getInt("ROOT_PARENT_ID")); + reviewDTO.setImmediateParentId(rs.getInt("IMMEDIATE_PARENT_ID")); + reviewDTO.setUsername(rs.getString("USERNAME")); + return reviewDTO; } + return null; } catch (SQLException e) { throw new ReviewManagementDAOException( - "SQL Error occurred while retrieving information of the review " + reviewId, e); + "SQL Error occurred while retrieving information of the reviewTmp " + reviewId, e); } catch (DBConnectionException e) { throw new ReviewManagementDAOException( - "DB Connection Exception occurred while retrieving information of the review " + reviewId, e); + "DB Connection Exception occurred while retrieving information of the reviewTmp " + reviewId, e); } finally { Util.cleanupResources(statement, rs); } - return review; } @Override - public List getAllReviews(String uuid, PaginationRequest request, int tenantId) + public ReviewDTO getReview(int appReleaseId, int reviewId) throws ReviewManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Getting reviewDTO with the review id(" + reviewId + ") from the database"); + } + Connection conn; + PreparedStatement statement = null; + ResultSet rs = null; + try { + conn = this.getDBConnection(); + sql = "SELECT " + + "ID, " + + "COMMENT," + + "ROOT_PARENT_ID," + + "IMMEDIATE_PARENT_ID, " + + "CREATED_AT, " + + "MODIFIED_AT, " + + "RATING, " + + "USERNAME " + + "FROM AP_APP_REVIEW " + + "WHERE ID = ? AND " + + "AP_APP_RELEASE_ID = ?"; + statement = conn.prepareStatement(sql); + statement.setInt(1, reviewId); + statement.setInt(2, appReleaseId); + rs = statement.executeQuery(); + if (rs.next()) { + ReviewDTO reviewDTO = new ReviewDTO(); + reviewDTO.setId(rs.getInt("ID")); + reviewDTO.setContent(rs.getString("COMMENT")); + reviewDTO.setCreatedAt(rs.getTimestamp("CREATED_AT")); + reviewDTO.setModifiedAt(rs.getTimestamp("MODIFIED_AT")); + reviewDTO.setRating(rs.getInt("RATING")); + reviewDTO.setRootParentId(rs.getInt("ROOT_PARENT_ID")); + reviewDTO.setImmediateParentId(rs.getInt("IMMEDIATE_PARENT_ID")); + reviewDTO.setUsername(rs.getString("USERNAME")); + return reviewDTO; + } + return null; + } catch (SQLException e) { + throw new ReviewManagementDAOException( + "SQL Error occurred while retrieving information of the reviewTmp " + reviewId, e); + } catch (DBConnectionException e) { + throw new ReviewManagementDAOException( + "DB Connection Exception occurred while retrieving information of the reviewTmp " + reviewId, e); + } finally { + Util.cleanupResources(statement, rs); + } + } + + + @Override + public List getAllReviews(String uuid, PaginationRequest request, int tenantId) throws ReviewManagementDAOException { if (log.isDebugEnabled()) { @@ -213,16 +279,25 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { Connection conn; PreparedStatement statement = null; ResultSet rs = null; - List reviews = new ArrayList<>(); + List reviewDTOs = new ArrayList<>(); try { conn = this.getDBConnection(); - 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.USERNAME AS USERNAME, AP_APP_REVIEW.PARENT_ID AS PARENT_ID, " - + "AP_APP_REVIEW.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_REVIEW.TENANT_ID = ? AND " - + "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID LIMIT ? OFFSET ?;"; + 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.USERNAME AS USERNAME, " + + "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, " + + "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, " + + "AP_APP_REVIEW.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_REVIEW.TENANT_ID = ? AND " + + "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID " + + "LIMIT ? OFFSET ?;"; statement = conn.prepareStatement(sql); statement.setString(1, uuid); statement.setInt(2, tenantId); @@ -230,25 +305,26 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { statement.setInt(4, request.getOffSet()); rs = statement.executeQuery(); while (rs.next()) { - Review review = new Review(); - review.setId(rs.getInt("ID")); - review.setComment(rs.getString("COMMENT")); - review.setCreatedAt(rs.getTimestamp("CREATED_AT")); - review.setModifiedAt(rs.getTimestamp("MODIFIED_AT")); - review.setParentId(rs.getInt("PARENT_ID")); - review.setUsername(rs.getString("USERNAME")); - review.setRating(rs.getInt("RATING")); - reviews.add(review); + ReviewDTO reviewDTO = new ReviewDTO(); + reviewDTO.setId(rs.getInt("ID")); + reviewDTO.setContent(rs.getString("COMMENT")); + reviewDTO.setCreatedAt(rs.getTimestamp("CREATED_AT")); + reviewDTO.setModifiedAt(rs.getTimestamp("MODIFIED_AT")); + reviewDTO.setRootParentId(rs.getInt("ROOT_PARENT_ID")); + reviewDTO.setImmediateParentId(rs.getInt("IMMEDIATE_PARENT_ID")); + reviewDTO.setUsername(rs.getString("USERNAME")); + reviewDTO.setRating(rs.getInt("RATING")); + reviewDTOs.add(reviewDTO); } } catch (DBConnectionException e) { throw new ReviewManagementDAOException( "Error occurred while obtaining the DB connection when verifying application existence", e); } catch (SQLException e) { - throw new ReviewManagementDAOException("DB connection error occurred while getting all reviews", e); + throw new ReviewManagementDAOException("DB connection error occurred while getting all reviewTmps", e); }finally { Util.cleanupResources(statement, rs); } - return reviews; + return reviewDTOs; } @Override diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ApplicationManagementDAOException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ApplicationManagementDAOException.java index ccadcab072..d946ee3fce 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ApplicationManagementDAOException.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ApplicationManagementDAOException.java @@ -16,8 +16,6 @@ */ package org.wso2.carbon.device.application.mgt.core.exception; -import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; - /** * Exception thrown during the ApplicationDTO Management DAO operations. */ diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ReviewManagementDAOException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ReviewManagementDAOException.java index f32f08b324..56cb3ff3ba 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ReviewManagementDAOException.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ReviewManagementDAOException.java @@ -21,7 +21,7 @@ package org.wso2.carbon.device.application.mgt.core.exception; import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException; /** - * Exception thrown during the Review Management DAO operations. + * Exception thrown during the ReviewTmp Management DAO operations. */ public class ReviewManagementDAOException extends ReviewManagementException { 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 ed50b02407..b3b4047d81 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 @@ -22,17 +22,25 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; 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.ReviewTmp; 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.dto.ApplicationReleaseDTO; +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.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; +import org.wso2.carbon.device.application.mgt.common.response.Review; import org.wso2.carbon.device.application.mgt.common.services.*; +import org.wso2.carbon.device.application.mgt.common.wrapper.ReviewWrapper; 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.common.ApplicationManagementDAOFactory; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; +import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; +import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; 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.internal.DataHolder; @@ -42,6 +50,7 @@ import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.TreeMap; @@ -64,34 +73,120 @@ public class ReviewManagerImpl implements ReviewManager { } @Override - public boolean addReview(Review review, String uuid) throws ReviewManagementException, NotFoundException { + public boolean addReview(ReviewWrapper reviewWrapper, String uuid) + throws ReviewManagementException, ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - boolean isSuccess = false; + + if (reviewWrapper == null) { + String msg = "Request payload is null. Please verify the request payload."; + log.error(msg); + throw new BadRequestException(msg); + } + if (reviewWrapper.getRating() < 0) { + String msg = "You are trying to add invalid rating value as rating. Therefore please verify the request " + + "payload."; + log.error(msg); + throw new BadRequestException(msg); + } try { - ConnectionManagerUtil.openDBConnection(); - if (!this.applicationReleaseDAO.verifyReleaseExistenceByUuid(uuid, tenantId)){ - throw new NotFoundException("Couldn't find application release for the application UUID: " + uuid); + ConnectionManagerUtil.beginDBTransaction(); + 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); } - Review existingReview = this.reviewDAO.haveUerCommented(uuid, username, tenantId); - if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId) - && review.getRating() > 0 && review.getRating() != existingReview.getRating()) { - Runnable task = () -> calculateRating(review.getRating(), existingReview.getRating(), uuid, tenantId); - new Thread(task).start(); - isSuccess = updateReview(review, existingReview.getId(), uuid, existingReview); - } else if (review.getRating() > 0) { - Runnable task = () -> calculateRating(review.getRating(), -12345, uuid, tenantId); - new Thread(task).start(); - review.setUsername(username); - isSuccess = this.reviewDAO.addReview(review, uuid, tenantId); + if (this.reviewDAO.haveUerReviewed(applicationReleaseDTO.getId(), username, tenantId)) { + String msg = + "User " + username + " has already reviewed the application release which has UUID: " + uuid + + ". Hence you can't add another review for same application release. But you can update " + + "the review that you have already added for ths application release."; + log.error(msg); + throw new ForbiddenException(msg); + } + Runnable task = () -> calculateRating(reviewWrapper.getRating(), -12345, uuid, tenantId); + new Thread(task).start(); + + ReviewDTO reviewDTO = reviewWrapperToDO(reviewWrapper); + reviewDTO.setUsername(username); + reviewDTO.setRootParentId(-1); + reviewDTO.setImmediateParentId(-1); + if (this.reviewDAO.addReview(reviewDTO, applicationReleaseDTO.getId(), tenantId)) { + ConnectionManagerUtil.commitDBTransaction(); + return true; } - return isSuccess; + ConnectionManagerUtil.rollbackDBTransaction(); + return false; + } catch (DBConnectionException e) { + String msg = "DB Connection error occurs when adding Review for application release with UUID: " + uuid + + " is failed"; + log.error(msg); + throw new ReviewManagementException(msg, e); + } catch (TransactionManagementException e) { + String msg = "DB transaction error occurred when adding review for application release which has " + + "application UUID: " + uuid; + log.error(msg); + 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); + } catch (ReviewManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = "Error occurred when getting review data or adding review data for application release which " + + "has UUID: " + uuid; + log.error(msg); + throw new ReviewManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } + + @Override + public boolean addReplyComment(ReviewWrapper reviewWrapper, String uuid, int parentReviewId) + throws ReviewManagementException, NotFoundException, BadRequestException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + + if (reviewWrapper == null) { + String msg = "Request payload is null. Please verify the request payload."; + log.error(msg); + throw new BadRequestException(msg); + } + try { + ConnectionManagerUtil.beginDBTransaction(); + 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) { + String msg = "Couldn't find an review which has review ID: " + parentReviewId + + " for application release which has UUID: " + uuid; + log.error(msg); + throw new BadRequestException(msg); + } + ReviewDTO replyComment = reviewWrapperToDO(reviewWrapper); + replyComment.setUsername(username); + replyComment.setRootParentId(parentReview.getRootParentId()); + replyComment.setImmediateParentId(parentReview.getId()); + if (this.reviewDAO.addReview(replyComment, applicationReleaseDTO.getId(), tenantId)) { + ConnectionManagerUtil.commitDBTransaction(); + return true; + } + return false; } catch (DBConnectionException e) { throw new ReviewManagementException( - "DB Connection error 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.", + "DB Connection error occurs ,ReviewTmp for application release with UUID: " + uuid + " is failed", e); + } catch (TransactionManagementException e) { + String msg = "DB transaction error occurred when adding reply comment for comment which has comment id: " + + parentReviewId; + log.error(msg); + throw new ReviewManagementException(msg, e); } catch (ApplicationManagementDAOException e) { throw new ReviewManagementException( "Error occured while verifying whether application release is exists or not.", e); @@ -100,54 +195,85 @@ public class ReviewManagerImpl implements ReviewManager { } } + private ReviewDTO reviewWrapperToDO(ReviewWrapper reviewWrapper){ + ReviewDTO reviewDTO = new ReviewDTO(); + reviewDTO.setContent(reviewWrapper.getContent()); + reviewDTO.setRating(reviewWrapper.getRating()); + return reviewDTO; + } + + private List reviewDTOToReview(List reviewDTOs){ + List reviews = new ArrayList<>(); + + for (ReviewDTO reviewDTO : reviewDTOs){ + Review review = new Review(); + review.setId(reviewDTO.getId()); + review.setContent(reviewDTO.getContent()); + review.setRootParentId(reviewDTO.getRootParentId()); + review.setImmediateParentId(reviewDTO.getImmediateParentId()); + review.setCreatedAt(reviewDTO.getCreatedAt()); + review.setModifiedAt(reviewDTO.getModifiedAt()); + review.setReplyComments(new TreeMap<>()); + reviews.add(review); + } + return reviews; + } + @Override - public boolean updateReview(Review review, int reviewId, String uuid, Review existingReview) - throws ReviewManagementException { + public boolean updateReview(ReviewWrapper updatingReview, int reviewId, String uuid) + throws ReviewManagementException, ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - boolean isConnectionOpen = false; if (log.isDebugEnabled()) { - log.debug("Review updating request is received for the review id " + reviewId); + log.debug("ReviewTmp updating request is received for the reviewTmp id " + reviewId); } try { - if (existingReview == null) { - ConnectionManagerUtil.openDBConnection(); - isConnectionOpen = true; - existingReview = this.reviewDAO.getReview(reviewId); - if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId)) { - if (review.getRating() > 0 && review.getRating() != existingReview.getRating()) { - Review finalExistingReview = existingReview; - Runnable task = () -> calculateRating(review.getRating(), finalExistingReview.getRating(), - uuid, tenantId); - new Thread(task).start(); - } - } else { - throw new ReviewManagementException( - "Please check the existence of the review, Review-Id: " + reviewId - + " or permission of the " + username + " to update the review."); - } + ConnectionManagerUtil.openDBConnection(); + ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO.getReleaseByUUID(uuid, tenantId); + if (applicationReleaseDTO == null) { + String msg = "Couldn't found an application release for UUID: " + uuid; + log.error(msg); + throw new NotFoundException(msg); } - if (review.getComment().isEmpty()) { - review.setComment(existingReview.getComment()); + ReviewDTO reviewDTO = this.reviewDAO.getReview(applicationReleaseDTO.getId(), reviewId); + if (reviewDTO == null) { + String msg = + "Couldn't found a review for application release which has UUID: " + uuid + " and review ID: " + + reviewId; + log.error(msg); + throw new NotFoundException(msg); } - if (review.getRating() == 0) { - review.setRating(existingReview.getRating()); + + if (!username.equals(reviewDTO.getUsername())) { + String msg = "You are trying to update a review which is triggered by " + reviewDTO.getUsername() + + ". Hence you are not permitted to update the review."; + log.error(msg); + throw new ForbiddenException(msg); + } + + if (reviewDTO.getRootParentId() == -1 && reviewDTO.getImmediateParentId() == -1 + && updatingReview.getRating() > 0 && updatingReview.getRating() != reviewDTO.getRating()) { + Runnable task = () -> calculateRating(updatingReview.getRating(), reviewDTO.getRating(), uuid, + tenantId); + new Thread(task).start(); + reviewDTO.setRating(updatingReview.getRating()); } - return this.reviewDAO.updateReview(review, reviewId, username, tenantId) == 1; + reviewDTO.setContent(updatingReview.getContent()); + return this.reviewDAO.updateReview(reviewDTO, reviewId, tenantId) == 1; } catch (ReviewManagementDAOException e) { - throw new ReviewManagementException("Error occured while getting review with review id " + reviewId + ".", - e); + String msg = "Error occured while getting reviewTmp with reviewTmp id " + reviewId + "."; + log.error(msg); + throw new ReviewManagementException(msg, e); } catch (DBConnectionException e) { - throw new ReviewManagementException( - "DB Connection error occurs 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); + String msg = "DB Connection error occurs updating reviewTmp with reviewTmp id " + reviewId + "."; + log.error(msg); + 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); } finally { - if (isConnectionOpen) { - ConnectionManagerUtil.closeDBConnection(); - } + ConnectionManagerUtil.closeDBConnection(); } } @@ -157,37 +283,44 @@ public class ReviewManagerImpl implements ReviewManager { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); PaginationResult paginationResult = new PaginationResult(); int numOfComments; - List reviews; - TreeMap hierarchicalReviewSet = new TreeMap<>(); + TreeMap reviewTree = new TreeMap<>(); if (log.isDebugEnabled()) { - log.debug("Get all reviews of the application release uuid: " + uuid); + log.debug("Get all reviewTmps of the application release uuid: " + uuid); } try { ConnectionManagerUtil.openDBConnection(); - reviews = this.reviewDAO.getAllReviews(uuid, request, tenantId); + List reviewDTOs= this.reviewDAO.getAllReviews(uuid, request, tenantId); + List reviews = reviewDTOToReview(reviewDTOs); + reviews.sort(Comparator.comparing(Review::getId)); for (Review review : reviews) { - if (hierarchicalReviewSet.containsKey(review.getParentId())) { - Review parentReview = hierarchicalReviewSet.get(review.getParentId()); - parentReview.setReplyReview(review); - hierarchicalReviewSet.replace(review.getParentId(), parentReview); - } else { - hierarchicalReviewSet.put(review.getId(), review); + if (review.getRootParentId() == -1 && review.getImmediateParentId() == -1) { + reviewTree.put(review.getId(), review); + } else if (reviewTree.containsKey(review.getRootParentId())) { + if (review.getRootParentId() == review.getImmediateParentId()) { + reviewTree.get(review.getRootParentId()).getReplyComments().put(review.getId(), review); + } else if (reviewTree.get(review.getRootParentId()).getReplyComments() + .containsKey(review.getImmediateParentId())) { + reviewTree.get(review.getRootParentId()).getReplyComments().get(review.getImmediateParentId()) + .getReplyComments().put(review.getId(), review); + } else { + //todo traverse and find + } } } - numOfComments = hierarchicalReviewSet.size(); + numOfComments = reviewTree.size(); if (numOfComments > 0) { - paginationResult.setData(new ArrayList<>(hierarchicalReviewSet.values())); + paginationResult.setData(new ArrayList<>(reviewTree.values())); paginationResult.setRecordsFiltered(numOfComments); paginationResult.setRecordsTotal(numOfComments); } else { - paginationResult.setData(new ArrayList()); + paginationResult.setData(new ArrayList()); paginationResult.setRecordsFiltered(0); paginationResult.setRecordsTotal(0); } return paginationResult; } catch (ReviewManagementDAOException e) { - throw new ReviewManagementException("Error occured while getting all reviews for application uuid: " + uuid, + throw new ReviewManagementException("Error occured while getting all reviewTmps for application uuid: " + uuid, e); } catch (DBConnectionException e) { throw new ReviewManagementException("Error occured while getting the DB connection.", e); @@ -199,7 +332,7 @@ public class ReviewManagerImpl implements ReviewManager { @Override public boolean deleteReview(String uuid, int reviewId) throws ReviewManagementException, ReviewDoesNotExistException { - Review existingReview; + ReviewDTO existingReview; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); try { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java index d4cc2f72c7..d3ae664f32 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java @@ -120,7 +120,7 @@ public class APIUtil { } /** - * To get the Review Manager from the osgi context. + * To get the ReviewTmp Manager from the osgi context. * @return ReviewManager instance in the current osgi context. */ public static ReviewManager getReviewManager() { @@ -131,7 +131,7 @@ public class APIUtil { reviewManager = (ReviewManager) ctx.getOSGiService(ReviewManager.class, null); if (reviewManager == null) { - String msg = "Review Manager service has not initialized."; + String msg = "ReviewTmp Manager service has not initialized."; log.error(msg); throw new IllegalStateException(msg); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java index d883ad454b..1b9695659f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java @@ -63,4 +63,6 @@ public class Constants { * Directory name of the release artifacts that are saved in the file system. */ public static final String RELEASE_ARTIFACT = "artifact"; + + public static final int MAXIMUM_REVIEWS_PER_USER = 10; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/pom.xml index ae5daccb49..d0a291c544 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/pom.xml @@ -157,16 +157,6 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.application.mgt.core provided - - - org.mockito - mockito-core - - - javassist - javassist - - org.wso2.carbon.devicemgt diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java index 045e5163b0..aea3990e5e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java @@ -32,7 +32,9 @@ 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.common.ErrorResponse; -import org.wso2.carbon.device.application.mgt.common.Review; +import org.wso2.carbon.device.application.mgt.common.ReviewTmp; +import org.wso2.carbon.device.application.mgt.common.wrapper.ReviewWrapper; + import javax.validation.Valid; import javax.ws.rs.Path; import javax.ws.rs.Consumes; @@ -63,19 +65,19 @@ import java.util.List; } ), tags = { - @Tag(name = "review_management", description = "Review Management related APIs") + @Tag(name = "review_management", description = "ReviewTmp Management related APIs") } ) @Scopes( scopes = { @Scope( - name = "Get Review Details", + name = "Get ReviewTmp Details", description = "Get review details", key = "perm:app:review:view", permissions = {"/app-mgt/store/review/view"} ), @Scope( - name = "Update a Review", + name = "Update a ReviewTmp", description = "Update a comment", key = "perm:app:review:update", permissions = {"/app-mgt/store/review/update"} @@ -84,7 +86,7 @@ import java.util.List; ) @Path("/review") -@Api(value = "Review Management", description = "This API carries all review management related operations such as get " +@Api(value = "ReviewTmp 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 { @@ -144,12 +146,12 @@ public interface ReviewManagementAPI { consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, httpMethod = "POST", - value = "Add a review", - notes = "This will add a new review", + value = "Add a reviewTmp", + notes = "This will add a new reviewTmp", tags = "Store Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:review:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:reviewTmp:update") }) } ) @@ -158,29 +160,79 @@ public interface ReviewManagementAPI { value = { @ApiResponse( code = 201, - message = "OK. \n Successfully add a review.", - response = Review.class), + message = "OK. \n Successfully add a reviewTmp.", + response = ReviewTmp.class), @ApiResponse( code = 400, message = "Bad Request. \n"), @ApiResponse( code = 500, - message = "Internal Server Error. \n Error occurred adding a review.", + message = "Internal Server Error. \n Error occurred adding a reviewTmp.", response = ErrorResponse.class) }) Response addReview( @ApiParam( - name = "review", - value = "Review details", - required = true) Review review, + name = "reviewTmp", + value = "ReviewTmp details", + required = true) ReviewWrapper reviewWrapper, @ApiParam( name="uuid", value="uuid of the release version of the application", required=true) @PathParam("uuid") String uuid); + @POST + @Path("/{uuid}/{parentReviewId}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Add a reviewTmp", + notes = "This will add a new reviewTmp", + tags = "Store Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:app:reviewTmp:update") + }) + } + ) + + @ApiResponses( + value = { + @ApiResponse( + code = 201, + message = "OK. \n Successfully add a reviewTmp.", + response = ReviewTmp.class), + @ApiResponse( + code = 400, + message = + "Bad Request. \n"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred adding a reviewTmp.", + response = ErrorResponse.class) + }) + + Response addReplyComment( + @ApiParam( + name = "reviewTmp", + value = "ReviewTmp details", + required = true) ReviewWrapper reviewWrapper, + @ApiParam( + name="uuid", + value="uuid of the release version of the application", + required=true) + @PathParam("uuid") String uuid, + @ApiParam( + name="parentReviewId", + value="uuid of the release version of the application", + required=true) + @PathParam("parentReviewId") int parentReviewId); + @PUT @Path("/{uuid}/{reviewId}") @Produces(MediaType.APPLICATION_JSON) @@ -189,12 +241,12 @@ public interface ReviewManagementAPI { consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, httpMethod = "PUT", - value = "Edit a review", - notes = "This will edit the review", + value = "Edit a reviewTmp", + notes = "This will edit the reviewTmp", tags = "Store Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:review:update") + @ExtensionProperty(name = SCOPE, value = "perm:app:reviewTmp:update") }) } ) @@ -202,22 +254,22 @@ public interface ReviewManagementAPI { value = { @ApiResponse( code = 200, - message = "OK. \n Successfully updated review.", - response = Review.class), + message = "OK. \n Successfully updated reviewTmp.", + response = ReviewTmp.class), @ApiResponse( code = 400, message = "Bad Request. \n Invalid request or validation error."), @ApiResponse( code = 500, - message = "Internal Server Error. \n Error occurred while updating the new review.", + message = "Internal Server Error. \n Error occurred while updating the new reviewTmp.", response = ErrorResponse.class) }) Response updateReview( @ApiParam( - name = "review", - value = "The review that need to be updated.", + name = "reviewTmp", + value = "The reviewTmp that need to be updated.", required = true) - @Valid Review review, + @Valid ReviewWrapper updatingReview, @ApiParam( name="uuid", value = "uuid of the application release", @@ -225,7 +277,7 @@ public interface ReviewManagementAPI { @PathParam("uuid") String uuid, @ApiParam( name="reviewId", - value = "review id of the updating review.", + value = "reviewTmp id of the updating reviewTmp.", required = true) @PathParam("reviewId") int reviewId); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ReviewManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ReviewManagementAPIImpl.java index da6a6a7228..5fb8137229 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ReviewManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ReviewManagementAPIImpl.java @@ -23,10 +23,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; 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.ReviewManager; +import org.wso2.carbon.device.application.mgt.common.wrapper.ReviewWrapper; +import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.store.api.services.ReviewManagementAPI; import org.wso2.carbon.device.application.mgt.common.PaginationRequest; @@ -46,7 +46,7 @@ import javax.ws.rs.DELETE; import javax.ws.rs.core.Response; /** - * Review Management related jax-rs APIs. + * ReviewTmp Management related jax-rs APIs. */ @Path("/review") public class ReviewManagementAPIImpl implements ReviewManagementAPI { @@ -77,15 +77,15 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI { @Consumes("application/json") @Path("/{uuid}") public Response addReview( - @ApiParam Review review, + @ApiParam ReviewWrapper reviewWrapper, @PathParam("uuid") String uuid) { ReviewManager reviewManager = APIUtil.getReviewManager(); try { - boolean isReviewCreated = reviewManager.addReview(review, uuid); + boolean isReviewCreated = reviewManager.addReview(reviewWrapper, uuid); if (isReviewCreated) { - return Response.status(Response.Status.CREATED).entity(review).build(); + return Response.status(Response.Status.CREATED).entity(reviewWrapper).build(); } else { - String msg = "Given review is not valid. Please check the review payload."; + String msg = "Given reviewTmp is not valid. Please check the reviewTmp payload."; log.error(msg); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } @@ -94,14 +94,42 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI { log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (ReviewManagementException e) { - String msg = "Error occurred while creating the review"; + String msg = "Error occurred while creating the reviewTmp"; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } catch (RequestValidatingException e) { - String msg = - "Error occurred while adding for application release. UUID of the application release: " + uuid; + } catch (ApplicationManagementException e) { + String msg = "Error occured while accessing application release for UUID: " + uuid; log.error(msg, e); - return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } + + @Override + @POST + @Consumes("application/json") + @Path("/{uuid}/{parentReviewId}") + public Response addReplyComment( + @ApiParam ReviewWrapper reviewWrapper, + @PathParam("uuid") String uuid, + @PathParam("parentReviewId") int parentReviewId) { + ReviewManager reviewManager = APIUtil.getReviewManager(); + try { + boolean isRepliedForReview = reviewManager.addReplyComment(reviewWrapper, uuid, parentReviewId); + if (isRepliedForReview) { + return Response.status(Response.Status.CREATED).entity(reviewWrapper).build(); + } else { + String msg = "Given reviewTmp is not valid. Please check the reviewTmp payload."; + log.error(msg); + 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) { + String msg = "Error occurred while creating the reviewTmp"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (ApplicationManagementException e) { String msg = "Error occured while accessing application release for UUID: " + uuid; log.error(msg, e); @@ -114,13 +142,13 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI { @Consumes("application/json") @Path("/{uuid}/{reviewId}") public Response updateReview( - @ApiParam Review review, + @ApiParam ReviewWrapper updatingReview, @PathParam("uuid") String uuid, @PathParam("reviewId") int reviewId) { ReviewManager reviewManager = APIUtil.getReviewManager(); try { - if (reviewManager.updateReview(review, reviewId, uuid, null)) { - return Response.status(Response.Status.OK).entity(review).build(); + if (reviewManager.updateReview(updatingReview, reviewId, uuid)) { + return Response.status(Response.Status.OK).entity(updatingReview).build(); } else { String msg = "Review updating failed. Please contact the administrator"; log.error(msg); @@ -130,11 +158,18 @@ 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; + } catch (NotFoundException e) { + String msg = "Couldn't found application release data for UUID " + uuid + " or Review for review ID: " + reviewId; log.error(msg, e); - return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); - } + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); + } catch (ForbiddenException e) { + String msg = "You dont have permission to update application release review."; + log.error(msg, e); + return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); + } catch (ApplicationManagementException e) { + String msg = "Error occurred when getting application release data for application release UUID:." + uuid; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } @Override @@ -147,9 +182,9 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI { ReviewManager reviewManager = APIUtil.getReviewManager(); try { if (reviewManager.deleteReview(uuid, reviewId)) { - return Response.status(Response.Status.OK).entity("Review is deleted successfully.").build(); + return Response.status(Response.Status.OK).entity("ReviewTmp is deleted successfully.").build(); } else { - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Review deleting is failed.") + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("ReviewTmp deleting is failed.") .build(); } } catch (ReviewManagementException e) { @@ -173,7 +208,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI { try { rating = reviewManager.getRating(uuid); } catch (ReviewManagementException e) { - log.error("Review Management Exception occurs", e); + log.error("ReviewTmp Management Exception occurs", e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } return Response.status(Response.Status.OK).entity(rating).build(); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/test/java/org/wso2/carbon/device/application/mgt/store/api/services/util/CommentMgtTestHelper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/test/java/org/wso2/carbon/device/application/mgt/store/api/services/util/CommentMgtTestHelper.java index 5cd0418f1e..c6b6b5f2a6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/test/java/org/wso2/carbon/device/application/mgt/store/api/services/util/CommentMgtTestHelper.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/test/java/org/wso2/carbon/device/application/mgt/store/api/services/util/CommentMgtTestHelper.java @@ -17,34 +17,34 @@ */ package org.wso2.carbon.device.application.mgt.store.api.services.util; -import org.wso2.carbon.device.application.mgt.common.Review; +import org.wso2.carbon.device.application.mgt.common.ReviewTmp; /** - * Helper class for Review Management API test cases. + * Helper class for ReviewTmp Management API test cases. */ public class CommentMgtTestHelper { - private static final String COMMENT_TEXT = "Dummy Review"; + private static final String COMMENT_TEXT = "Dummy ReviewTmp"; private static final String CREATED_BY = "TEST_CREATED_BY"; private static final String MODIFIED_BY = "TEST_MODIFIED_BY"; private static final int PARENT_ID = 123; private static final int COMMENT_ID = 1; /** - * Creates a Review with given text and given uuid. - * If the text is null, the COMMENT_TEXT will be used as the Dummy Review. + * Creates a ReviewTmp with given text and given uuid. + * If the text is null, the COMMENT_TEXT will be used as the Dummy ReviewTmp. * - * @param commentText : Text of the Review - * @return Review + * @param commentText : Text of the ReviewTmp + * @return ReviewTmp */ - public static Review getDummyComment(String commentText, String uuid) { - Review review = new Review(); - review.setId(COMMENT_ID); - review.setUsername(CREATED_BY); - review.setComment(commentText != null ? commentText : COMMENT_TEXT); + public static ReviewTmp getDummyComment(String commentText, String uuid) { + ReviewTmp reviewTmp = new ReviewTmp(); + reviewTmp.setId(COMMENT_ID); + reviewTmp.setUsername(CREATED_BY); + reviewTmp.setComment(commentText != null ? commentText : COMMENT_TEXT); - return review; + return reviewTmp; } } diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index 5450d3941d..b060ec7652 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -55,7 +55,8 @@ CREATE TABLE IF NOT EXISTS AP_APP_REVIEW( ID INTEGER NOT NULL AUTO_INCREMENT, TENANT_ID INTEGER NOT NULL, COMMENT VARCHAR(250) NOT NULL, - REPLY_COMMENT VARCHAR(250) NULL, + ROOT_PARENT_ID INTEGER NOT NULL, + IMMEDIATE_PARENT_ID INTEGER NOT NULL, CREATED_AT TIMESTAMP NOT NULL, MODIFIED_AT TIMESTAMP NOT NULL, RATING INTEGER NULL,