You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RuleDto.java 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2020 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.Set;
  22. import javax.annotation.CheckForNull;
  23. import javax.annotation.Nullable;
  24. import org.apache.commons.lang.builder.EqualsBuilder;
  25. import org.apache.commons.lang.builder.HashCodeBuilder;
  26. import org.sonar.api.rule.RuleKey;
  27. import org.sonar.api.rule.RuleStatus;
  28. import org.sonar.api.rules.RuleType;
  29. public class RuleDto {
  30. public enum Format {
  31. HTML, MARKDOWN
  32. }
  33. public enum Scope {
  34. MAIN, TEST, ALL
  35. }
  36. private final RuleDefinitionDto definition;
  37. private final RuleMetadataDto metadata;
  38. public RuleDto() {
  39. this(new RuleDefinitionDto(), new RuleMetadataDto());
  40. }
  41. public RuleDto(RuleDefinitionDto definition, RuleMetadataDto metadata) {
  42. this.definition = definition;
  43. this.metadata = metadata;
  44. }
  45. public RuleDefinitionDto getDefinition() {
  46. return definition;
  47. }
  48. public RuleMetadataDto getMetadata() {
  49. return metadata;
  50. }
  51. public RuleKey getKey() {
  52. return definition.getKey();
  53. }
  54. public String getUuid() {
  55. return definition.getUuid();
  56. }
  57. public RuleDto setUuid(String uuid) {
  58. definition.setUuid(uuid);
  59. metadata.setRuleUuid(uuid);
  60. return this;
  61. }
  62. public String getRepositoryKey() {
  63. return definition.getRepositoryKey();
  64. }
  65. public RuleDto setRepositoryKey(String s) {
  66. definition.setRepositoryKey(s);
  67. return this;
  68. }
  69. public String getRuleKey() {
  70. return definition.getRuleKey();
  71. }
  72. public RuleDto setRuleKey(String s) {
  73. definition.setRuleKey(s);
  74. return this;
  75. }
  76. @CheckForNull
  77. public String getPluginKey() {
  78. return definition.getPluginKey();
  79. }
  80. public RuleDto setPluginKey(@Nullable String s) {
  81. definition.setPluginKey(s);
  82. return this;
  83. }
  84. public String getDescription() {
  85. return definition.getDescription();
  86. }
  87. public RuleDto setDescription(String description) {
  88. definition.setDescription(description);
  89. return this;
  90. }
  91. public Format getDescriptionFormat() {
  92. return definition.getDescriptionFormat();
  93. }
  94. public RuleDto setDescriptionFormat(Format descriptionFormat) {
  95. definition.setDescriptionFormat(descriptionFormat);
  96. return this;
  97. }
  98. public RuleStatus getStatus() {
  99. return definition.getStatus();
  100. }
  101. public RuleDto setStatus(@Nullable RuleStatus s) {
  102. definition.setStatus(s);
  103. return this;
  104. }
  105. public String getName() {
  106. return definition.getName();
  107. }
  108. public RuleDto setName(@Nullable String s) {
  109. definition.setName(s);
  110. return this;
  111. }
  112. public String getConfigKey() {
  113. return definition.getConfigKey();
  114. }
  115. public RuleDto setConfigKey(@Nullable String configKey) {
  116. definition.setConfigKey(configKey);
  117. return this;
  118. }
  119. public Scope getScope() {
  120. return definition.getScope();
  121. }
  122. public RuleDto setScope(Scope scope) {
  123. definition.setScope(scope);
  124. return this;
  125. }
  126. @CheckForNull
  127. public Integer getSeverity() {
  128. return definition.getSeverity();
  129. }
  130. @CheckForNull
  131. public String getSeverityString() {
  132. return definition.getSeverityString();
  133. }
  134. public RuleDto setSeverity(@Nullable String severity) {
  135. definition.setSeverity(severity);
  136. return this;
  137. }
  138. public RuleDto setSeverity(@Nullable Integer severity) {
  139. definition.setSeverity(severity);
  140. return this;
  141. }
  142. public boolean isExternal() {
  143. return definition.isExternal();
  144. }
  145. public RuleDto setIsExternal(boolean isExternal) {
  146. definition.setIsExternal(isExternal);
  147. return this;
  148. }
  149. public boolean isAdHoc() {
  150. return definition.isAdHoc();
  151. }
  152. public RuleDto setIsAdhoc(boolean isAdHoc) {
  153. definition.setIsAdHoc(isAdHoc);
  154. return this;
  155. }
  156. @CheckForNull
  157. public String getAdHocName() {
  158. return metadata.getAdHocName();
  159. }
  160. public RuleDto setAdHocName(@Nullable String adHocName) {
  161. metadata.setAdHocName(adHocName);
  162. return this;
  163. }
  164. @CheckForNull
  165. public String getAdHocDescription() {
  166. return metadata.getAdHocDescription();
  167. }
  168. public RuleDto setAdHocDescription(@Nullable String adHocDescription) {
  169. metadata.setAdHocDescription(adHocDescription);
  170. return this;
  171. }
  172. @CheckForNull
  173. public String getAdHocSeverity() {
  174. return metadata.getAdHocSeverity();
  175. }
  176. public RuleDto setAdHocSeverity(@Nullable String adHocSeverity) {
  177. metadata.setAdHocSeverity(adHocSeverity);
  178. return this;
  179. }
  180. @CheckForNull
  181. public Integer getAdHocType() {
  182. return metadata.getAdHocType();
  183. }
  184. public RuleDto setAdHocType(@Nullable Integer type) {
  185. metadata.setAdHocType(type);
  186. return this;
  187. }
  188. public RuleDto setAdHocType(@Nullable RuleType adHocType) {
  189. metadata.setAdHocType(adHocType);
  190. return this;
  191. }
  192. public boolean isTemplate() {
  193. return definition.isTemplate();
  194. }
  195. public RuleDto setIsTemplate(boolean isTemplate) {
  196. definition.setIsTemplate(isTemplate);
  197. return this;
  198. }
  199. @CheckForNull
  200. public String getLanguage() {
  201. return definition.getLanguage();
  202. }
  203. public RuleDto setLanguage(String language) {
  204. definition.setLanguage(language);
  205. return this;
  206. }
  207. @CheckForNull
  208. public String getTemplateUuid() {
  209. return definition.getTemplateUuid();
  210. }
  211. public RuleDto setTemplateUuid(@Nullable String templateUuid) {
  212. definition.setTemplateUuid(templateUuid);
  213. return this;
  214. }
  215. @CheckForNull
  216. public String getDefRemediationFunction() {
  217. return definition.getDefRemediationFunction();
  218. }
  219. public RuleDto setDefRemediationFunction(@Nullable String defaultRemediationFunction) {
  220. definition.setDefRemediationFunction(defaultRemediationFunction);
  221. return this;
  222. }
  223. @CheckForNull
  224. public String getDefRemediationGapMultiplier() {
  225. return definition.getDefRemediationGapMultiplier();
  226. }
  227. public RuleDto setDefRemediationGapMultiplier(@Nullable String defaultRemediationGapMultiplier) {
  228. definition.setDefRemediationGapMultiplier(defaultRemediationGapMultiplier);
  229. return this;
  230. }
  231. @CheckForNull
  232. public String getDefRemediationBaseEffort() {
  233. return definition.getDefRemediationBaseEffort();
  234. }
  235. public RuleDto setDefRemediationBaseEffort(@Nullable String defaultRemediationBaseEffort) {
  236. definition.setDefRemediationBaseEffort(defaultRemediationBaseEffort);
  237. return this;
  238. }
  239. @CheckForNull
  240. public String getGapDescription() {
  241. return definition.getGapDescription();
  242. }
  243. public RuleDto setGapDescription(@Nullable String s) {
  244. definition.setGapDescription(s);
  245. return this;
  246. }
  247. public RuleDto setSystemTags(Set<String> tags) {
  248. this.definition.setSystemTags(tags);
  249. return this;
  250. }
  251. public RuleDto setSecurityStandards(Set<String> standards) {
  252. this.definition.setSecurityStandards(standards);
  253. return this;
  254. }
  255. public int getType() {
  256. return definition.getType();
  257. }
  258. public RuleDto setType(int type) {
  259. definition.setType(type);
  260. return this;
  261. }
  262. public RuleDto setType(RuleType type) {
  263. definition.setType(type);
  264. return this;
  265. }
  266. public Set<String> getSystemTags() {
  267. return definition.getSystemTags();
  268. }
  269. /**
  270. * Used in MyBatis mapping.
  271. */
  272. private void setSystemTagsField(String s) {
  273. definition.setSystemTagsField(s);
  274. }
  275. public Set<String> getSecurityStandards() {
  276. return definition.getSecurityStandards();
  277. }
  278. /**
  279. * Used in MyBatis mapping.
  280. */
  281. private void setSecurityStandardsField(String s) {
  282. definition.setSecurityStandardsField(s);
  283. }
  284. public long getCreatedAt() {
  285. return definition.getCreatedAt();
  286. }
  287. public RuleDto setCreatedAt(long createdAt) {
  288. definition.setCreatedAt(createdAt);
  289. metadata.setCreatedAt(createdAt);
  290. return this;
  291. }
  292. /**
  293. * Used in MyBatis mapping.
  294. */
  295. private void setCreatedAtFromDefinition(@Nullable Long createdAt) {
  296. if (createdAt != null && createdAt > definition.getCreatedAt()) {
  297. setCreatedAt(createdAt);
  298. }
  299. }
  300. /**
  301. * Used in MyBatis mapping.
  302. */
  303. private void setCreatedAtFromMetadata(@Nullable Long createdAt) {
  304. if (createdAt != null && createdAt > definition.getCreatedAt()) {
  305. setCreatedAt(createdAt);
  306. }
  307. }
  308. public long getUpdatedAt() {
  309. return definition.getUpdatedAt();
  310. }
  311. public RuleDto setUpdatedAt(long updatedAt) {
  312. definition.setUpdatedAt(updatedAt);
  313. metadata.setUpdatedAt(updatedAt);
  314. return this;
  315. }
  316. /**
  317. * Used in MyBatis mapping.
  318. */
  319. private void setUpdatedAtFromDefinition(@Nullable Long updatedAt) {
  320. if (updatedAt != null && updatedAt > definition.getUpdatedAt()) {
  321. setUpdatedAt(updatedAt);
  322. }
  323. }
  324. /**
  325. * Used in MyBatis mapping.
  326. */
  327. private void setUpdatedAtFromMetadata(@Nullable Long updatedAt) {
  328. if (updatedAt != null && updatedAt > definition.getUpdatedAt()) {
  329. setUpdatedAt(updatedAt);
  330. }
  331. }
  332. public String getOrganizationUuid() {
  333. return metadata.getOrganizationUuid();
  334. }
  335. public RuleDto setOrganizationUuid(String organizationUuid) {
  336. metadata.setOrganizationUuid(organizationUuid);
  337. return this;
  338. }
  339. @CheckForNull
  340. public String getNoteData() {
  341. return metadata.getNoteData();
  342. }
  343. public RuleDto setNoteData(@Nullable String s) {
  344. metadata.setNoteData(s);
  345. return this;
  346. }
  347. @CheckForNull
  348. public String getNoteUserUuid() {
  349. return metadata.getNoteUserUuid();
  350. }
  351. public RuleDto setNoteUserUuid(@Nullable String noteUserUuid) {
  352. metadata.setNoteUserUuid(noteUserUuid);
  353. return this;
  354. }
  355. @CheckForNull
  356. public Long getNoteCreatedAt() {
  357. return metadata.getNoteCreatedAt();
  358. }
  359. public RuleDto setNoteCreatedAt(@Nullable Long noteCreatedAt) {
  360. metadata.setNoteCreatedAt(noteCreatedAt);
  361. return this;
  362. }
  363. @CheckForNull
  364. public Long getNoteUpdatedAt() {
  365. return metadata.getNoteUpdatedAt();
  366. }
  367. public RuleDto setNoteUpdatedAt(@Nullable Long noteUpdatedAt) {
  368. metadata.setNoteUpdatedAt(noteUpdatedAt);
  369. return this;
  370. }
  371. @CheckForNull
  372. public String getRemediationFunction() {
  373. return metadata.getRemediationFunction();
  374. }
  375. public RuleDto setRemediationFunction(@Nullable String remediationFunction) {
  376. metadata.setRemediationFunction(remediationFunction);
  377. return this;
  378. }
  379. @CheckForNull
  380. public String getRemediationGapMultiplier() {
  381. return metadata.getRemediationGapMultiplier();
  382. }
  383. public RuleDto setRemediationGapMultiplier(@Nullable String remediationGapMultiplier) {
  384. metadata.setRemediationGapMultiplier(remediationGapMultiplier);
  385. return this;
  386. }
  387. @CheckForNull
  388. public String getRemediationBaseEffort() {
  389. return metadata.getRemediationBaseEffort();
  390. }
  391. public RuleDto setRemediationBaseEffort(@Nullable String remediationBaseEffort) {
  392. metadata.setRemediationBaseEffort(remediationBaseEffort);
  393. return this;
  394. }
  395. public Set<String> getTags() {
  396. return metadata.getTags();
  397. }
  398. /**
  399. * Used in MyBatis mapping.
  400. */
  401. private void setTagsField(String s) {
  402. metadata.setTagsField(s);
  403. }
  404. public RuleDto setTags(Set<String> tags) {
  405. this.metadata.setTags(tags);
  406. return this;
  407. }
  408. @Override
  409. public boolean equals(Object obj) {
  410. if (!(obj instanceof RuleDto)) {
  411. return false;
  412. }
  413. if (this == obj) {
  414. return true;
  415. }
  416. RuleDto other = (RuleDto) obj;
  417. return new EqualsBuilder()
  418. .append(getRepositoryKey(), other.getRepositoryKey())
  419. .append(getRuleKey(), other.getRuleKey())
  420. .isEquals();
  421. }
  422. @Override
  423. public int hashCode() {
  424. return new HashCodeBuilder(17, 37)
  425. .append(getRepositoryKey())
  426. .append(getRuleKey())
  427. .toHashCode();
  428. }
  429. @Override
  430. public String toString() {
  431. return "RuleDto{" +
  432. "definition=" + definition +
  433. ", metadata=" + metadata +
  434. '}';
  435. }
  436. public static RuleDto createFor(RuleKey key) {
  437. return new RuleDto()
  438. .setRepositoryKey(key.repository())
  439. .setRuleKey(key.rule());
  440. }
  441. }