|
|
@ -172,8 +172,12 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ReviewDTO replyComment = reviewWrapperToDO(reviewWrapper);
|
|
|
|
ReviewDTO replyComment = reviewWrapperToDO(reviewWrapper);
|
|
|
|
replyComment.setUsername(username);
|
|
|
|
replyComment.setUsername(username);
|
|
|
|
replyComment.setRootParentId(parentReview.getRootParentId());
|
|
|
|
|
|
|
|
replyComment.setImmediateParentId(parentReview.getId());
|
|
|
|
replyComment.setImmediateParentId(parentReview.getId());
|
|
|
|
|
|
|
|
if (parentReview.getRootParentId() == -1) {
|
|
|
|
|
|
|
|
replyComment.setRootParentId(parentReview.getId());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
replyComment.setRootParentId(parentReview.getRootParentId());
|
|
|
|
|
|
|
|
}
|
|
|
|
if (this.reviewDAO.addReview(replyComment, applicationReleaseDTO.getId(), tenantId)) {
|
|
|
|
if (this.reviewDAO.addReview(replyComment, applicationReleaseDTO.getId(), tenantId)) {
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
@ -214,12 +218,24 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
review.setImmediateParentId(reviewDTO.getImmediateParentId());
|
|
|
|
review.setImmediateParentId(reviewDTO.getImmediateParentId());
|
|
|
|
review.setCreatedAt(reviewDTO.getCreatedAt());
|
|
|
|
review.setCreatedAt(reviewDTO.getCreatedAt());
|
|
|
|
review.setModifiedAt(reviewDTO.getModifiedAt());
|
|
|
|
review.setModifiedAt(reviewDTO.getModifiedAt());
|
|
|
|
review.setReplyComments(new TreeMap<>());
|
|
|
|
review.setReplies(new ArrayList<>());
|
|
|
|
reviews.add(review);
|
|
|
|
reviews.add(review);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reviews;
|
|
|
|
return reviews;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Review reviewDTOToReview(ReviewDTO reviewDTO){
|
|
|
|
|
|
|
|
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.setReplies(new ArrayList<>());
|
|
|
|
|
|
|
|
return review;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean updateReview(ReviewWrapper updatingReview, int reviewId, String uuid)
|
|
|
|
public boolean updateReview(ReviewWrapper updatingReview, int reviewId, String uuid)
|
|
|
|
throws ReviewManagementException, ApplicationManagementException {
|
|
|
|
throws ReviewManagementException, ApplicationManagementException {
|
|
|
@ -283,38 +299,35 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
throws ReviewManagementException {
|
|
|
|
throws ReviewManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
PaginationResult paginationResult = new PaginationResult();
|
|
|
|
PaginationResult paginationResult = new PaginationResult();
|
|
|
|
int numOfComments;
|
|
|
|
TreeMap<Integer, ReviewNode<ReviewDTO>> reviewTree = new TreeMap<>();
|
|
|
|
TreeMap<Integer, ReviewNode<Review>> reviewTree = new TreeMap<>();
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Get all reviewTmps of the application release uuid: " + uuid);
|
|
|
|
log.debug("Get all reviewTmps of the application release uuid: " + uuid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
List<ReviewDTO> reviewDTOs= this.reviewDAO.getAllReviews(uuid, request, tenantId);
|
|
|
|
List<ReviewDTO> reviewDTOs= this.reviewDAO.getAllReviews(uuid, request, tenantId);
|
|
|
|
List<Review> reviews = reviewDTOToReview(reviewDTOs);
|
|
|
|
reviewDTOs.sort(Comparator.comparing(ReviewDTO::getId));
|
|
|
|
reviews.sort(Comparator.comparing(Review::getId));
|
|
|
|
|
|
|
|
|
|
|
|
for (ReviewDTO reviewDTO : reviewDTOs) {
|
|
|
|
for (Review review : reviews) {
|
|
|
|
if (reviewDTO.getRootParentId() == -1 && reviewDTO.getImmediateParentId() == -1) {
|
|
|
|
if (review.getRootParentId() == -1 && review.getImmediateParentId() == -1) {
|
|
|
|
ReviewNode<ReviewDTO> rootNode = new ReviewNode<>(reviewDTO);
|
|
|
|
ReviewNode<Review> rootNode = new ReviewNode<>(review);
|
|
|
|
reviewTree.put(reviewDTO.getId(), rootNode);
|
|
|
|
reviewTree.put(review.getId(), rootNode);
|
|
|
|
} else if (reviewTree.containsKey(reviewDTO.getImmediateParentId())) {
|
|
|
|
} else if (reviewTree.containsKey(review.getImmediateParentId())) {
|
|
|
|
ReviewNode<ReviewDTO> childNode = new ReviewNode<>(reviewDTO);
|
|
|
|
ReviewNode<Review> childNode = new ReviewNode<>(review);
|
|
|
|
reviewTree.get(reviewDTO.getImmediateParentId()).addChild(childNode);
|
|
|
|
reviewTree.get(review.getImmediateParentId()).addChild(childNode);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
reviewTree.put(review.getId(), findAndSetChild(reviewTree.get(review.getRootParentId()), review));
|
|
|
|
reviewTree.put(reviewDTO.getId(), findAndSetChild(reviewTree.get(reviewDTO.getRootParentId()), reviewDTO));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
numOfComments = reviewTree.size();
|
|
|
|
int numOfReviews = reviewTree.size();
|
|
|
|
if (numOfComments > 0) {
|
|
|
|
List<Review> results = new ArrayList<>();
|
|
|
|
paginationResult.setData(new ArrayList<>(reviewTree.values()));
|
|
|
|
|
|
|
|
paginationResult.setRecordsFiltered(numOfComments);
|
|
|
|
for (ReviewNode<ReviewDTO> reviewNode : reviewTree.values()){
|
|
|
|
paginationResult.setRecordsTotal(numOfComments);
|
|
|
|
results.add(printTree(null, reviewNode));
|
|
|
|
} else {
|
|
|
|
|
|
|
|
paginationResult.setData(new ArrayList<ReviewTmp>());
|
|
|
|
|
|
|
|
paginationResult.setRecordsFiltered(0);
|
|
|
|
|
|
|
|
paginationResult.setRecordsTotal(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
paginationResult.setData(new ArrayList<>(results));
|
|
|
|
|
|
|
|
paginationResult.setRecordsFiltered(numOfReviews);
|
|
|
|
|
|
|
|
paginationResult.setRecordsTotal(numOfReviews);
|
|
|
|
return paginationResult;
|
|
|
|
return paginationResult;
|
|
|
|
} catch (ReviewManagementDAOException e) {
|
|
|
|
} catch (ReviewManagementDAOException e) {
|
|
|
|
throw new ReviewManagementException("Error occured while getting all reviewTmps for application uuid: " + uuid,
|
|
|
|
throw new ReviewManagementException("Error occured while getting all reviewTmps for application uuid: " + uuid,
|
|
|
@ -326,16 +339,30 @@ public class ReviewManagerImpl implements ReviewManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ReviewNode<Review> findAndSetChild(ReviewNode<Review> node, Review review) {
|
|
|
|
private ReviewNode<ReviewDTO> findAndSetChild(ReviewNode<ReviewDTO> node, ReviewDTO reviewDTO) {
|
|
|
|
for (ReviewNode<Review> each : node.getChildren()) {
|
|
|
|
for (ReviewNode<ReviewDTO> each : node.getChildren()) {
|
|
|
|
if ((each.getData()).getId() == review.getImmediateParentId()) {
|
|
|
|
if ((each.getData()).getId() == reviewDTO.getImmediateParentId()) {
|
|
|
|
ReviewNode<Review> childNode = new ReviewNode<>(review);
|
|
|
|
ReviewNode<ReviewDTO> childNode = new ReviewNode<>(reviewDTO);
|
|
|
|
each.addChild(childNode);
|
|
|
|
each.addChild(childNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Review printTree(Review parentReview, ReviewNode<ReviewDTO> node) {
|
|
|
|
|
|
|
|
Review review = reviewDTOToReview(node.getData());
|
|
|
|
|
|
|
|
if (parentReview != null){
|
|
|
|
|
|
|
|
parentReview.getReplies().add(review);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node.getChildren().isEmpty()){
|
|
|
|
|
|
|
|
return review;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ReviewNode<ReviewDTO> reviewDTOReviewNode : node.getChildren()) {
|
|
|
|
|
|
|
|
printTree(review, reviewDTOReviewNode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return review;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean deleteReview(String uuid, int reviewId)
|
|
|
|
public boolean deleteReview(String uuid, int reviewId)
|
|
|
|
throws ReviewManagementException, ReviewDoesNotExistException {
|
|
|
|
throws ReviewManagementException, ReviewDoesNotExistException {
|
|
|
|