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    import java.util.Date;
023    
024    public class Violation extends Model {
025    
026      private String message = null;
027      private String severity = null;
028      private Integer line = null;
029      private String ruleKey = null;
030      private String ruleName = null;
031      private String resourceKey = null;
032      private String resourceName = null;
033      private String resourceScope = null;
034      private String resourceQualifier = null;
035      private Date createdAt = null;
036      private boolean switchedOff;
037      private Review review = null;
038    
039      public String getMessage() {
040        return message;
041      }
042    
043      public void setMessage(String message) {
044        this.message = message;
045      }
046    
047      /**
048       * @since 2.5
049       */
050      public String getSeverity() {
051        return severity;
052      }
053    
054      /**
055       * @since 2.5
056       */
057      public void setSeverity(String severity) {
058        this.severity = severity;
059      }
060    
061      /**
062       * @deprecated since 2.5 use {@link #getSeverity()} instead. See http://jira.codehaus.org/browse/SONAR-1829
063       */
064      @Deprecated
065      public String getPriority() {
066        return severity;
067      }
068    
069      /**
070       * @deprecated since 2.5 use {@link #setSeverity(String)} instead. See http://jira.codehaus.org/browse/SONAR-1829
071       */
072      @Deprecated
073      public void setPriority(String priority) {
074        this.severity = priority;
075      }
076    
077      /**
078       * @return line number (numeration starts from 1), or <code>null</code> if violation doesn't belong to concrete line
079       * @see #hasLine()
080       */
081      public Integer getLine() {
082        return line;
083      }
084    
085      public void setLine(Integer line) {
086        if (line != null && line < 1) {
087          /*
088           * This shouldn't happen, however line would be normalized to null if web service returns incorrect value (less than 1)
089           * in compliance with a contract for getLine method. Normalization added in 2.8 - see http://jira.codehaus.org/browse/SONAR-2386
090           */
091          this.line = null;
092        } else {
093          this.line = line;
094        }
095      }
096    
097      /**
098       * @return <code>true<code> if violation belongs to concrete line
099       * @since 2.8
100       */
101      public boolean hasLine() {
102        return line != null;
103      }
104    
105      public String getResourceKey() {
106        return resourceKey;
107      }
108    
109      public void setResourceKey(String resourceKey) {
110        this.resourceKey = resourceKey;
111      }
112    
113      public String getRuleKey() {
114        return ruleKey;
115      }
116    
117      public Violation setRuleKey(String s) {
118        this.ruleKey = s;
119        return this;
120      }
121    
122      public String getRuleName() {
123        return ruleName;
124      }
125    
126      public Violation setRuleName(String ruleName) {
127        this.ruleName = ruleName;
128        return this;
129      }
130    
131      public String getResourceName() {
132        return resourceName;
133      }
134    
135      public Violation setResourceName(String resourceName) {
136        this.resourceName = resourceName;
137        return this;
138      }
139    
140      public String getResourceScope() {
141        return resourceScope;
142      }
143    
144      public Violation setResourceScope(String resourceScope) {
145        this.resourceScope = resourceScope;
146        return this;
147      }
148    
149      public String getResourceQualifier() {
150        return resourceQualifier;
151      }
152    
153      public Violation setResourceQualifier(String resourceQualifier) {
154        this.resourceQualifier = resourceQualifier;
155        return this;
156      }
157    
158      /**
159       * @since 2.5
160       */
161      public Date getCreatedAt() {
162        return createdAt;
163      }
164    
165      /**
166       * @since 2.5
167       */
168      public Violation setCreatedAt(Date createdAt) {
169        this.createdAt = createdAt;
170        return this;
171      }
172    
173      /**
174       * @since 2.5
175       */
176      public boolean isCreatedAfter(Date date) {
177        return createdAt != null && date != null && createdAt.after(date);
178      }
179    
180      /**
181       * @since 2.8
182       */
183      public Violation setSwitchedOff(Boolean b) {
184        this.switchedOff = (b != null && b);
185        return this;
186      }
187    
188      /**
189       * @since 2.8
190       */
191      public boolean isSwitchedOff() {
192        return switchedOff;
193      }
194    
195      /**
196       * @since 2.8
197       */
198      public Review getReview() {
199        return review;
200      }
201    
202      /**
203       * @since 2.8
204       */
205      public Violation setReview(Review review) {
206        this.review = review;
207        return this;
208      }
209    }