123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474 |
- /*
- * 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.server.issue.notification;
-
- import com.google.common.collect.ImmutableSet;
- import java.util.Objects;
- import java.util.Optional;
- import java.util.Set;
- import javax.annotation.CheckForNull;
- import javax.annotation.Nullable;
- import javax.annotation.concurrent.Immutable;
- import org.sonar.api.rule.RuleKey;
- import org.sonar.api.rules.RuleType;
-
- import static com.google.common.base.Preconditions.checkArgument;
- import static java.util.Objects.requireNonNull;
- import static java.util.Optional.ofNullable;
-
- @Immutable
- public class IssuesChangesNotificationBuilder {
-
- private static final String KEY_CANT_BE_NULL_MESSAGE = "key can't be null";
- private final Set<ChangedIssue> issues;
- private final Change change;
-
- public IssuesChangesNotificationBuilder(Set<ChangedIssue> issues, Change change) {
- checkArgument(!issues.isEmpty(), "issues can't be empty");
-
- this.issues = ImmutableSet.copyOf(issues);
- this.change = requireNonNull(change, "change can't be null");
- }
-
- public Set<ChangedIssue> getIssues() {
- return issues;
- }
-
- public Change getChange() {
- return change;
- }
-
- @Immutable
- public static final class ChangedIssue {
- private final String key;
- private final String newStatus;
- @CheckForNull
- private final String newResolution;
- @CheckForNull
- private final User assignee;
- private final Rule rule;
- private final Project project;
-
- public ChangedIssue(Builder builder) {
- this.key = requireNonNull(builder.key, KEY_CANT_BE_NULL_MESSAGE);
- this.newStatus = requireNonNull(builder.newStatus, "newStatus can't be null");
- this.newResolution = builder.newResolution;
- this.assignee = builder.assignee;
- this.rule = requireNonNull(builder.rule, "rule can't be null");
- this.project = requireNonNull(builder.project, "project can't be null");
- }
-
- public String getKey() {
- return key;
- }
-
- public String getNewStatus() {
- return newStatus;
- }
-
- public Optional<String> getNewResolution() {
- return ofNullable(newResolution);
- }
-
- public Optional<User> getAssignee() {
- return ofNullable(assignee);
- }
-
- public Rule getRule() {
- return rule;
- }
-
- public Project getProject() {
- return project;
- }
-
- public static class Builder {
- private final String key;
- private String newStatus;
- @CheckForNull
- private String newResolution;
- @CheckForNull
- private User assignee;
- private Rule rule;
- private Project project;
-
- public Builder(String key) {
- this.key = key;
- }
-
- public Builder setNewStatus(String newStatus) {
- this.newStatus = newStatus;
- return this;
- }
-
- public Builder setNewResolution(@Nullable String newResolution) {
- this.newResolution = newResolution;
- return this;
- }
-
- public Builder setAssignee(@Nullable User assignee) {
- this.assignee = assignee;
- return this;
- }
-
- public Builder setRule(Rule rule) {
- this.rule = rule;
- return this;
- }
-
- public Builder setProject(Project project) {
- this.project = project;
- return this;
- }
-
- public ChangedIssue build() {
- return new ChangedIssue(this);
- }
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- ChangedIssue that = (ChangedIssue) o;
- return key.equals(that.key) &&
- newStatus.equals(that.newStatus) &&
- Objects.equals(newResolution, that.newResolution) &&
- Objects.equals(assignee, that.assignee) &&
- rule.equals(that.rule) &&
- project.equals(that.project);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(key, newStatus, newResolution, assignee, rule, project);
- }
-
- @Override
- public String toString() {
- return "ChangedIssue{" +
- "key='" + key + '\'' +
- ", newStatus='" + newStatus + '\'' +
- ", newResolution='" + newResolution + '\'' +
- ", assignee=" + assignee +
- ", rule=" + rule +
- ", project=" + project +
- '}';
- }
- }
-
- public static final class User {
- private final String uuid;
- private final String login;
- @CheckForNull
- private final String name;
-
- public User(String uuid, String login, @Nullable String name) {
- this.uuid = requireNonNull(uuid, "uuid can't be null");
- this.login = requireNonNull(login, "login can't be null");
- this.name = name;
- }
-
- public String getUuid() {
- return uuid;
- }
-
- public String getLogin() {
- return login;
- }
-
- public Optional<String> getName() {
- return ofNullable(name);
- }
-
- @Override
- public String toString() {
- return "User{" +
- "uuid='" + uuid + '\'' +
- ", login='" + login + '\'' +
- ", name='" + name + '\'' +
- '}';
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- User user = (User) o;
- return uuid.equals(user.uuid) &&
- login.equals(user.login) &&
- Objects.equals(name, user.name);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(uuid, login, name);
- }
- }
-
- @Immutable
- public static final class Rule {
- private final RuleKey key;
- private final RuleType ruleType;
- private final String name;
-
- public Rule(RuleKey key, @Nullable String ruleType, String name) {
- this(key, ruleType != null ? RuleType.valueOf(ruleType) : null, name);
- }
-
- public Rule(RuleKey key, @Nullable RuleType ruleType, String name) {
- this.key = requireNonNull(key, KEY_CANT_BE_NULL_MESSAGE);
- this.ruleType = ruleType;
- this.name = requireNonNull(name, "name can't be null");
- }
-
- public RuleKey getKey() {
- return key;
- }
-
- @CheckForNull
- public RuleType getRuleType() {
- return ruleType;
- }
-
- public String getName() {
- return name;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- Rule that = (Rule) o;
- return key.equals(that.key) && ruleType.equals(that.ruleType) && name.equals(that.name);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(key, ruleType, name);
- }
-
- @Override
- public String toString() {
- return "Rule{" +
- "key=" + key +
- ", type=" + ruleType +
- ", name='" + name + '\'' +
- '}';
- }
- }
-
- @Immutable
- public static final class Project {
- private final String uuid;
- private final String key;
- private final String projectName;
- @Nullable
- private final String branchName;
-
- public Project(Builder builder) {
- this.uuid = requireNonNull(builder.uuid, "uuid can't be null");
- this.key = requireNonNull(builder.key, KEY_CANT_BE_NULL_MESSAGE);
- this.projectName = requireNonNull(builder.projectName, "projectName can't be null");
- this.branchName = builder.branchName;
- }
-
- public String getUuid() {
- return uuid;
- }
-
- public String getKey() {
- return key;
- }
-
- public String getProjectName() {
- return projectName;
- }
-
- public Optional<String> getBranchName() {
- return ofNullable(branchName);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- Project project = (Project) o;
- return uuid.equals(project.uuid) &&
- key.equals(project.key) &&
- projectName.equals(project.projectName) &&
- Objects.equals(branchName, project.branchName);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(uuid, key, projectName, branchName);
- }
-
- @Override
- public String toString() {
- return "Project{" +
- "uuid='" + uuid + '\'' +
- ", key='" + key + '\'' +
- ", projectName='" + projectName + '\'' +
- ", branchName='" + branchName + '\'' +
- '}';
- }
-
- public static class Builder {
- private final String uuid;
- private String key;
- private String projectName;
- @CheckForNull
- private String branchName;
-
- public Builder(String uuid) {
- this.uuid = uuid;
- }
-
- public Builder setKey(String key) {
- this.key = key;
- return this;
- }
-
- public Builder setProjectName(String projectName) {
- this.projectName = projectName;
- return this;
- }
-
- public Builder setBranchName(@Nullable String branchName) {
- this.branchName = branchName;
- return this;
- }
-
- public Project build() {
- return new Project(this);
- }
- }
- }
-
- public abstract static class Change {
- protected final long date;
-
- private Change(long date) {
- this.date = date;
- }
-
- public long getDate() {
- return date;
- }
-
- public abstract boolean isAuthorLogin(String login);
- }
-
- @Immutable
- public static final class AnalysisChange extends Change {
- public AnalysisChange(long date) {
- super(date);
- }
-
- @Override
- public boolean isAuthorLogin(String login) {
- return false;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- Change change = (Change) o;
- return date == change.date;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(date);
- }
-
- @Override
- public String toString() {
- return "AnalysisChange{" + date + '}';
- }
- }
-
- @Immutable
- public static final class UserChange extends Change {
- private final User user;
-
- public UserChange(long date, User user) {
- super(date);
- this.user = requireNonNull(user, "user can't be null");
- }
-
- public User getUser() {
- return user;
- }
-
- @Override
- public boolean isAuthorLogin(String login) {
- return this.user.login.equals(login);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- UserChange that = (UserChange) o;
- return date == that.date && user.equals(that.user);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(user, date);
- }
-
- @Override
- public String toString() {
- return "UserChange{" +
- "date=" + date +
- ", user=" + user +
- '}';
- }
- }
- }
|