Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

RuleMetadataDto.java 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.db.rule;
  21. import java.util.Arrays;
  22. import java.util.HashSet;
  23. import java.util.Set;
  24. import java.util.TreeSet;
  25. import javax.annotation.CheckForNull;
  26. import javax.annotation.Nullable;
  27. import org.apache.commons.lang.StringUtils;
  28. import org.sonar.api.rules.RuleType;
  29. import static com.google.common.base.Preconditions.checkArgument;
  30. public class RuleMetadataDto {
  31. private String ruleUuid;
  32. private String noteData;
  33. private String noteUserUuid;
  34. private Long noteCreatedAt;
  35. private Long noteUpdatedAt;
  36. private String remediationFunction;
  37. private String remediationGapMultiplier;
  38. private String remediationBaseEffort;
  39. private String tags;
  40. /**
  41. * Name of on ad hoc rule.
  42. * When {@link RuleDefinitionDto#isAdHoc} is true, this field should always be set
  43. */
  44. private String adHocName;
  45. /**
  46. * Optional description of on ad hoc rule.
  47. */
  48. private String adHocDescription;
  49. /**
  50. * Severity of on ad hoc rule.
  51. * When {@link RuleDefinitionDto#isAdHoc} is true, this field should always be set
  52. */
  53. private String adHocSeverity;
  54. /**
  55. * Type of on ad hoc rule.
  56. * When {@link RuleDefinitionDto#isAdHoc} is true, this field should always be set
  57. */
  58. private Integer adHocType;
  59. private long createdAt;
  60. private long updatedAt;
  61. public RuleMetadataDto() {
  62. // nothing to do here
  63. }
  64. public String getRuleUuid() {
  65. return ruleUuid;
  66. }
  67. public RuleMetadataDto setRuleUuid(String ruleUuid) {
  68. this.ruleUuid = ruleUuid;
  69. return this;
  70. }
  71. @CheckForNull
  72. public String getNoteData() {
  73. return noteData;
  74. }
  75. public RuleMetadataDto setNoteData(@Nullable String s) {
  76. this.noteData = s;
  77. return this;
  78. }
  79. @CheckForNull
  80. public String getNoteUserUuid() {
  81. return noteUserUuid;
  82. }
  83. public RuleMetadataDto setNoteUserUuid(@Nullable String noteUserUuid) {
  84. this.noteUserUuid = noteUserUuid;
  85. return this;
  86. }
  87. @CheckForNull
  88. public Long getNoteCreatedAt() {
  89. return noteCreatedAt;
  90. }
  91. public RuleMetadataDto setNoteCreatedAt(@Nullable Long noteCreatedAt) {
  92. this.noteCreatedAt = noteCreatedAt;
  93. return this;
  94. }
  95. @CheckForNull
  96. public Long getNoteUpdatedAt() {
  97. return noteUpdatedAt;
  98. }
  99. public RuleMetadataDto setNoteUpdatedAt(@Nullable Long noteUpdatedAt) {
  100. this.noteUpdatedAt = noteUpdatedAt;
  101. return this;
  102. }
  103. @CheckForNull
  104. public String getRemediationFunction() {
  105. return remediationFunction;
  106. }
  107. public RuleMetadataDto setRemediationFunction(@Nullable String remediationFunction) {
  108. this.remediationFunction = remediationFunction;
  109. return this;
  110. }
  111. @CheckForNull
  112. public String getRemediationGapMultiplier() {
  113. return remediationGapMultiplier;
  114. }
  115. public RuleMetadataDto setRemediationGapMultiplier(@Nullable String remediationGapMultiplier) {
  116. this.remediationGapMultiplier = remediationGapMultiplier;
  117. return this;
  118. }
  119. @CheckForNull
  120. public String getRemediationBaseEffort() {
  121. return remediationBaseEffort;
  122. }
  123. public RuleMetadataDto setRemediationBaseEffort(@Nullable String remediationBaseEffort) {
  124. this.remediationBaseEffort = remediationBaseEffort;
  125. return this;
  126. }
  127. public Set<String> getTags() {
  128. return tags == null ? new HashSet<>() : new TreeSet<>(Arrays.asList(StringUtils.split(tags, ',')));
  129. }
  130. String getTagsAsString() {
  131. return tags;
  132. }
  133. public RuleMetadataDto setTags(Set<String> tags) {
  134. String raw = tags.isEmpty() ? null : StringUtils.join(tags, ',');
  135. checkArgument(raw == null || raw.length() <= 4000, "Rule tags are too long: %s", raw);
  136. this.tags = raw;
  137. return this;
  138. }
  139. private String getTagsField() {
  140. return tags;
  141. }
  142. void setTagsField(String s) {
  143. tags = s;
  144. }
  145. @CheckForNull
  146. public String getAdHocName() {
  147. return adHocName;
  148. }
  149. public RuleMetadataDto setAdHocName(@Nullable String adHocName) {
  150. this.adHocName = adHocName;
  151. return this;
  152. }
  153. @CheckForNull
  154. public String getAdHocDescription() {
  155. return adHocDescription;
  156. }
  157. public RuleMetadataDto setAdHocDescription(@Nullable String adHocDescription) {
  158. this.adHocDescription = adHocDescription;
  159. return this;
  160. }
  161. @CheckForNull
  162. public String getAdHocSeverity() {
  163. return adHocSeverity;
  164. }
  165. public RuleMetadataDto setAdHocSeverity(@Nullable String adHocSeverity) {
  166. this.adHocSeverity = adHocSeverity;
  167. return this;
  168. }
  169. @CheckForNull
  170. public Integer getAdHocType() {
  171. return adHocType;
  172. }
  173. public RuleMetadataDto setAdHocType(@Nullable Integer adHocType) {
  174. this.adHocType = adHocType;
  175. return this;
  176. }
  177. public RuleMetadataDto setAdHocType(@Nullable RuleType adHocType) {
  178. setAdHocType(adHocType != null ? adHocType.getDbConstant() : null);
  179. return this;
  180. }
  181. public long getCreatedAt() {
  182. return createdAt;
  183. }
  184. public RuleMetadataDto setCreatedAt(long createdAt) {
  185. this.createdAt = createdAt;
  186. return this;
  187. }
  188. public long getUpdatedAt() {
  189. return updatedAt;
  190. }
  191. public RuleMetadataDto setUpdatedAt(long updatedAt) {
  192. this.updatedAt = updatedAt;
  193. return this;
  194. }
  195. @Override
  196. public String toString() {
  197. return "RuleMetadataDto{" +
  198. "ruleUuid=" + ruleUuid +
  199. ", noteData='" + noteData + '\'' +
  200. ", noteUserUuid='" + noteUserUuid + '\'' +
  201. ", noteCreatedAt=" + noteCreatedAt +
  202. ", noteUpdatedAt=" + noteUpdatedAt +
  203. ", remediationFunction='" + remediationFunction + '\'' +
  204. ", remediationGapMultiplier='" + remediationGapMultiplier + '\'' +
  205. ", remediationBaseEffort='" + remediationBaseEffort + '\'' +
  206. ", tags='" + tags + '\'' +
  207. ", createdAt=" + createdAt +
  208. ", updatedAt=" + updatedAt +
  209. '}';
  210. }
  211. }