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.

RuleFailureModel.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Sonar, open source software quality management tool.
  3. * Copyright (C) 2009 SonarSource SA
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * Sonar 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. * Sonar 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
  17. * License along with Sonar; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
  19. */
  20. package org.sonar.api.database.model;
  21. import org.apache.commons.lang.StringUtils;
  22. import org.apache.commons.lang.builder.EqualsBuilder;
  23. import org.apache.commons.lang.builder.HashCodeBuilder;
  24. import org.apache.commons.lang.builder.ReflectionToStringBuilder;
  25. import org.sonar.api.database.BaseIdentifiable;
  26. import org.sonar.api.rules.Rule;
  27. import org.sonar.api.rules.RulePriority;
  28. import javax.persistence.*;
  29. @Entity
  30. @Table(name = "rule_failures")
  31. public class RuleFailureModel extends BaseIdentifiable {
  32. public static final int MESSAGE_COLUMN_SIZE = 4000;
  33. @Column(name = "snapshot_id")
  34. protected Integer snapshotId;
  35. @ManyToOne(fetch = FetchType.EAGER)
  36. @JoinColumn(name = "rule_id")
  37. private Rule rule;
  38. @Column(name = "failure_level", updatable = false, nullable = false)
  39. @Enumerated(EnumType.ORDINAL)
  40. private RulePriority priority;
  41. @Column(name = "message", updatable = false, nullable = true, length = MESSAGE_COLUMN_SIZE)
  42. private String message;
  43. @Column(name = "line", updatable = true, nullable = true)
  44. private Integer line;
  45. @Column(name = "cost", updatable = true, nullable = true)
  46. private Double cost;
  47. public RuleFailureModel() {
  48. }
  49. public RuleFailureModel(Rule rule, RulePriority priority) {
  50. this.rule = rule;
  51. this.priority = priority;
  52. }
  53. public String getMessage() {
  54. return message;
  55. }
  56. public void setMessage(String message) {
  57. this.message = StringUtils.abbreviate(StringUtils.trim(message), MESSAGE_COLUMN_SIZE);
  58. }
  59. public RulePriority getLevel() {
  60. return priority;
  61. }
  62. public void setLevel(RulePriority priority) {
  63. this.priority = priority;
  64. }
  65. public Rule getRule() {
  66. return rule;
  67. }
  68. public void setRule(Rule rule) {
  69. this.rule = rule;
  70. }
  71. public Integer getLine() {
  72. return line;
  73. }
  74. public RulePriority getPriority() {
  75. return priority;
  76. }
  77. public Integer getSnapshotId() {
  78. return snapshotId;
  79. }
  80. public void setSnapshotId(Integer snapshotId) {
  81. this.snapshotId = snapshotId;
  82. }
  83. public void setPriority(RulePriority priority) {
  84. this.priority = priority;
  85. }
  86. public void setLine(Integer line) {
  87. this.line = line;
  88. }
  89. public Double getCost() {
  90. return cost;
  91. }
  92. public RuleFailureModel setCost(Double d) {
  93. this.cost = d;
  94. return this;
  95. }
  96. @Override
  97. public boolean equals(Object obj) {
  98. if (!(obj instanceof RuleFailureModel)) {
  99. return false;
  100. }
  101. if (this == obj) {
  102. return true;
  103. }
  104. RuleFailureModel other = (RuleFailureModel) obj;
  105. return new EqualsBuilder()
  106. .append(getId(), other.getId()).isEquals();
  107. }
  108. @Override
  109. public int hashCode() {
  110. return new HashCodeBuilder(17, 37).
  111. append(getId()).toHashCode();
  112. }
  113. @Override
  114. public String toString() {
  115. return ReflectionToStringBuilder.toString(this);
  116. }
  117. }