From: Sébastien Lesaint Date: Mon, 20 Mar 2017 14:43:28 +0000 (+0100) Subject: SONAR-8867 RuleDto aggregates RuleDefinitionDto and RuleMetadataDto X-Git-Tag: 6.4-RC1~585 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=87c263bf25a165b1b346c11bc1ef444554f8ea75;p=sonarqube.git SONAR-8867 RuleDto aggregates RuleDefinitionDto and RuleMetadataDto --- diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java index a5a9bafb476..5a7b7ca6495 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java @@ -28,8 +28,6 @@ import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; -import org.apache.commons.lang.builder.ReflectionToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rules.RuleType; @@ -69,6 +67,10 @@ public class RuleDefinitionDto { return key; } + void setKey(RuleKey key) { + this.key = key; + } + public Integer getId() { return id; } @@ -98,6 +100,12 @@ public class RuleDefinitionDto { return this; } + public RuleDefinitionDto setRuleKey(RuleKey ruleKey) { + this.repositoryKey = ruleKey.repository(); + this.ruleKey = ruleKey.rule(); + return this; + } + public String getDescription() { return description; } @@ -240,7 +248,7 @@ public class RuleDefinitionDto { return systemTags; } - private void setSystemTagsField(String s) { + void setSystemTagsField(String s) { systemTags = s; } @@ -291,29 +299,49 @@ public class RuleDefinitionDto { } RuleDto other = (RuleDto) obj; return new EqualsBuilder() - .append(repositoryKey, other.getRepositoryKey()) - .append(ruleKey, other.getRuleKey()) - .isEquals(); + .append(repositoryKey, other.getRepositoryKey()) + .append(ruleKey, other.getRuleKey()) + .isEquals(); } @Override public int hashCode() { return new HashCodeBuilder(17, 37) - .append(repositoryKey) - .append(ruleKey) - .toHashCode(); - } - - @Override - public String toString() { - return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString(); + .append(repositoryKey) + .append(ruleKey) + .toHashCode(); } public static RuleDto createFor(RuleKey key) { return new RuleDto() - .setRepositoryKey(key.repository()) - .setRuleKey(key.rule()); + .setRepositoryKey(key.repository()) + .setRuleKey(key.rule()); } + @Override + public String toString() { + return "RuleDefinitionDto{" + + "id=" + id + + ", repositoryKey='" + repositoryKey + '\'' + + ", ruleKey='" + ruleKey + '\'' + + ", description='" + description + '\'' + + ", descriptionFormat=" + descriptionFormat + + ", status=" + status + + ", name='" + name + '\'' + + ", configKey='" + configKey + '\'' + + ", severity=" + severity + + ", isTemplate=" + isTemplate + + ", language='" + language + '\'' + + ", templateId=" + templateId + + ", defRemediationFunction='" + defRemediationFunction + '\'' + + ", defRemediationGapMultiplier='" + defRemediationGapMultiplier + '\'' + + ", defRemediationBaseEffort='" + defRemediationBaseEffort + '\'' + + ", gapDescription='" + gapDescription + '\'' + + ", systemTags='" + systemTags + '\'' + + ", type=" + type + + ", key=" + key + + ", createdAt=" + createdAt + + ", updatedAt=" + updatedAt + + '}'; + } } - diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java index 898a6fcb14c..e2d8f2e16e4 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java @@ -19,367 +19,336 @@ */ package org.sonar.db.rule; -import java.util.Arrays; -import java.util.Collections; import java.util.Date; import java.util.Set; -import java.util.TreeSet; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; -import org.apache.commons.lang.builder.ReflectionToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rules.RuleType; -import static com.google.common.base.Preconditions.checkArgument; - public class RuleDto { public enum Format { HTML, MARKDOWN } - private Integer id; - private String repositoryKey; - private String ruleKey; - private String description; - private Format descriptionFormat; - private RuleStatus status; - private String name; - private String configKey; - private Integer severity; - private boolean isTemplate; - private String language; - private Integer templateId; - private String noteData; - private String noteUserLogin; - private Date noteCreatedAt; - private Date noteUpdatedAt; - private String remediationFunction; - private String defRemediationFunction; - private String remediationGapMultiplier; - private String defRemediationGapMultiplier; - private String remediationBaseEffort; - private String defRemediationBaseEffort; - private String gapDescription; - private String tags; - private String systemTags; - private int type; - - private RuleKey key; - - private long createdAt; - private long updatedAt; + private final RuleDefinitionDto definition = new RuleDefinitionDto(); + private final RuleMetadataDto metadata = new RuleMetadataDto(); + + public RuleDefinitionDto getDefinition() { + return definition; + } + + public RuleMetadataDto getMetadata() { + return metadata; + } public RuleKey getKey() { - if (key == null) { - key = RuleKey.of(getRepositoryKey(), getRuleKey()); + if (definition.getKey() == null) { + definition.setKey(RuleKey.of(getRepositoryKey(), getRuleKey())); } - return key; + return definition.getKey(); } public Integer getId() { - return id; + return definition.getId(); } public RuleDto setId(Integer id) { - this.id = id; + definition.setId(id); + metadata.setRuleId(id); return this; } public String getRepositoryKey() { - return repositoryKey; + return definition.getRepositoryKey(); } public RuleDto setRepositoryKey(String s) { - checkArgument(s.length() <= 255, "Rule repository is too long: %s", s); - this.repositoryKey = s; + definition.setRepositoryKey(s); return this; } public String getRuleKey() { - return ruleKey; + return definition.getRuleKey(); } public RuleDto setRuleKey(String s) { - checkArgument(s.length() <= 200, "Rule key is too long: %s", s); - this.ruleKey = s; + definition.setRuleKey(s); return this; } public String getDescription() { - return description; + return definition.getDescription(); } public RuleDto setDescription(String description) { - this.description = description; + definition.setDescription(description); return this; } public Format getDescriptionFormat() { - return descriptionFormat; + return definition.getDescriptionFormat(); } public RuleDto setDescriptionFormat(Format descriptionFormat) { - this.descriptionFormat = descriptionFormat; + definition.setDescriptionFormat(descriptionFormat); return this; } public RuleStatus getStatus() { - return status; + return definition.getStatus(); } public RuleDto setStatus(@Nullable RuleStatus s) { - this.status = s; + definition.setStatus(s); return this; } public String getName() { - return name; + return definition.getName(); } public RuleDto setName(@Nullable String s) { - checkArgument(s == null || s.length() <= 255, "Rule name is too long: %s", s); - this.name = s; + definition.setName(s); return this; } public String getConfigKey() { - return configKey; + return definition.getConfigKey(); } public RuleDto setConfigKey(@Nullable String configKey) { - this.configKey = configKey; + definition.setConfigKey(configKey); return this; } @CheckForNull public Integer getSeverity() { - return severity; + return definition.getSeverity(); } @CheckForNull public String getSeverityString() { - return severity != null ? SeverityUtil.getSeverityFromOrdinal(severity) : null; + return definition.getSeverityString(); } public RuleDto setSeverity(@Nullable String severity) { - return this.setSeverity(severity != null ? SeverityUtil.getOrdinalFromSeverity(severity) : null); + definition.setSeverity(severity); + return this; } public RuleDto setSeverity(@Nullable Integer severity) { - this.severity = severity; + definition.setSeverity(severity); return this; } public boolean isTemplate() { - return isTemplate; + return definition.isTemplate(); } public RuleDto setIsTemplate(boolean isTemplate) { - this.isTemplate = isTemplate; + definition.setIsTemplate(isTemplate); return this; } @CheckForNull public String getLanguage() { - return language; + return definition.getLanguage(); } public RuleDto setLanguage(String language) { - this.language = language; + definition.setLanguage(language); return this; } @CheckForNull public Integer getTemplateId() { - return templateId; + return definition.getTemplateId(); } public RuleDto setTemplateId(@Nullable Integer templateId) { - this.templateId = templateId; + definition.setTemplateId(templateId); return this; } @CheckForNull - public String getNoteData() { - return noteData; + public String getDefaultRemediationFunction() { + return definition.getDefaultRemediationFunction(); } - public RuleDto setNoteData(@Nullable String s) { - this.noteData = s; + public RuleDto setDefaultRemediationFunction(@Nullable String defaultRemediationFunction) { + definition.setDefaultRemediationFunction(defaultRemediationFunction); return this; } @CheckForNull - public String getNoteUserLogin() { - return noteUserLogin; + public String getDefaultRemediationGapMultiplier() { + return definition.getDefaultRemediationGapMultiplier(); } - public RuleDto setNoteUserLogin(@Nullable String noteUserLogin) { - this.noteUserLogin = noteUserLogin; + public RuleDto setDefaultRemediationGapMultiplier(@Nullable String defaultRemediationGapMultiplier) { + definition.setDefaultRemediationGapMultiplier(defaultRemediationGapMultiplier); return this; } @CheckForNull - public Date getNoteCreatedAt() { - return noteCreatedAt; + public String getDefaultRemediationBaseEffort() { + return definition.getDefaultRemediationBaseEffort(); } - public RuleDto setNoteCreatedAt(@Nullable Date noteCreatedAt) { - this.noteCreatedAt = noteCreatedAt; + public RuleDto setDefaultRemediationBaseEffort(@Nullable String defaultRemediationBaseEffort) { + definition.setDefaultRemediationBaseEffort(defaultRemediationBaseEffort); return this; } @CheckForNull - public Date getNoteUpdatedAt() { - return noteUpdatedAt; + public String getGapDescription() { + return definition.getGapDescription(); } - public RuleDto setNoteUpdatedAt(@Nullable Date noteUpdatedAt) { - this.noteUpdatedAt = noteUpdatedAt; + public RuleDto setGapDescription(@Nullable String s) { + definition.setGapDescription(s); return this; } - @CheckForNull - public String getRemediationFunction() { - return remediationFunction; + public RuleDto setSystemTags(Set tags) { + this.definition.setSystemTags(tags); + return this; } - public RuleDto setRemediationFunction(@Nullable String remediationFunction) { - this.remediationFunction = remediationFunction; - return this; + public int getType() { + return definition.getType(); } - @CheckForNull - public String getDefaultRemediationFunction() { - return defRemediationFunction; + public RuleDto setType(int type) { + definition.setType(type); + return this; } - public RuleDto setDefaultRemediationFunction(@Nullable String defaultRemediationFunction) { - this.defRemediationFunction = defaultRemediationFunction; + public RuleDto setType(RuleType type) { + definition.setType(type); return this; } - @CheckForNull - public String getRemediationGapMultiplier() { - return remediationGapMultiplier; + public long getCreatedAt() { + return definition.getCreatedAt(); } - public RuleDto setRemediationGapMultiplier(@Nullable String remediationGapMultiplier) { - this.remediationGapMultiplier = remediationGapMultiplier; + public RuleDto setCreatedAt(long createdAt) { + definition.setCreatedAt(createdAt); return this; } - @CheckForNull - public String getDefaultRemediationGapMultiplier() { - return defRemediationGapMultiplier; + public long getUpdatedAt() { + return definition.getUpdatedAt(); } - public RuleDto setDefaultRemediationGapMultiplier(@Nullable String defaultRemediationGapMultiplier) { - this.defRemediationGapMultiplier = defaultRemediationGapMultiplier; + public RuleDto setUpdatedAt(long updatedAt) { + definition.setUpdatedAt(updatedAt); return this; } - @CheckForNull - public String getRemediationBaseEffort() { - return remediationBaseEffort; + public String getOrganizationUuid() { + return metadata.getOrganizationUuid(); } - public RuleDto setRemediationBaseEffort(@Nullable String remediationBaseEffort) { - this.remediationBaseEffort = remediationBaseEffort; + public RuleDto setOrganizationUuid(String organizationUuid) { + metadata.setOrganizationUuid(organizationUuid); return this; } @CheckForNull - public String getDefaultRemediationBaseEffort() { - return defRemediationBaseEffort; + public String getNoteData() { + return metadata.getNoteData(); } - public RuleDto setDefaultRemediationBaseEffort(@Nullable String defaultRemediationBaseEffort) { - this.defRemediationBaseEffort = defaultRemediationBaseEffort; + public RuleDto setNoteData(@Nullable String s) { + metadata.setNoteData(s); return this; } @CheckForNull - public String getGapDescription() { - return gapDescription; + public String getNoteUserLogin() { + return metadata.getNoteUserLogin(); } - public RuleDto setGapDescription(@Nullable String s) { - this.gapDescription = s; + public RuleDto setNoteUserLogin(@Nullable String noteUserLogin) { + metadata.setNoteUserLogin(noteUserLogin); return this; } - public Set getTags() { - return tags == null ? Collections.emptySet() : new TreeSet<>(Arrays.asList(StringUtils.split(tags, ','))); + @CheckForNull + public Date getNoteCreatedAt() { + return metadata.getNoteCreatedAt(); } - public Set getSystemTags() { - return systemTags == null ? Collections.emptySet() : new TreeSet<>(Arrays.asList(StringUtils.split(systemTags, ','))); + public RuleDto setNoteCreatedAt(@Nullable Date noteCreatedAt) { + metadata.setNoteCreatedAt(noteCreatedAt); + return this; } - private String getTagsField() { - return tags; + @CheckForNull + public Date getNoteUpdatedAt() { + return metadata.getNoteUpdatedAt(); } - private String getSystemTagsField() { - return systemTags; + public RuleDto setNoteUpdatedAt(@Nullable Date noteUpdatedAt) { + metadata.setNoteUpdatedAt(noteUpdatedAt); + return this; } - private void setTagsField(String s) { - tags = s; + @CheckForNull + public String getRemediationFunction() { + return metadata.getRemediationFunction(); } - private void setSystemTagsField(String s) { - systemTags = s; + public RuleDto setRemediationFunction(@Nullable String remediationFunction) { + metadata.setRemediationFunction(remediationFunction); + return this; } - public RuleDto setTags(Set tags) { - String raw = tags.isEmpty() ? null : StringUtils.join(tags, ','); - checkArgument(raw == null || raw.length() <= 4000, "Rule tags are too long: %s", raw); - this.tags = raw; - return this; + @CheckForNull + public String getRemediationGapMultiplier() { + return metadata.getRemediationGapMultiplier(); } - public RuleDto setSystemTags(Set tags) { - this.systemTags = tags.isEmpty() ? null : StringUtils.join(tags, ','); + public RuleDto setRemediationGapMultiplier(@Nullable String remediationGapMultiplier) { + metadata.setRemediationGapMultiplier(remediationGapMultiplier); return this; } - public int getType() { - return type; + @CheckForNull + public String getRemediationBaseEffort() { + return metadata.getRemediationBaseEffort(); } - public RuleDto setType(int type) { - this.type = type; + public RuleDto setRemediationBaseEffort(@Nullable String remediationBaseEffort) { + metadata.setRemediationBaseEffort(remediationBaseEffort); return this; } - public RuleDto setType(RuleType type) { - this.type = type.getDbConstant(); - return this; + public Set getTags() { + return metadata.getTags(); } - public long getCreatedAt() { - return createdAt; + private void setTagsField(String s) { + metadata.setTagsField(s); } - public RuleDto setCreatedAt(long createdAt) { - this.createdAt = createdAt; - return this; + public Set getSystemTags() { + return definition.getSystemTags(); } - public long getUpdatedAt() { - return updatedAt; + private void setSystemTagsField(String s) { + definition.setSystemTagsField(s); } - public RuleDto setUpdatedAt(long updatedAt) { - this.updatedAt = updatedAt; + public RuleDto setTags(Set tags) { + this.metadata.setTags(tags); return this; } @@ -393,22 +362,25 @@ public class RuleDto { } RuleDto other = (RuleDto) obj; return new EqualsBuilder() - .append(repositoryKey, other.getRepositoryKey()) - .append(ruleKey, other.getRuleKey()) + .append(getRepositoryKey(), other.getRepositoryKey()) + .append(getRuleKey(), other.getRuleKey()) .isEquals(); } @Override public int hashCode() { return new HashCodeBuilder(17, 37) - .append(repositoryKey) - .append(ruleKey) + .append(getRepositoryKey()) + .append(getRuleKey()) .toHashCode(); } @Override public String toString() { - return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString(); + return "RuleDto{" + + "definition=" + definition + + ", metadata=" + metadata + + '}'; } public static RuleDto createFor(RuleKey key) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMetadataDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMetadataDto.java index 29ebe3da75f..3ce1e937f04 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMetadataDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMetadataDto.java @@ -32,6 +32,7 @@ import static com.google.common.base.Preconditions.checkArgument; public class RuleMetadataDto { private int ruleId; + private String organizationUuid; private String noteData; private String noteUserLogin; private Date noteCreatedAt; @@ -51,6 +52,15 @@ public class RuleMetadataDto { return this; } + public String getOrganizationUuid() { + return organizationUuid; + } + + public RuleMetadataDto setOrganizationUuid(String organizationUuid) { + this.organizationUuid = organizationUuid; + return this; + } + @CheckForNull public String getNoteData() { return noteData; @@ -136,7 +146,7 @@ public class RuleMetadataDto { return tags; } - private void setTagsField(String s) { + void setTagsField(String s) { tags = s; } @@ -148,4 +158,21 @@ public class RuleMetadataDto { this.updatedAt = updatedAt; return this; } + + @Override + public String toString() { + return "RuleMetadataDto{" + + "ruleId=" + ruleId + + ", organizationUuid='" + organizationUuid + '\'' + + ", noteData='" + noteData + '\'' + + ", noteUserLogin='" + noteUserLogin + '\'' + + ", noteCreatedAt=" + noteCreatedAt + + ", noteUpdatedAt=" + noteUpdatedAt + + ", remediationFunction='" + remediationFunction + '\'' + + ", remediationGapMultiplier='" + remediationGapMultiplier + '\'' + + ", remediationBaseEffort='" + remediationBaseEffort + '\'' + + ", tags='" + tags + '\'' + + ", updatedAt=" + updatedAt + + '}'; + } } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml index 263c13afe7c..185195a465a 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml @@ -21,11 +21,11 @@ r.note_created_at as "noteCreatedAt", r.note_updated_at as "noteUpdatedAt", r.remediation_function as "remediationFunction", - r.def_remediation_function as "defRemediationFunction", + r.def_remediation_function as "defaultRemediationFunction", r.remediation_gap_mult as "remediationGapMultiplier", - r.def_remediation_gap_mult as "defRemediationGapMultiplier", + r.def_remediation_gap_mult as "defaultRemediationGapMultiplier", r.remediation_base_effort as "remediationBaseEffort", - r.def_remediation_base_effort as "defRemediationBaseEffort", + r.def_remediation_base_effort as "defaultRemediationBaseEffort", r.gap_description as "gapDescription", r.tags as "tagsField", r.system_tags as "systemTagsField", diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTesting.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTesting.java index bb5f4ad2952..c14178c3aa9 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTesting.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTesting.java @@ -122,6 +122,7 @@ public class RuleTesting { .setUpdatedAt(new Date().getTime()); if (organization != null) { res + .setOrganizationUuid(organization.getUuid()) .setTags(ImmutableSet.of("tag1", "tag2")) .setRemediationFunction("LINEAR") .setRemediationGapMultiplier("1h");