1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.linecorp.centraldogma.client;
17
18 import static java.util.Objects.requireNonNull;
19
20 import java.util.Objects;
21 import java.util.concurrent.CompletableFuture;
22 import java.util.concurrent.ScheduledExecutorService;
23
24 import com.google.common.base.MoreObjects;
25 import com.google.common.collect.ImmutableList;
26
27 import com.linecorp.centraldogma.common.Change;
28 import com.linecorp.centraldogma.common.Markup;
29 import com.linecorp.centraldogma.common.MergeQuery;
30 import com.linecorp.centraldogma.common.MergeSource;
31 import com.linecorp.centraldogma.common.PathPattern;
32 import com.linecorp.centraldogma.common.Query;
33 import com.linecorp.centraldogma.common.QueryType;
34 import com.linecorp.centraldogma.common.Revision;
35
36
37
38
39 public final class CentralDogmaRepository {
40
41 private final CentralDogma centralDogma;
42 private final String projectName;
43 private final String repositoryName;
44 private final ScheduledExecutorService blockingTaskExecutor;
45
46 CentralDogmaRepository(CentralDogma centralDogma, String projectName, String repositoryName,
47 ScheduledExecutorService blockingTaskExecutor) {
48 this.centralDogma = centralDogma;
49 this.projectName = projectName;
50 this.repositoryName = repositoryName;
51 this.blockingTaskExecutor = blockingTaskExecutor;
52 }
53
54 CentralDogma centralDogma() {
55 return centralDogma;
56 }
57
58 String projectName() {
59 return projectName;
60 }
61
62 String repositoryName() {
63 return repositoryName;
64 }
65
66
67
68
69
70
71 public CompletableFuture<Revision> normalize(Revision revision) {
72 requireNonNull(revision, "revision");
73 return centralDogma.normalizeRevision(projectName, repositoryName, revision);
74 }
75
76
77
78
79
80
81 public FileRequest<?> file(String path) {
82 requireNonNull(path, "path");
83 return file(Query.of(QueryType.IDENTITY, path));
84 }
85
86
87
88
89
90
91 public <T> FileRequest<T> file(Query<T> query) {
92 requireNonNull(query, "query");
93 return new FileRequest<>(this, query);
94 }
95
96
97
98
99
100
101 public FilesRequest file(PathPattern pathPattern) {
102 requireNonNull(pathPattern, "pathPattern");
103 return new FilesRequest(this, pathPattern);
104 }
105
106
107
108
109
110
111
112 public MergeRequest<?> merge(MergeSource... mergeSources) {
113 requireNonNull(mergeSources, "mergeSources");
114 return merge(ImmutableList.copyOf(mergeSources));
115 }
116
117
118
119
120
121
122
123 public MergeRequest<?> merge(Iterable<MergeSource> mergeSources) {
124 requireNonNull(mergeSources, "mergeSources");
125 return merge(MergeQuery.ofJson(mergeSources));
126 }
127
128
129
130
131
132
133
134 public <T> MergeRequest<T> merge(MergeQuery<T> mergeQuery) {
135 requireNonNull(mergeQuery, "mergeQuery");
136 return new MergeRequest<>(this, mergeQuery);
137 }
138
139
140
141
142
143
144
145 public HistoryRequest history() {
146 return history(PathPattern.all());
147 }
148
149
150
151
152
153
154
155 public HistoryRequest history(PathPattern pathPattern) {
156 requireNonNull(pathPattern, "pathPattern");
157 return new HistoryRequest(this, pathPattern);
158 }
159
160
161
162
163
164
165
166 public DiffRequest<?> diff(String path) {
167 requireNonNull(path, "path");
168 return diff(Query.of(QueryType.IDENTITY, path));
169 }
170
171
172
173
174
175
176
177 public <T> DiffRequest<T> diff(Query<T> query) {
178 requireNonNull(query, "query");
179 return new DiffRequest<>(this, query);
180 }
181
182
183
184
185
186
187
188 public DiffFilesRequest diff(PathPattern pathPattern) {
189 requireNonNull(pathPattern, "pathPattern");
190 return new DiffFilesRequest(this, pathPattern);
191 }
192
193
194
195
196
197
198
199 public PreviewDiffRequest diff(Change<?>... changes) {
200 requireNonNull(changes, "changes");
201 return new PreviewDiffRequest(this, ImmutableList.copyOf(changes));
202 }
203
204
205
206
207
208
209
210 public PreviewDiffRequest diff(Iterable<? extends Change<?>> changes) {
211 requireNonNull(changes, "changes");
212 return new PreviewDiffRequest(this, changes);
213 }
214
215
216
217
218
219
220
221 public CommitRequest commit(String summary, Change<?>... changes) {
222 requireNonNull(changes, "changes");
223 return commit(summary, ImmutableList.copyOf(changes));
224 }
225
226
227
228
229
230
231
232 public CommitRequest commit(String summary, Iterable<? extends Change<?>> changes) {
233 requireNonNull(summary, "summary");
234 requireNonNull(changes, "changes");
235 return new CommitRequest(this, summary, changes);
236 }
237
238
239
240
241
242
243
244 public WatchRequest<?> watch(String path) {
245 requireNonNull(path, "path");
246 return watch(Query.of(QueryType.IDENTITY, path));
247 }
248
249
250
251
252
253
254
255 public <T> WatchRequest<T> watch(Query<T> query) {
256 requireNonNull(query, "query");
257 return new WatchRequest<>(this, query);
258 }
259
260
261
262
263
264
265
266 public WatchFilesRequest watch(PathPattern pathPattern) {
267 requireNonNull(pathPattern, "pathPattern");
268 return new WatchFilesRequest(this, pathPattern);
269 }
270
271
272
273
274 public <T> WatcherRequest<T> watcher(Query<T> query) {
275 requireNonNull(query, "query");
276 return new WatcherRequest<>(this, query, blockingTaskExecutor);
277 }
278
279
280
281
282 public WatcherRequest<Revision> watcher(PathPattern pathPattern) {
283 requireNonNull(pathPattern, "pathPattern");
284 return new WatcherRequest<>(this, pathPattern, blockingTaskExecutor);
285 }
286
287 @Override
288 public boolean equals(Object o) {
289 if (this == o) {
290 return true;
291 }
292 if (!(o instanceof CentralDogmaRepository)) {
293 return false;
294 }
295 final CentralDogmaRepository that = (CentralDogmaRepository) o;
296 return centralDogma == that.centralDogma &&
297 projectName.equals(that.projectName) && repositoryName.equals(that.repositoryName) &&
298 blockingTaskExecutor == that.blockingTaskExecutor;
299 }
300
301 @Override
302 public int hashCode() {
303 return Objects.hash(centralDogma, projectName, repositoryName, blockingTaskExecutor);
304 }
305
306 @Override
307 public String toString() {
308 return MoreObjects.toStringHelper(this)
309 .add("centralDogma", centralDogma)
310 .add("projectName", projectName)
311 .add("repositoryName", repositoryName)
312 .add("blockingTaskExecutor", blockingTaskExecutor)
313 .toString();
314 }
315 }