All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.server.rule.index.RuleQuery Maven / Gradle / Ivy

There is a newer version: 7.2.1
Show newest version
/*
 * SonarQube
 * Copyright (C) 2009-2017 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.server.rule.index;

import com.google.common.base.Preconditions;
import java.util.Collection;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RuleType;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QProfileDto;

import static java.util.Arrays.asList;

public class RuleQuery {

  private String key;
  private String queryText;
  private Collection languages;
  private Collection repositories;
  private Collection severities;
  private Collection statuses;
  private Collection tags;
  private Collection types;
  private Boolean activation;
  private QProfileDto profile;
  private QProfileDto compareToQProfile;
  private Collection inheritance;
  private Collection activeSeverities;
  private String templateKey;
  private Boolean isTemplate;
  private Long availableSince;
  private String sortField;
  private boolean ascendingSort = true;
  private String internalKey;
  private String ruleKey;
  private OrganizationDto organization;

  @CheckForNull
  public QProfileDto getQProfile() {
    return profile;
  }

  public RuleQuery setQProfile(@Nullable QProfileDto p) {
    this.profile = p;
    return this;
  }

  public RuleQuery setActivation(@Nullable Boolean activation) {
    this.activation = activation;
    return this;
  }

  @CheckForNull
  public Boolean getActivation() {
    return this.activation;
  }

  @CheckForNull
  public String getKey() {
    return key;
  }

  public RuleQuery setKey(@Nullable String key) {
    this.key = key;
    return this;
  }

  @CheckForNull
  public String getQueryText() {
    return queryText;
  }

  /**
   * Ignored if null or blank
   */
  public RuleQuery setQueryText(@Nullable String queryText) {
    this.queryText = queryText;
    return this;
  }

  @CheckForNull
  public Collection getLanguages() {
    return languages;
  }

  public RuleQuery setLanguages(@Nullable Collection languages) {
    this.languages = languages;
    return this;
  }

  @CheckForNull
  public Collection getRepositories() {
    return repositories;
  }

  public RuleQuery setRepositories(@Nullable Collection repositories) {
    this.repositories = repositories;
    return this;
  }

  @CheckForNull
  public Collection getSeverities() {
    return severities;
  }

  public RuleQuery setSeverities(@Nullable Collection severities) {
    if (severities != null) {
      for (String severity : severities) {
        Preconditions.checkArgument(Severity.ALL.contains(severity), "Unknown severity: " + severity);
      }
    }
    this.severities = severities;
    return this;
  }

  public RuleQuery setSeverities(@Nullable String... severities) {
    if (severities != null) {
      return setSeverities(asList(severities));
    }
    return this;
  }

  @CheckForNull
  public Collection getStatuses() {
    return statuses;
  }

  public RuleQuery setStatuses(@Nullable Collection statuses) {
    this.statuses = statuses;
    return this;
  }

  @CheckForNull
  public Collection getTags() {
    return tags;
  }

  public RuleQuery setTags(@Nullable Collection tags) {
    this.tags = tags;
    return this;
  }

  @CheckForNull
  public Collection getTypes() {
    return types;
  }

  public RuleQuery setTypes(@Nullable Collection types) {
    this.types = types;
    return this;
  }

  @CheckForNull
  public Collection getInheritance() {
    return inheritance;
  }

  public RuleQuery setInheritance(@Nullable Collection inheritance) {
    this.inheritance = inheritance;
    return this;
  }

  @CheckForNull
  public Collection getActiveSeverities() {
    return activeSeverities;
  }

  public RuleQuery setActiveSeverities(@Nullable Collection severities) {
    if (severities != null) {
      for (String severity : severities) {
        Preconditions.checkArgument(Severity.ALL.contains(severity), "Unknown severity: " + severity);
      }
    }
    this.activeSeverities = severities;
    return this;
  }

  @CheckForNull
  public Boolean isTemplate() {
    return isTemplate;
  }

  public RuleQuery setIsTemplate(@Nullable Boolean b) {
    this.isTemplate = b;
    return this;
  }

  @CheckForNull
  public String templateKey() {
    return templateKey;
  }

  public RuleQuery setTemplateKey(@Nullable String templateKey) {
    this.templateKey = templateKey;
    return this;
  }

  public String getSortField() {
    return this.sortField;
  }

  public RuleQuery setSortField(@Nullable String field) {
    if (field != null && !RuleIndexDefinition.SORT_FIELDS.contains(field)) {
      throw new IllegalStateException(String.format("Field '%s' is not sortable", field));
    }
    this.sortField = field;
    return this;
  }

  public boolean isAscendingSort() {
    return ascendingSort;
  }

  public RuleQuery setAscendingSort(boolean b) {
    this.ascendingSort = b;
    return this;
  }

  public RuleQuery setAvailableSince(@Nullable Long l) {
    this.availableSince = l;
    return this;
  }

  public Long getAvailableSinceLong() {
    return this.availableSince;
  }

  public RuleQuery setInternalKey(@Nullable String s) {
    this.internalKey = s;
    return this;
  }

  @CheckForNull
  public String getInternalKey() {
    return internalKey;
  }

  public RuleQuery setRuleKey(@Nullable String s) {
    this.ruleKey = s;
    return this;
  }

  @CheckForNull
  public String getRuleKey() {
    return ruleKey;
  }

  public OrganizationDto getOrganization() {
    return organization;
  }

  public RuleQuery setOrganization(OrganizationDto o) {
    this.organization = o;
    return this;
  }

  @CheckForNull
  public QProfileDto getCompareToQProfile() {
    return compareToQProfile;
  }

  public RuleQuery setCompareToQProfile(@Nullable QProfileDto compareToQProfile) {
    this.compareToQProfile = compareToQProfile;
    return this;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy