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 com.google.common.base.Preconditions.checkArgument;
20 import static java.util.Objects.requireNonNull;
21
22 import java.util.Objects;
23
24 import javax.annotation.Nullable;
25
26 import com.fasterxml.jackson.annotation.JsonCreator;
27 import com.fasterxml.jackson.annotation.JsonInclude;
28 import com.fasterxml.jackson.annotation.JsonInclude.Include;
29 import com.fasterxml.jackson.annotation.JsonProperty;
30 import com.google.common.base.MoreObjects.ToStringHelper;
31
32 import com.linecorp.centraldogma.common.Author;
33 import com.linecorp.centraldogma.server.storage.encryption.WrappedDekDetails;
34
35
36
37
38 @JsonInclude(Include.NON_NULL)
39 public final class CreateRepositoryCommand extends ProjectCommand<Void> {
40
41 private final String repositoryName;
42 @Nullable
43 private final WrappedDekDetails wdekDetails;
44
45 @JsonCreator
46 CreateRepositoryCommand(@JsonProperty("timestamp") @Nullable Long timestamp,
47 @JsonProperty("author") @Nullable Author author,
48 @JsonProperty("projectName") String projectName,
49 @JsonProperty("repositoryName") String repositoryName,
50 @JsonProperty("wdekDetails") @Nullable WrappedDekDetails wdekDetails) {
51 super(CommandType.CREATE_REPOSITORY, timestamp, author, projectName);
52 this.repositoryName = requireNonNull(repositoryName, "repositoryName");
53 this.wdekDetails = wdekDetails;
54 if (wdekDetails != null) {
55 checkArgument(wdekDetails.projectName().equals(projectName) &&
56 wdekDetails.repoName().equals(repositoryName),
57 "projectName: %s and repositoryName: %s, " +
58 "(expected projectName: %s and repositoryName: %s in wdekDetails)",
59 projectName, repositoryName, wdekDetails.projectName(), wdekDetails.repoName());
60 }
61 }
62
63
64
65
66 @JsonProperty
67 public String repositoryName() {
68 return repositoryName;
69 }
70
71
72
73
74 @JsonProperty
75 @Nullable
76 public WrappedDekDetails wdekDetails() {
77 return wdekDetails;
78 }
79
80 @Override
81 public boolean equals(Object obj) {
82 if (this == obj) {
83 return true;
84 }
85
86 if (!(obj instanceof CreateRepositoryCommand)) {
87 return false;
88 }
89
90 final CreateRepositoryCommand that = (CreateRepositoryCommand) obj;
91 return super.equals(obj) &&
92 repositoryName.equals(that.repositoryName) &&
93 Objects.equals(wdekDetails, that.wdekDetails);
94 }
95
96 @Override
97 public int hashCode() {
98 return (repositoryName.hashCode() * 31 + Objects.hashCode(wdekDetails)) * 31 + super.hashCode();
99 }
100
101 @Override
102 ToStringHelper toStringHelper() {
103 return super.toStringHelper().omitNullValues()
104 .add("repositoryName", repositoryName)
105 .add("wdekDetails", wdekDetails);
106 }
107 }