diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-06-23 17:50:52 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-06-27 20:26:26 +0400 |
commit | 595485bb2bf8b327cb50e24597894d97d28c178d (patch) | |
tree | a2cd2ba9563e2baf5e043a4ef64923a067be6817 /sonar-ws-client/src/main/java/org/sonar | |
parent | 7be54b4df2a55f180620775659bcd888f5249183 (diff) | |
download | sonarqube-595485bb2bf8b327cb50e24597894d97d28c178d.tar.gz sonarqube-595485bb2bf8b327cb50e24597894d97d28c178d.zip |
SONAR-2404 Refactor reviews API - web-service and sonar-ws-client
* Remove ability to edit and delete comments.
* Fix bug - comment should be transferred in body.
* Fix XML/JSON output - new attribute 'resolution'.
Diffstat (limited to 'sonar-ws-client/src/main/java/org/sonar')
5 files changed, 94 insertions, 330 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Review.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Review.java index 646e2b2a7a1..f399788eef3 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Review.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Review.java @@ -39,109 +39,84 @@ public class Review extends Model { private String severity = null; private String resourceKee = null; private Integer line = null; - private Boolean falsePositive = null; + private String resolution = null; private Long violationId; private List<Review.Comment> comments = new ArrayList<Review.Comment>(); /** - * @return the id + * @return id */ public Long getId() { return id; } - /** - * @param id - * the id to set - */ public Review setId(Long id) { this.id = id; return this; } /** - * @return the createdAt + * @return date of creation */ public Date getCreatedAt() { return createdAt; } - /** - * @param createdAt - * the createdAt to set - */ public Review setCreatedAt(Date createdAt) { this.createdAt = createdAt; return this; } /** - * @return the updatedAt + * @return date of last modification */ public Date getUpdatedAt() { return updatedAt; } - /** - * @param updatedAt - * the updatedAt to set - */ public Review setUpdatedAt(Date updatedAt) { this.updatedAt = updatedAt; return this; } /** - * @return the authorLogin + * @return user that initiated review */ public String getAuthorLogin() { return authorLogin; } - /** - * @param s - * the authorLogin to set - */ public Review setAuthorLogin(String s) { this.authorLogin = s; return this; } /** - * @return the assigneeLogin + * @return assignee */ public String getAssigneeLogin() { return assigneeLogin; } - /** - * @param s - * the assigneeLogin to set - */ public Review setAssigneeLogin(String s) { this.assigneeLogin = s; return this; } /** - * @return the title + * @return title */ public String getTitle() { return title; } - /** - * @param s - * the title to set - */ public Review setTitle(String s) { this.title = s; return this; } /** - * @deprecated since 2.9. Use {@link #getFalsePositive()} instead. - * @return the type + * @deprecated since 2.9. */ @Deprecated public String getType() { @@ -149,81 +124,57 @@ public class Review extends Model { } /** - * @deprecated since 2.9. Use {@link #setFalsePositive(Boolean)} instead. - * @param s - * the type to set + * @deprecated since 2.9. */ @Deprecated public Review setType(String s) { this.type = s; - // the following code is only here to ensure backward compatibility with 2.8 - if ("FALSE_POSITIVE".equals(type)) { - falsePositive = Boolean.TRUE; - } else if ("VIOLATION".equals(type)) { - falsePositive = Boolean.FALSE; - } return this; } /** - * @return the status + * @return status */ public String getStatus() { return status; } - /** - * @param status - * the status to set - */ public Review setStatus(String status) { this.status = status; return this; } /** - * @return the severity + * @return severity */ public String getSeverity() { return severity; } - /** - * @param severity - * the severity to set - */ public Review setSeverity(String severity) { this.severity = severity; return this; } /** - * @return the resourceKee + * @return resourceKee */ public String getResourceKee() { return resourceKee; } - /** - * @param resourceKee - * the resourceKee to set - */ public Review setResourceKee(String resourceKee) { this.resourceKee = resourceKee; return this; } /** - * @return the line + * @return line */ public Integer getLine() { return line; } - /** - * @param line - * the line to set - */ public Review setLine(Integer line) { this.line = line; return this; @@ -231,41 +182,34 @@ public class Review extends Model { /** * @since 2.9 - * @return the falsePositive */ - public Boolean getFalsePositive() { - return falsePositive; + public String getResolution() { + return resolution; } /** * @since 2.9 - * @param falsePositive - * true if false positive */ - public Review setFalsePositive(Boolean falsePositive) { - this.falsePositive = falsePositive; + public Review setResolution(String resolution) { + this.resolution = resolution; return this; } /** * @since 2.9 - * @return the violation id + * @return violation id */ public Long getViolationId() { return violationId; } - /** - * @param id - * the violation id to set - */ public Review setViolationId(Long violationId) { this.violationId = violationId; return this; } /** - * @return the comments + * @return comments */ public List<Review.Comment> getComments() { return comments; @@ -295,28 +239,28 @@ public class Review extends Model { /** * @since 2.9 - * @return the id + * @return id */ public Long getId() { return id; } /** - * @return the authorLogin + * @return user that created this comment */ public String getAuthorLogin() { return authorLogin; } /** - * @return the updatedAt + * @return date of last modification */ public Date getUpdatedAt() { return updatedAt; } /** - * @return the text + * @return text */ public String getText() { return text; diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewCreateQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewCreateQuery.java index f48eb971e19..11fc0b5afa3 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewCreateQuery.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewCreateQuery.java @@ -25,58 +25,14 @@ package org.sonar.wsclient.services; public class ReviewCreateQuery extends CreateQuery<Review> { private Long violationId; - private String text; + private String comment; private String assignee; - private Boolean falsePositive; + private String status; + private String resolution; public ReviewCreateQuery() { } - /** - * Builds a request that will create a simple review on a violation, without any assignee. - * - * @param violationId - * The id of the violation that is reviewed - * @param text - * The comment of the review - */ - public static ReviewCreateQuery createSimpleReviewQuery(Long violationId, String text) { - ReviewCreateQuery query = new ReviewCreateQuery(); - query.setText(text); - query.setViolationId(violationId); - return query; - } - - /** - * Builds a request that will create a simple review on a violation and that will be assigned to the given user. - * - * @param violationId - * The id of the violation that is reviewed - * @param text - * The comment of the review - * @param userLogin - * The login of the user whom this review will be assigned to - */ - public static ReviewCreateQuery createAssignedReviewQuery(Long violationId, String text, String userLogin) { - ReviewCreateQuery query = createSimpleReviewQuery(violationId, text); - query.setAssignee(userLogin); - return query; - } - - /** - * Builds a request that will create a false-positive review on a violation. - * - * @param violationId - * The id of the violation that is reviewed - * @param text - * The comment of the review - */ - public static ReviewCreateQuery createFalsePositiveReviewQuery(Long violationId, String text) { - ReviewCreateQuery query = createSimpleReviewQuery(violationId, text); - query.setFalsePositive(Boolean.TRUE); - return query; - } - public Long getViolationId() { return violationId; } @@ -86,12 +42,12 @@ public class ReviewCreateQuery extends CreateQuery<Review> { return this; } - public String getText() { - return text; + public String getComment() { + return comment; } - public ReviewCreateQuery setText(String text) { - this.text = text; + public ReviewCreateQuery setComment(String comment) { + this.comment = comment; return this; } @@ -104,34 +60,41 @@ public class ReviewCreateQuery extends CreateQuery<Review> { return this; } - public Boolean getFalsePositive() { - return falsePositive; + public String getStatus() { + return status; + } + + public ReviewCreateQuery setStatus(String status) { + this.status = status; + return this; + } + + public String getResolution() { + return resolution; } - public ReviewCreateQuery setFalsePositive(Boolean falsePositive) { - this.falsePositive = falsePositive; + public ReviewCreateQuery setResolution(String resolution) { + this.resolution = resolution; return this; } @Override public String getUrl() { StringBuilder url = new StringBuilder(); - url.append(ReviewQuery.BASE_URL); - url.append("/"); - url.append('?'); + url.append(ReviewQuery.BASE_URL).append('?'); appendUrlParameter(url, "violation_id", getViolationId()); - appendUrlParameter(url, "text", getText()); appendUrlParameter(url, "assignee", getAssignee()); - appendUrlParameter(url, "false_positive", getFalsePositive()); + appendUrlParameter(url, "status", getStatus()); + appendUrlParameter(url, "resolution", getResolution()); return url.toString(); } /** - * Property 'text' is transmitted through request body as content may exceed URL size allowed by the server. + * Property {@link #comment} is transmitted through request body as content may exceed URL size allowed by the server. */ @Override public String getBody() { - return text; + return comment; } @Override diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewDeleteQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewDeleteQuery.java deleted file mode 100644 index 5a217666607..00000000000 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewDeleteQuery.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * Sonar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.wsclient.services; - -/** - * @since 2.9 - */ -public class ReviewDeleteQuery extends DeleteQuery<Review> { - - private Long reviewId; - private Long commentId; - - public ReviewDeleteQuery() { - } - - /** - * Builds a request that will delete the comment of a review. For the moment, only the last comment can be deleted, and only the author of - * this comment is allowed to do so. - * - * @param reviewId - * the id of the review - * @param commentId - * the id of the comment to delete - */ - public static ReviewDeleteQuery deleteCommentQuery(Long reviewId, Long commentId) { - ReviewDeleteQuery query = new ReviewDeleteQuery(); - query.reviewId = reviewId; - query.commentId = commentId; - return query; - } - - public Long getReviewId() { - return reviewId; - } - - public ReviewDeleteQuery setReviewId(Long reviewId) { - this.reviewId = reviewId; - return this; - } - - public Long getCommentId() { - return commentId; - } - - public ReviewDeleteQuery setCommentId(Long commentId) { - this.commentId = commentId; - return this; - } - - @Override - public String getUrl() { - StringBuilder url = new StringBuilder(); - url.append(ReviewQuery.BASE_URL); - url.append("/"); - url.append('?'); - appendUrlParameter(url, "id", getReviewId()); - appendUrlParameter(url, "comment_id", getCommentId()); - return url.toString(); - } -} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewUpdateQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewUpdateQuery.java index 262cc9e4bfe..62e8cdd583a 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewUpdateQuery.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewUpdateQuery.java @@ -24,121 +24,63 @@ package org.sonar.wsclient.services; */ public class ReviewUpdateQuery extends UpdateQuery<Review> { - private Long reviewId; - private String text; - private String newText; + private long reviewId; + private String action; + private String comment; private String assignee; - private Boolean falsePositive; - private String status; - - public ReviewUpdateQuery() { - } + private String resolution; /** - * Builds a request that will add a comment on a an existing review. - * - * @param reviewId - * The id of the review - * @param text - * The new comment + * Creates query to add comment to review. */ - public static ReviewUpdateQuery addCommentQuery(Long reviewId, String text) { - ReviewUpdateQuery query = new ReviewUpdateQuery(); - query.setReviewId(reviewId); - query.setNewText(text); - return query; + public static ReviewUpdateQuery addComment(long id, String comment) { + return new ReviewUpdateQuery(id, "add_comment").setComment(comment); } /** - * Builds a request that will update the false-positive status of an existing review. - * - * @param reviewId - * The id of the review - * @param text - * The comment for this modification - * @param falsePositive - * the new false positive status of the review + * Creates query to reassign review. */ - public static ReviewUpdateQuery updateFalsePositiveQuery(Long reviewId, String text, Boolean falsePositive) { - ReviewUpdateQuery query = addCommentQuery(reviewId, text); - query.setFalsePositive(falsePositive); - return query; + public static ReviewUpdateQuery reassign(long id, String assignee) { + return new ReviewUpdateQuery(id, "reassign").setAssignee(assignee); } /** - * Builds a request that will reassign an existing review to the given user. <br/> - * <br/> - * To unassign the review, simply pass "none" for the user login. + * Creates query to resolve review. + * If resolution "FALSE-POSITIVE", then you must provide comment using {@link #setComment(String)}. + * Otherwise comment is optional. * - * @param reviewId - * The id of the review that is reviewed - * @param userLogin - * The login of the user whom this review will be assigned to, or "none" to unassign + * @param resolution + * can be "FIXED" or "FALSE-POSITIVE" */ - public static ReviewUpdateQuery reassignQuery(Long reviewId, String userLogin) { - ReviewUpdateQuery query = new ReviewUpdateQuery(); - query.setReviewId(reviewId); - query.setAssignee(userLogin); - return query; + public static ReviewUpdateQuery resolve(long id, String resolution) { + return new ReviewUpdateQuery(id, "resolve").setResolution(resolution); } /** - * Builds a request that will edit the last comment of a an existing review (if the last comment belongs to the current user). - * - * @param reviewId - * The id of the review - * @param text - * The new text for the last comment + * Creates query to reopen review. + * If review was resolved as "FALSE-POSITIVE", then you must provide comment using {@link #setComment(String)}. + * Otherwise comment is optional. */ - public static ReviewUpdateQuery editLastCommentQuery(Long reviewId, String text) { - ReviewUpdateQuery query = new ReviewUpdateQuery(); - query.setReviewId(reviewId); - query.setText(text); - return query; + public static ReviewUpdateQuery reopen(long id) { + return new ReviewUpdateQuery(id, "reopen"); } - /** - * Builds a request that will change the status of a an existing review.<br/> - * <br/> - * Currently, only "RESOLVED" and "REOPENED" are supported. - * - * @param reviewId - * The id of the review - * @param status - * The new status - */ - public static ReviewUpdateQuery changeStatusQuery(Long reviewId, String status) { - ReviewUpdateQuery query = new ReviewUpdateQuery(); - query.setReviewId(reviewId); - query.setStatus(status); - return query; + private ReviewUpdateQuery(long id, String action) { + this.reviewId = id; + this.action = action; } - public Long getReviewId() { + public long getReviewId() { return reviewId; } - public ReviewUpdateQuery setReviewId(Long reviewId) { - this.reviewId = reviewId; + public ReviewUpdateQuery setComment(String comment) { + this.comment = comment; return this; } - public String getText() { - return text; - } - - public ReviewUpdateQuery setText(String text) { - this.text = text; - return this; - } - - public String getNewText() { - return newText; - } - - public ReviewUpdateQuery setNewText(String text) { - this.newText = text; - return this; + public String getComment() { + return comment; } public String getAssignee() { @@ -150,45 +92,37 @@ public class ReviewUpdateQuery extends UpdateQuery<Review> { return this; } - public Boolean getFalsePositive() { - return falsePositive; + public String getResolution() { + return resolution; } - public ReviewUpdateQuery setFalsePositive(Boolean falsePositive) { - this.falsePositive = falsePositive; - return this; - } - - public String getStatus() { - return status; - } - - public ReviewUpdateQuery setStatus(String status) { - this.status = status; + /** + * @param resolution + * can be "FIXED" or "FALSE-POSITIVE" + */ + public ReviewUpdateQuery setResolution(String resolution) { + this.resolution = resolution; return this; } @Override public String getUrl() { StringBuilder url = new StringBuilder(); - url.append(ReviewQuery.BASE_URL); - url.append("/"); - url.append('?'); - appendUrlParameter(url, "id", getReviewId()); - appendUrlParameter(url, "text", getText()); - appendUrlParameter(url, "new_text", getNewText()); + url.append(ReviewQuery.BASE_URL) + .append('/').append(action) + .append('/').append(reviewId) + .append('?'); appendUrlParameter(url, "assignee", getAssignee()); - appendUrlParameter(url, "false_positive", getFalsePositive()); - appendUrlParameter(url, "status", getStatus()); + appendUrlParameter(url, "resolution", getResolution()); return url.toString(); } /** - * Properties 'text' or 'new_text' are transmitted through request body as content may exceed URL size allowed by the server. + * Property {@link #comment} transmitted through request body as content may exceed URL size allowed by the server. */ @Override public String getBody() { - return text == null ? newText : text; + return comment; } @Override diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshaller.java index 3ea023700ea..a757c551a0d 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshaller.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshaller.java @@ -42,7 +42,7 @@ public class ReviewUnmarshaller extends AbstractUnmarshaller<Review> { review.setSeverity(utils.getString(json, "severity")); review.setResourceKee(utils.getString(json, "resource")); review.setLine(utils.getInteger(json, "line")); - review.setFalsePositive(utils.getBoolean(json, "falsePositive")); + review.setResolution(utils.getString(json, "resolution")); review.setViolationId(utils.getLong(json, "violationId")); review.setType(utils.getString(json, "type")); |