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

org.sonar.server.issue.ws.SearchResponseData Maven / Gradle / Ivy

There is a newer version: 7.2.1
Show newest version
/*
 * SonarQube
 * Copyright (C) 2009-2018 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.issue.ws;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ListMultimap;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.issue.IssueChangeDto;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.issue.workflow.Transition;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * All the data required to write response of api/issues/search
 */
public class SearchResponseData {

  private final List issues;

  private Long effortTotal = null;
  private List users = null;
  private List rules = null;
  private final Map organizationKeysByUuid = new HashMap<>();
  private final Map componentsByUuid = new HashMap<>();
  private final ListMultimap commentsByIssueKey = ArrayListMultimap.create();
  private final ListMultimap actionsByIssueKey = ArrayListMultimap.create();
  private final ListMultimap transitionsByIssueKey = ArrayListMultimap.create();
  private final Set updatableComments = new HashSet<>();

  public SearchResponseData(IssueDto issue) {
    checkNotNull(issue);
    this.issues = ImmutableList.of(issue);
  }

  public SearchResponseData(List issues) {
    checkNotNull(issues);
    this.issues = issues;
  }

  public List getIssues() {
    return issues;
  }

  public Collection getComponents() {
    return componentsByUuid.values();
  }

  @CheckForNull
  public ComponentDto getComponentByUuid(String uuid) {
    return componentsByUuid.get(uuid);
  }

  @CheckForNull
  public List getUsers() {
    return users;
  }

  @CheckForNull
  public List getRules() {
    return rules;
  }

  public String getOrganizationKey(String organizationUuid) {
    String organizationKey = organizationKeysByUuid.get(organizationUuid);
    checkNotNull(organizationKey, "Organization for uuid '%s' not found", organizationUuid);
    return organizationKey;
  }

  @CheckForNull
  public List getCommentsForIssueKey(String issueKey) {
    if (commentsByIssueKey.containsKey(issueKey)) {
      return commentsByIssueKey.get(issueKey);
    }
    return null;
  }

  @CheckForNull
  public List getActionsForIssueKey(String issueKey) {
    if (actionsByIssueKey.containsKey(issueKey)) {
      return actionsByIssueKey.get(issueKey);
    }
    return null;
  }

  @CheckForNull
  public List getTransitionsForIssueKey(String issueKey) {
    if (transitionsByIssueKey.containsKey(issueKey)) {
      return transitionsByIssueKey.get(issueKey);
    }
    return null;
  }

  public void setUsers(@Nullable List users) {
    this.users = users;
  }

  public void setRules(@Nullable List rules) {
    this.rules = rules;
  }

  public void setComments(@Nullable List comments) {
    for (IssueChangeDto comment : comments) {
      commentsByIssueKey.put(comment.getIssueKey(), comment);
    }
  }

  public void addComponents(@Nullable Collection dtos) {
    if (dtos != null) {
      for (ComponentDto dto : dtos) {
        componentsByUuid.put(dto.uuid(), dto);
      }
    }
  }

  public void addActions(String issueKey, List actions) {
    actionsByIssueKey.putAll(issueKey, actions);
  }

  public void addTransitions(String issueKey, List transitions) {
    transitionsByIssueKey.putAll(issueKey, transitions);
  }

  public void addUpdatableComment(String commentKey) {
    updatableComments.add(commentKey);
  }

  public boolean isUpdatableComment(String commentKey) {
    return updatableComments.contains(commentKey);
  }

  @CheckForNull
  public Long getEffortTotal() {
    return effortTotal;
  }

  public void setEffortTotal(@Nullable Long effortTotal) {
    this.effortTotal = effortTotal;
  }

  public void addOrganization(OrganizationDto organizationDto) {
    this.organizationKeysByUuid.put(organizationDto.getUuid(), organizationDto.getKey());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy