aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client/src/main/java/org/sonar/wsclient
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2011-04-28 08:50:54 +0200
committerFabrice Bellingard <bellingard@gmail.com>2011-04-28 15:15:49 +0200
commitc3fabd05ae340704746d2b3be87b584bdd0da475 (patch)
treedab8469d0b567c7b34cd8a87498cbf974b173ad5 /sonar-ws-client/src/main/java/org/sonar/wsclient
parent50a43f7b9dab293b61fabe742252dca659f2e4ca (diff)
downloadsonarqube-c3fabd05ae340704746d2b3be87b584bdd0da475.tar.gz
sonarqube-c3fabd05ae340704746d2b3be87b584bdd0da475.zip
SONAR-2382 Create a new "reviews" web service API
Diffstat (limited to 'sonar-ws-client/src/main/java/org/sonar/wsclient')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Review.java261
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java242
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java6
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshaller.java57
4 files changed, 566 insertions, 0 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
new file mode 100644
index 00000000000..e2c1756d726
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Review.java
@@ -0,0 +1,261 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @since 2.8
+ */
+public class Review extends Model {
+
+ private Long id;
+ private Date createdAt = null;
+ private Date updatedAt = null;
+ private String authorLogin = null;
+ private String assigneeLogin = null;
+ private String title = null;
+ private String type = null;
+ private String status = null;
+ private String severity = null;
+ private String resourceKee = null;
+ private Integer line = null;
+ private List<Review.Comment> comments = new ArrayList<Review.Comment>();
+
+ /**
+ * @return the id
+ */
+ public Long getId() {
+ return id;
+ }
+
+ /**
+ * @param id
+ * the id to set
+ */
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the createdAt
+ */
+ public Date getCreatedAt() {
+ return createdAt;
+ }
+
+ /**
+ * @param createdAt
+ * the createdAt to set
+ */
+ public void setCreatedAt(Date createdAt) {
+ this.createdAt = createdAt;
+ }
+
+ /**
+ * @return the updatedAt
+ */
+ public Date getUpdatedAt() {
+ return updatedAt;
+ }
+
+ /**
+ * @param updatedAt
+ * the updatedAt to set
+ */
+ public void setUpdatedAt(Date updatedAt) {
+ this.updatedAt = updatedAt;
+ }
+
+ /**
+ * @return the authorLogin
+ */
+ public String getAuthorLogin() {
+ return authorLogin;
+ }
+
+ /**
+ * @param authorLogin
+ * the authorLogin to set
+ */
+ public void setAuthorLogin(String authorLogin) {
+ this.authorLogin = authorLogin;
+ }
+
+ /**
+ * @return the assigneeLogin
+ */
+ public String getAssigneeLogin() {
+ return assigneeLogin;
+ }
+
+ /**
+ * @param assigneeLogin
+ * the assigneeLogin to set
+ */
+ public void setAssigneeLogin(String assigneeLogin) {
+ this.assigneeLogin = assigneeLogin;
+ }
+
+ /**
+ * @return the title
+ */
+ public String getTitle() {
+ return title;
+ }
+
+ /**
+ * @param title
+ * the title to set
+ */
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ /**
+ * @return the type
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * @param type
+ * the type to set
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ /**
+ * @return the status
+ */
+ public String getStatus() {
+ return status;
+ }
+
+ /**
+ * @param status
+ * the status to set
+ */
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ /**
+ * @return the severity
+ */
+ public String getSeverity() {
+ return severity;
+ }
+
+ /**
+ * @param severity
+ * the severity to set
+ */
+ public void setSeverity(String severity) {
+ this.severity = severity;
+ }
+
+ /**
+ * @return the resourceKee
+ */
+ public String getResourceKee() {
+ return resourceKee;
+ }
+
+ /**
+ * @param resourceKee
+ * the resourceKee to set
+ */
+ public void setResourceKee(String resourceKee) {
+ this.resourceKee = resourceKee;
+ }
+
+ /**
+ * @return the line
+ */
+ public Integer getLine() {
+ return line;
+ }
+
+ /**
+ * @param line
+ * the line to set
+ */
+ public void setLine(Integer line) {
+ this.line = line;
+ }
+
+ /**
+ * @return the comments
+ */
+ public List<Review.Comment> getComments() {
+ return comments;
+ }
+
+ /**
+ * @param comments
+ * the comments to set
+ */
+ public void addComments(Date updatedAt, String authorLogin, String text) {
+ this.comments.add(new Review.Comment(updatedAt, authorLogin, text));
+ }
+
+ /**
+ * @since 2.8
+ */
+ public class Comment extends Model {
+
+ private String authorLogin = null;
+ private Date updatedAt = null;
+ private String text = null;
+
+ private Comment(Date updatedAt, String authorLogin, String text) {
+ this.updatedAt = updatedAt;
+ this.authorLogin = authorLogin;
+ this.text = text;
+ }
+
+ /**
+ * @return the authorLogin
+ */
+ public String getAuthorLogin() {
+ return authorLogin;
+ }
+
+ /**
+ * @return the updatedAt
+ */
+ public Date getUpdatedAt() {
+ return updatedAt;
+ }
+
+ /**
+ * @return the text
+ */
+ public String getText() {
+ return text;
+ }
+ }
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java
new file mode 100644
index 00000000000..0df5e0195d4
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java
@@ -0,0 +1,242 @@
+/*
+ * 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.8
+ */
+public class ReviewQuery extends Query<Review> {
+
+ public static final String BASE_URL = "/api/reviews";
+
+ private String reviewType;
+ private Long id;
+ private Long[] ids;
+ private String[] statuses;
+ private String[] severities;
+ private Long[] projects;
+ private Long[] resources;
+ private Long[] authors;
+ private Long[] assignees;
+ private Boolean html;
+
+ public ReviewQuery() {
+ }
+
+ /**
+ * @return the reviewType
+ */
+ public String getReviewType() {
+ return reviewType;
+ }
+
+ /**
+ * @param reviewType
+ * the reviewType to set
+ */
+ public ReviewQuery setReviewType(String reviewType) {
+ this.reviewType = reviewType;
+ return this;
+ }
+
+ /**
+ * @return the id
+ */
+ public Long getId() {
+ return id;
+ }
+
+ /**
+ * @param id
+ * the id to set
+ */
+ public ReviewQuery setId(Long id) {
+ this.id = id;
+ return this;
+ }
+
+ /**
+ * @return the ids
+ */
+ public Long[] getIds() {
+ return ids;
+ }
+
+ /**
+ * @param ids
+ * the ids to set
+ */
+ public ReviewQuery setIds(Long... ids) {
+ this.ids = ids;
+ return this;
+ }
+
+ /**
+ * @return the statuses
+ */
+ public String[] getStatuses() {
+ return statuses;
+ }
+
+ /**
+ * @param statuses
+ * the statuses to set
+ */
+ public ReviewQuery setStatuses(String... statuses) {
+ this.statuses = statuses;
+ return this;
+ }
+
+ /**
+ * @return the severities
+ */
+ public String[] getSeverities() {
+ return severities;
+ }
+
+ /**
+ * @param severities
+ * the severities to set
+ */
+ public ReviewQuery setSeverities(String... severities) {
+ this.severities = severities;
+ return this;
+ }
+
+ /**
+ * @return the projects
+ */
+ public Long[] getProjects() {
+ return projects;
+ }
+
+ /**
+ * Specify the IDs of the projects.
+ *
+ * @param projects
+ * the project IDs to set
+ */
+ public ReviewQuery setProjects(Long... projects) {
+ this.projects = projects;
+ return this;
+ }
+
+ /**
+ * @return the resources
+ */
+ public Long[] getResources() {
+ return resources;
+ }
+
+ /**
+ * Specify the IDs of the resources.
+ *
+ * @param resources
+ * the resource IDs to set
+ */
+ public ReviewQuery setResources(Long... resources) {
+ this.resources = resources;
+ return this;
+ }
+
+ /**
+ * @return the authors
+ */
+ public Long[] getAuthors() {
+ return authors;
+ }
+
+ /**
+ * Specify the IDs of the authors.
+ *
+ * @param authors
+ * the author IDs to set
+ */
+ public ReviewQuery setAuthors(Long... authors) {
+ this.authors = authors;
+ return this;
+ }
+
+ /**
+ * @return the assignees
+ */
+ public Long[] getAssignees() {
+ return assignees;
+ }
+
+ /**
+ * Specify the IDs of the assignees.
+ *
+ * @param assignees
+ * the assignee IDs to set
+ */
+ public ReviewQuery setAssignees(Long... assignees) {
+ this.assignees = assignees;
+ return this;
+ }
+
+ /**
+ * @return the html
+ */
+ public Boolean getHtml() {
+ return html;
+ }
+
+ /**
+ * If true, the comments will be generated in HTML. Otherwise, they will be in raw text.
+ *
+ * @param html the html to set
+ */
+ public ReviewQuery setHtml(Boolean html) {
+ this.html = html;
+ return this;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder url = new StringBuilder(BASE_URL);
+ url.append('?');
+ if (id != null) {
+ appendUrlParameter(url, "id", id);
+ } else if (ids != null) {
+ appendUrlParameter(url, "ids", ids);
+ }
+ appendUrlParameter(url, "review_type", reviewType);
+ appendUrlParameter(url, "statuses", statuses);
+ appendUrlParameter(url, "severities", severities);
+ appendUrlParameter(url, "projects", projects);
+ appendUrlParameter(url, "resources", resources);
+ appendUrlParameter(url, "authors", authors);
+ appendUrlParameter(url, "assignees", assignees);
+ appendUrlParameter(url, "html", html);
+
+ return url.toString();
+ }
+
+ @Override
+ public Class<Review> getModelClass() {
+ return Review.class;
+ }
+
+ public static ReviewQuery createForResource(Resource resource) {
+ return new ReviewQuery().setId(new Long(resource.getId()));
+ }
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java
index d077ac97495..1c74a823b52 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java
@@ -192,10 +192,16 @@ public class Violation extends Model {
return switchedOff;
}
+ /**
+ * @since 2.8
+ */
public Long getReviewId() {
return reviewId;
}
+ /**
+ * @since 2.8
+ */
public Violation setReviewId(Long l) {
this.reviewId = l;
return this;
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
new file mode 100644
index 00000000000..cdaf3c2bb63
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshaller.java
@@ -0,0 +1,57 @@
+/*
+ * 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.unmarshallers;
+
+import org.sonar.wsclient.services.Review;
+import org.sonar.wsclient.services.WSUtils;
+
+/**
+ * @since 2.8
+ */
+public class ReviewUnmarshaller extends AbstractUnmarshaller<Review> {
+
+ @Override
+ protected Review parse(Object json) {
+ WSUtils utils = WSUtils.getINSTANCE();
+
+ Review review = new Review();
+ review.setId(utils.getLong(json, "id"));
+ review.setCreatedAt(utils.getDateTime(json, "createdAt"));
+ review.setUpdatedAt(utils.getDateTime(json, "updatedAt"));
+ review.setAuthorLogin(utils.getString(json, "author"));
+ review.setAssigneeLogin(utils.getString(json, "assignee"));
+ review.setTitle(utils.getString(json, "title"));
+ review.setType(utils.getString(json, "type"));
+ review.setStatus(utils.getString(json, "status"));
+ review.setSeverity(utils.getString(json, "severity"));
+ review.setResourceKee(utils.getString(json, "resource"));
+ review.setLine(utils.getInteger(json, "line"));
+
+ Object comments = utils.getField(json, "comments");
+ if (comments != null) {
+ for (int i = 0; i < utils.getArraySize(comments); i++) {
+ Object comment = utils.getArrayElement(comments, i);
+ review.addComments(utils.getDateTime(comment, "updatedAt"), utils.getString(comment, "author"), utils.getString(comment, "text"));
+ }
+ }
+
+ return review;
+ }
+}