diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-16 15:58:42 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-16 15:58:42 +0000 |
commit | 690808781ae7625dad12536fe19a15a0146bdbae (patch) | |
tree | 6401137c24cb7825420613bf87d273c49f176244 /sonar-plugin-api | |
parent | 17976169eb50d6c8d715285ee40bcb3b9ca12bed (diff) | |
download | sonarqube-690808781ae7625dad12536fe19a15a0146bdbae.tar.gz sonarqube-690808781ae7625dad12536fe19a15a0146bdbae.zip |
add the column CHARACTERISTICS.ENABLED
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Characteristic.java | 12 | ||||
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Model.java | 42 |
2 files changed, 46 insertions, 8 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Characteristic.java b/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Characteristic.java index 3922ec8d3b2..1b2d30ea961 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Characteristic.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Characteristic.java @@ -68,6 +68,9 @@ public final class Characteristic implements Comparable<Characteristic> { @Column(name = "description", nullable = true, length = 4000) private String description; + @Column(name = "enabled", updatable = true, nullable = true) + private Boolean enabled = Boolean.TRUE; + @ManyToMany @JoinTable( name = "characteristic_edges", @@ -134,6 +137,15 @@ public final class Characteristic implements Comparable<Characteristic> { return this; } + public Boolean getEnabled() { + return enabled; + } + + public Characteristic setEnabled(Boolean b) { + this.enabled = b; + return this; + } + public Characteristic addChildren(Characteristic... list) { if (list != null) { for (Characteristic c : list) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Model.java b/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Model.java index 5e698902084..20bb2a46a57 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Model.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Model.java @@ -19,6 +19,7 @@ */ package org.sonar.api.qualitymodel; +import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; @@ -44,7 +45,7 @@ public final class Model implements Comparable<Model> { private String name; @OneToMany(mappedBy = "model", cascade = CascadeType.ALL, fetch = FetchType.LAZY) - private List<Characteristic> characteristics = new ArrayList<Characteristic>(); + private List<Characteristic> characteristics = Lists.newArrayList(); /** * Use the factory method <code>Model</code> @@ -104,32 +105,57 @@ public final class Model implements Comparable<Model> { return c; } + /** + * @return enabled characteristics + */ public List<Characteristic> getCharacteristics() { - return characteristics; + return getCharacteristics(true); + } + + public List<Characteristic> getCharacteristics(boolean onlyEnabled) { + if (!onlyEnabled) { + return characteristics; + } + List<Characteristic> result = Lists.newArrayList(); + for (Characteristic characteristic : characteristics) { + if (characteristic.getEnabled()) { + result.add(characteristic); + } + } + return result; } + /** + * Search for an ENABLED characteristic by its key. + */ public Characteristic getCharacteristicByKey(String key) { - for (Characteristic characteristic : getCharacteristics()) { - if (StringUtils.equals(key, characteristic.getKey())) { + for (Characteristic characteristic : characteristics) { + if (characteristic.getEnabled() && StringUtils.equals(key, characteristic.getKey())) { return characteristic; } } return null; } + /** + * Search for ENABLED characteristics by their depth. + */ public List<Characteristic> getCharacteristicsByDepth(int depth) { - List<Characteristic> result = new ArrayList<Characteristic>(); + List<Characteristic> result = Lists.newArrayList(); for (Characteristic c : characteristics) { - if (c.getDepth()==depth) { + if (c.getEnabled() && c.getDepth()==depth) { result.add(c); } } return result; } + /** + * Search for an ENABLED characteristic by its name. + */ public Characteristic getCharacteristicByName(String name) { - for (Characteristic characteristic : getCharacteristics()) { - if (StringUtils.equals(name, characteristic.getName())) { + for (Characteristic characteristic : characteristics) { + if (characteristic.getEnabled() && StringUtils.equals(name, characteristic.getName())) { return characteristic; } } |