001    /*
002     * Sonar, open source software quality management tool.
003     * Copyright (C) 2008-2011 SonarSource
004     * mailto:contact AT sonarsource DOT com
005     *
006     * Sonar is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU Lesser General Public
008     * License as published by the Free Software Foundation; either
009     * version 3 of the License, or (at your option) any later version.
010     *
011     * Sonar is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014     * Lesser General Public License for more details.
015     *
016     * You should have received a copy of the GNU Lesser General Public
017     * License along with Sonar; if not, write to the Free Software
018     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
019     */
020    package org.sonar.wsclient.services;
021    
022    /**
023     * @since 2.9
024     */
025    public class ReviewUpdateQuery extends UpdateQuery<Review> {
026    
027      private long reviewId;
028      private String action;
029      private String comment;
030      private String assignee;
031      private String resolution;
032    
033      /**
034       * Creates query to add comment to review.
035       */
036      public static ReviewUpdateQuery addComment(long id, String comment) {
037        return new ReviewUpdateQuery(id, "add_comment").setComment(comment);
038      }
039    
040      /**
041       * Creates query to reassign review.
042       */
043      public static ReviewUpdateQuery reassign(long id, String assignee) {
044        return new ReviewUpdateQuery(id, "reassign").setAssignee(assignee);
045      }
046    
047      /**
048       * Creates query to resolve review.
049       * If resolution "FALSE-POSITIVE", then you must provide comment using {@link #setComment(String)}.
050       * Otherwise comment is optional.
051       * 
052       * @param resolution
053       *          can be "FIXED" or "FALSE-POSITIVE"
054       */
055      public static ReviewUpdateQuery resolve(long id, String resolution) {
056        return new ReviewUpdateQuery(id, "resolve").setResolution(resolution);
057      }
058    
059      /**
060       * Creates query to reopen review.
061       * If review was resolved as "FALSE-POSITIVE", then you must provide comment using {@link #setComment(String)}.
062       * Otherwise comment is optional.
063       */
064      public static ReviewUpdateQuery reopen(long id) {
065        return new ReviewUpdateQuery(id, "reopen");
066      }
067    
068      private ReviewUpdateQuery(long id, String action) {
069        this.reviewId = id;
070        this.action = action;
071      }
072    
073      public long getReviewId() {
074        return reviewId;
075      }
076    
077      public ReviewUpdateQuery setComment(String comment) {
078        this.comment = comment;
079        return this;
080      }
081    
082      public String getComment() {
083        return comment;
084      }
085    
086      public String getAssignee() {
087        return assignee;
088      }
089    
090      public ReviewUpdateQuery setAssignee(String userLogin) {
091        this.assignee = userLogin;
092        return this;
093      }
094    
095      public String getResolution() {
096        return resolution;
097      }
098    
099      /**
100       * @param resolution
101       *          can be "FIXED" or "FALSE-POSITIVE"
102       */
103      public ReviewUpdateQuery setResolution(String resolution) {
104        this.resolution = resolution;
105        return this;
106      }
107    
108      @Override
109      public String getUrl() {
110        StringBuilder url = new StringBuilder();
111        url.append(ReviewQuery.BASE_URL)
112            .append('/').append(action)
113            .append('/').append(reviewId)
114            .append('?');
115        appendUrlParameter(url, "assignee", getAssignee());
116        appendUrlParameter(url, "resolution", getResolution());
117        return url.toString();
118      }
119    
120      /**
121       * Property {@link #comment} transmitted through request body as content may exceed URL size allowed by the server.
122       */
123      @Override
124      public String getBody() {
125        return comment;
126      }
127    
128      @Override
129      public Class<Review> getModelClass() {
130        return Review.class;
131      }
132    }