001 /*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube 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 * SonarQube 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 License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
019 */
020 package org.sonar.wsclient.services;
021
022 import java.util.Date;
023
024 public class EventQuery extends Query<Event> {
025 public static final String BASE_URL = "/api/events";
026
027 private String resourceKey;
028 private String[] categories;
029 private Date fromDate;
030 private boolean includeFromTime;
031 private Date toDate;
032 private boolean includeToTime;
033
034 public EventQuery() {
035 }
036
037 public EventQuery(String resourceKey) {
038 this.resourceKey = resourceKey;
039 }
040
041 public Date getFrom() {
042 return fromDate;
043 }
044
045 public EventQuery setFrom(Date fromDate, boolean includeTime) {
046 this.fromDate = fromDate;
047 this.includeFromTime = includeTime;
048 return this;
049 }
050
051 public boolean isIncludeFromTime() {
052 return includeFromTime;
053 }
054
055 public Date getTo() {
056 return toDate;
057 }
058
059 public EventQuery setTo(Date toDate, boolean includeTime) {
060 this.toDate = toDate;
061 this.includeToTime = includeTime;
062 return this;
063 }
064
065 public boolean isIncludeToTime() {
066 return includeToTime;
067 }
068
069 public String getResourceKey() {
070 return resourceKey;
071 }
072
073 public EventQuery setResourceKey(String resourceKey) {
074 this.resourceKey = resourceKey;
075 return this;
076 }
077
078 public String[] getCategories() {
079 return categories;
080 }
081
082 public EventQuery setCategories(String[] categories) {
083 this.categories = categories;
084 return this;
085 }
086
087 @Override
088 public String getUrl() {
089 StringBuilder url = new StringBuilder(BASE_URL);
090 url.append('?');
091 appendUrlParameter(url, "resource", resourceKey);
092 appendUrlParameter(url, "categories", categories);
093 if (fromDate != null) {
094 if (includeFromTime) {
095 appendUrlParameter(url, "fromDateTime", fromDate, true);
096 } else {
097 appendUrlParameter(url, "fromDate", fromDate, false);
098 }
099 }
100 if (toDate != null) {
101 if (includeToTime) {
102 appendUrlParameter(url, "toDateTime", toDate, true);
103 } else {
104 appendUrlParameter(url, "toDate", toDate, false);
105 }
106 }
107 return url.toString();
108 }
109
110 @Override
111 public Class<Event> getModelClass() {
112 return Event.class;
113 }
114 }