1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.linecorp.centraldogma.server.command;
18
19 import static java.util.Objects.requireNonNull;
20
21 import java.util.Objects;
22
23 import javax.annotation.Nullable;
24
25 import com.fasterxml.jackson.annotation.JsonProperty;
26 import com.google.common.base.MoreObjects.ToStringHelper;
27
28 import com.linecorp.centraldogma.common.Author;
29
30
31
32
33
34
35 public abstract class RepositoryCommand<T> extends AbstractCommand<T> {
36
37 private final String projectName;
38 private final String repositoryName;
39
40 RepositoryCommand(CommandType commandType, @Nullable Long timestamp, @Nullable Author author,
41 String projectName, String repositoryName) {
42 super(commandType, timestamp, author);
43 this.projectName = requireNonNull(projectName, "projectName");
44 this.repositoryName = requireNonNull(repositoryName, "repositoryName");
45 }
46
47
48
49
50 @JsonProperty
51 public final String projectName() {
52 return projectName;
53 }
54
55
56
57
58 @JsonProperty
59 public final String repositoryName() {
60 return repositoryName;
61 }
62
63 @Override
64 public final String executionPath() {
65 return String.format("/%s/%s", projectName, repositoryName);
66 }
67
68 @Override
69 public boolean equals(Object obj) {
70 if (this == obj) {
71 return true;
72 }
73
74 if (!(obj instanceof RepositoryCommand)) {
75 return false;
76 }
77
78 final RepositoryCommand<?> that = (RepositoryCommand<?>) obj;
79 return super.equals(that) &&
80 projectName.equals(that.projectName) &&
81 repositoryName.equals(that.repositoryName);
82 }
83
84 @Override
85 public int hashCode() {
86 return Objects.hash(projectName, repositoryName) * 31 + super.hashCode();
87 }
88
89 @Override
90 ToStringHelper toStringHelper() {
91 return super.toStringHelper()
92 .add("projectName", projectName)
93 .add("repositoryName", repositoryName);
94 }
95 }