001/* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2008-2012 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 */ 020package org.sonar.api.workflow.internal; 021 022import com.google.common.annotations.Beta; 023import com.google.common.base.Preconditions; 024import com.google.common.base.Strings; 025import com.google.common.collect.Lists; 026import com.google.common.collect.Maps; 027import org.apache.commons.lang.builder.ReflectionToStringBuilder; 028import org.apache.commons.lang.builder.ToStringStyle; 029import org.sonar.api.workflow.Comment; 030import org.sonar.api.workflow.MutableReview; 031import org.sonar.api.utils.KeyValueFormat; 032 033import javax.annotation.Nullable; 034import java.util.Collections; 035import java.util.List; 036import java.util.Map; 037 038/** 039 * @since 3.1 040 */ 041@Beta 042public final class DefaultReview implements MutableReview { 043 044 private Long violationId; 045 private Long reviewId; 046 private String ruleRepositoryKey; 047 private String ruleKey; 048 private String ruleName; 049 private Long line; 050 private boolean switchedOff = false; 051 private boolean manual = false; 052 private String message; 053 private String status; 054 private String resolution; 055 private String severity; 056 private Map<String, String> properties; 057 private List<Comment> newComments; 058 059 public Long getViolationId() { 060 return violationId; 061 } 062 063 public DefaultReview setViolationId(Long violationId) { 064 this.violationId = violationId; 065 return this; 066 } 067 068 public Long getReviewId() { 069 return reviewId; 070 } 071 072 public DefaultReview setReviewId(Long reviewId) { 073 this.reviewId = reviewId; 074 return this; 075 } 076 077 public String getRuleRepositoryKey() { 078 return ruleRepositoryKey; 079 } 080 081 public DefaultReview setRuleRepositoryKey(String s) { 082 this.ruleRepositoryKey = s; 083 return this; 084 } 085 086 public String getRuleKey() { 087 return ruleKey; 088 } 089 090 public DefaultReview setRuleKey(String s) { 091 this.ruleKey = s; 092 return this; 093 } 094 095 public String getRuleName() { 096 return ruleName; 097 } 098 099 public DefaultReview setRuleName(String s) { 100 this.ruleName = s; 101 return this; 102 } 103 104 public Long getLine() { 105 return line; 106 } 107 108 public DefaultReview setLine(Long line) { 109 this.line = line; 110 return this; 111 } 112 113 public boolean isSwitchedOff() { 114 return switchedOff; 115 } 116 117 public DefaultReview setSwitchedOff(boolean b) { 118 this.switchedOff = b; 119 return this; 120 } 121 122 public boolean isManual() { 123 return manual; 124 } 125 126 public DefaultReview setManual(boolean manual) { 127 this.manual = manual; 128 return this; 129 } 130 131 public String getMessage() { 132 return message; 133 } 134 135 public DefaultReview setMessage(String message) { 136 this.message = message; 137 return this; 138 } 139 140 public String getStatus() { 141 return status; 142 } 143 144 public DefaultReview setStatus(String s) { 145 Preconditions.checkArgument(!Strings.isNullOrEmpty(s)); 146 this.status = s; 147 return this; 148 } 149 150 public String getResolution() { 151 return resolution; 152 } 153 154 public DefaultReview setResolution(@Nullable String s) { 155 this.resolution = s; 156 return this; 157 } 158 159 public String getSeverity() { 160 return severity; 161 } 162 163 public DefaultReview setSeverity(String s) { 164 Preconditions.checkArgument(!Strings.isNullOrEmpty(s)); 165 this.severity = s; 166 return this; 167 } 168 169 public Map<String, String> getProperties() { 170 if (properties == null) { 171 return Collections.emptyMap(); 172 } 173 return properties; 174 } 175 176 public DefaultReview setProperties(Map<String, String> properties) { 177 this.properties = properties; 178 return this; 179 } 180 181 public DefaultReview setPropertiesAsString(@Nullable String s) { 182 this.properties = (s == null ? null : KeyValueFormat.parse(s)); 183 return this; 184 } 185 186 public Comment createComment() { 187 if (newComments == null) { 188 newComments = Lists.newArrayList(); 189 } 190 Comment comment = new DefaultComment(); 191 newComments.add(comment); 192 return comment; 193 } 194 195 public List<Comment> getNewComments() { 196 if (newComments == null) { 197 return Collections.emptyList(); 198 } 199 return newComments; 200 } 201 202 public DefaultReview setProperty(String key, @Nullable String value) { 203 if (properties == null) { 204 // keeping entries ordered by key allows to have consistent behavior in unit tests 205 properties = Maps.newLinkedHashMap(); 206 } 207 properties.put(key, value); 208 return this; 209 } 210 211 @Override 212 public String toString() { 213 return new ReflectionToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).toString(); 214 } 215}