123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543 |
- /*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
- package org.sonar.db.rule;
-
- import java.util.Set;
- import javax.annotation.CheckForNull;
- import javax.annotation.Nullable;
- import org.apache.commons.lang.builder.EqualsBuilder;
- import org.apache.commons.lang.builder.HashCodeBuilder;
- import org.sonar.api.rule.RuleKey;
- import org.sonar.api.rule.RuleStatus;
- import org.sonar.api.rules.RuleType;
-
- public class RuleDto {
-
- public enum Format {
- HTML, MARKDOWN
- }
-
- public enum Scope {
- MAIN, TEST, ALL
- }
-
- private final RuleDefinitionDto definition;
- private final RuleMetadataDto metadata;
-
- public RuleDto() {
- this(new RuleDefinitionDto(), new RuleMetadataDto());
- }
-
- public RuleDto(RuleDefinitionDto definition, RuleMetadataDto metadata) {
- this.definition = definition;
- this.metadata = metadata;
- }
-
- public RuleDefinitionDto getDefinition() {
- return definition;
- }
-
- public RuleMetadataDto getMetadata() {
- return metadata;
- }
-
- public RuleKey getKey() {
- return definition.getKey();
- }
-
- public String getUuid() {
- return definition.getUuid();
- }
-
- public RuleDto setUuid(String uuid) {
- definition.setUuid(uuid);
- metadata.setRuleUuid(uuid);
- return this;
- }
-
- public String getRepositoryKey() {
- return definition.getRepositoryKey();
- }
-
- public RuleDto setRepositoryKey(String s) {
- definition.setRepositoryKey(s);
- return this;
- }
-
- public String getRuleKey() {
- return definition.getRuleKey();
- }
-
- public RuleDto setRuleKey(String s) {
- definition.setRuleKey(s);
- return this;
- }
-
- @CheckForNull
- public String getPluginKey() {
- return definition.getPluginKey();
- }
-
- public RuleDto setPluginKey(@Nullable String s) {
- definition.setPluginKey(s);
- return this;
- }
-
- public String getDescription() {
- return definition.getDescription();
- }
-
- public RuleDto setDescription(String description) {
- definition.setDescription(description);
- return this;
- }
-
- public Format getDescriptionFormat() {
- return definition.getDescriptionFormat();
- }
-
- public RuleDto setDescriptionFormat(Format descriptionFormat) {
- definition.setDescriptionFormat(descriptionFormat);
- return this;
- }
-
- public RuleStatus getStatus() {
- return definition.getStatus();
- }
-
- public RuleDto setStatus(@Nullable RuleStatus s) {
- definition.setStatus(s);
- return this;
- }
-
- public String getName() {
- return definition.getName();
- }
-
- public RuleDto setName(@Nullable String s) {
- definition.setName(s);
- return this;
- }
-
- public String getConfigKey() {
- return definition.getConfigKey();
- }
-
- public RuleDto setConfigKey(@Nullable String configKey) {
- definition.setConfigKey(configKey);
- return this;
- }
-
- public Scope getScope() {
- return definition.getScope();
- }
-
- public RuleDto setScope(Scope scope) {
- definition.setScope(scope);
- return this;
- }
-
- @CheckForNull
- public Integer getSeverity() {
- return definition.getSeverity();
- }
-
- @CheckForNull
- public String getSeverityString() {
- return definition.getSeverityString();
- }
-
- public RuleDto setSeverity(@Nullable String severity) {
- definition.setSeverity(severity);
- return this;
- }
-
- public RuleDto setSeverity(@Nullable Integer severity) {
- definition.setSeverity(severity);
- return this;
- }
-
- public boolean isExternal() {
- return definition.isExternal();
- }
-
- public RuleDto setIsExternal(boolean isExternal) {
- definition.setIsExternal(isExternal);
- return this;
- }
-
- public boolean isAdHoc() {
- return definition.isAdHoc();
- }
-
- public RuleDto setIsAdhoc(boolean isAdHoc) {
- definition.setIsAdHoc(isAdHoc);
- return this;
- }
-
- @CheckForNull
- public String getAdHocName() {
- return metadata.getAdHocName();
- }
-
- public RuleDto setAdHocName(@Nullable String adHocName) {
- metadata.setAdHocName(adHocName);
- return this;
- }
-
- @CheckForNull
- public String getAdHocDescription() {
- return metadata.getAdHocDescription();
- }
-
- public RuleDto setAdHocDescription(@Nullable String adHocDescription) {
- metadata.setAdHocDescription(adHocDescription);
- return this;
- }
-
- @CheckForNull
- public String getAdHocSeverity() {
- return metadata.getAdHocSeverity();
- }
-
- public RuleDto setAdHocSeverity(@Nullable String adHocSeverity) {
- metadata.setAdHocSeverity(adHocSeverity);
- return this;
- }
-
- @CheckForNull
- public Integer getAdHocType() {
- return metadata.getAdHocType();
- }
-
- public RuleDto setAdHocType(@Nullable Integer type) {
- metadata.setAdHocType(type);
- return this;
- }
-
- public RuleDto setAdHocType(@Nullable RuleType adHocType) {
- metadata.setAdHocType(adHocType);
- return this;
- }
-
- public boolean isTemplate() {
- return definition.isTemplate();
- }
-
- public RuleDto setIsTemplate(boolean isTemplate) {
- definition.setIsTemplate(isTemplate);
- return this;
- }
-
- @CheckForNull
- public String getLanguage() {
- return definition.getLanguage();
- }
-
- public RuleDto setLanguage(String language) {
- definition.setLanguage(language);
- return this;
- }
-
- @CheckForNull
- public String getTemplateUuid() {
- return definition.getTemplateUuid();
- }
-
- public RuleDto setTemplateUuid(@Nullable String templateUuid) {
- definition.setTemplateUuid(templateUuid);
- return this;
- }
-
- @CheckForNull
- public String getDefRemediationFunction() {
- return definition.getDefRemediationFunction();
- }
-
- public RuleDto setDefRemediationFunction(@Nullable String defaultRemediationFunction) {
- definition.setDefRemediationFunction(defaultRemediationFunction);
- return this;
- }
-
- @CheckForNull
- public String getDefRemediationGapMultiplier() {
- return definition.getDefRemediationGapMultiplier();
- }
-
- public RuleDto setDefRemediationGapMultiplier(@Nullable String defaultRemediationGapMultiplier) {
- definition.setDefRemediationGapMultiplier(defaultRemediationGapMultiplier);
- return this;
- }
-
- @CheckForNull
- public String getDefRemediationBaseEffort() {
- return definition.getDefRemediationBaseEffort();
- }
-
- public RuleDto setDefRemediationBaseEffort(@Nullable String defaultRemediationBaseEffort) {
- definition.setDefRemediationBaseEffort(defaultRemediationBaseEffort);
- return this;
- }
-
- @CheckForNull
- public String getGapDescription() {
- return definition.getGapDescription();
- }
-
- public RuleDto setGapDescription(@Nullable String s) {
- definition.setGapDescription(s);
- return this;
- }
-
- public RuleDto setSystemTags(Set<String> tags) {
- this.definition.setSystemTags(tags);
- return this;
- }
-
- public RuleDto setSecurityStandards(Set<String> standards) {
- this.definition.setSecurityStandards(standards);
- return this;
- }
-
- public int getType() {
- return definition.getType();
- }
-
- public RuleDto setType(int type) {
- definition.setType(type);
- return this;
- }
-
- public RuleDto setType(RuleType type) {
- definition.setType(type);
- return this;
- }
-
- public Set<String> getSystemTags() {
- return definition.getSystemTags();
- }
-
- /**
- * Used in MyBatis mapping.
- */
- private void setSystemTagsField(String s) {
- definition.setSystemTagsField(s);
- }
-
- public Set<String> getSecurityStandards() {
- return definition.getSecurityStandards();
- }
-
- /**
- * Used in MyBatis mapping.
- */
- private void setSecurityStandardsField(String s) {
- definition.setSecurityStandardsField(s);
- }
-
- public long getCreatedAt() {
- return definition.getCreatedAt();
- }
-
- public RuleDto setCreatedAt(long createdAt) {
- definition.setCreatedAt(createdAt);
- metadata.setCreatedAt(createdAt);
- return this;
- }
-
- /**
- * Used in MyBatis mapping.
- */
- private void setCreatedAtFromDefinition(@Nullable Long createdAt) {
- if (createdAt != null && createdAt > definition.getCreatedAt()) {
- setCreatedAt(createdAt);
- }
- }
-
- /**
- * Used in MyBatis mapping.
- */
- private void setCreatedAtFromMetadata(@Nullable Long createdAt) {
- if (createdAt != null && createdAt > definition.getCreatedAt()) {
- setCreatedAt(createdAt);
- }
- }
-
- public long getUpdatedAt() {
- return definition.getUpdatedAt();
- }
-
- public RuleDto setUpdatedAt(long updatedAt) {
- definition.setUpdatedAt(updatedAt);
- metadata.setUpdatedAt(updatedAt);
- return this;
- }
-
- /**
- * Used in MyBatis mapping.
- */
- private void setUpdatedAtFromDefinition(@Nullable Long updatedAt) {
- if (updatedAt != null && updatedAt > definition.getUpdatedAt()) {
- setUpdatedAt(updatedAt);
- }
- }
-
- /**
- * Used in MyBatis mapping.
- */
- private void setUpdatedAtFromMetadata(@Nullable Long updatedAt) {
- if (updatedAt != null && updatedAt > definition.getUpdatedAt()) {
- setUpdatedAt(updatedAt);
- }
- }
-
- public String getOrganizationUuid() {
- return metadata.getOrganizationUuid();
- }
-
- public RuleDto setOrganizationUuid(String organizationUuid) {
- metadata.setOrganizationUuid(organizationUuid);
- return this;
- }
-
- @CheckForNull
- public String getNoteData() {
- return metadata.getNoteData();
- }
-
- public RuleDto setNoteData(@Nullable String s) {
- metadata.setNoteData(s);
- return this;
- }
-
- @CheckForNull
- public String getNoteUserUuid() {
- return metadata.getNoteUserUuid();
- }
-
- public RuleDto setNoteUserUuid(@Nullable String noteUserUuid) {
- metadata.setNoteUserUuid(noteUserUuid);
- return this;
- }
-
- @CheckForNull
- public Long getNoteCreatedAt() {
- return metadata.getNoteCreatedAt();
- }
-
- public RuleDto setNoteCreatedAt(@Nullable Long noteCreatedAt) {
- metadata.setNoteCreatedAt(noteCreatedAt);
- return this;
- }
-
- @CheckForNull
- public Long getNoteUpdatedAt() {
- return metadata.getNoteUpdatedAt();
- }
-
- public RuleDto setNoteUpdatedAt(@Nullable Long noteUpdatedAt) {
- metadata.setNoteUpdatedAt(noteUpdatedAt);
- return this;
- }
-
- @CheckForNull
- public String getRemediationFunction() {
- return metadata.getRemediationFunction();
- }
-
- public RuleDto setRemediationFunction(@Nullable String remediationFunction) {
- metadata.setRemediationFunction(remediationFunction);
- return this;
- }
-
- @CheckForNull
- public String getRemediationGapMultiplier() {
- return metadata.getRemediationGapMultiplier();
- }
-
- public RuleDto setRemediationGapMultiplier(@Nullable String remediationGapMultiplier) {
- metadata.setRemediationGapMultiplier(remediationGapMultiplier);
- return this;
- }
-
- @CheckForNull
- public String getRemediationBaseEffort() {
- return metadata.getRemediationBaseEffort();
- }
-
- public RuleDto setRemediationBaseEffort(@Nullable String remediationBaseEffort) {
- metadata.setRemediationBaseEffort(remediationBaseEffort);
- return this;
- }
-
- public Set<String> getTags() {
- return metadata.getTags();
- }
-
- /**
- * Used in MyBatis mapping.
- */
- private void setTagsField(String s) {
- metadata.setTagsField(s);
- }
-
- public RuleDto setTags(Set<String> tags) {
- this.metadata.setTags(tags);
- return this;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof RuleDto)) {
- return false;
- }
- if (this == obj) {
- return true;
- }
- RuleDto other = (RuleDto) obj;
- return new EqualsBuilder()
- .append(getRepositoryKey(), other.getRepositoryKey())
- .append(getRuleKey(), other.getRuleKey())
- .isEquals();
- }
-
- @Override
- public int hashCode() {
- return new HashCodeBuilder(17, 37)
- .append(getRepositoryKey())
- .append(getRuleKey())
- .toHashCode();
- }
-
- @Override
- public String toString() {
- return "RuleDto{" +
- "definition=" + definition +
- ", metadata=" + metadata +
- '}';
- }
-
- public static RuleDto createFor(RuleKey key) {
- return new RuleDto()
- .setRepositoryKey(key.repository())
- .setRuleKey(key.rule());
- }
-
- }
|