1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.linecorp.centraldogma.internal.api.v1;
18
19 import static com.linecorp.centraldogma.internal.api.v1.HttpApiV1Constants.PROJECTS_PREFIX;
20 import static com.linecorp.centraldogma.internal.api.v1.HttpApiV1Constants.REPOS;
21 import static java.time.format.DateTimeFormatter.ISO_INSTANT;
22 import static java.util.Objects.requireNonNull;
23
24 import java.time.Instant;
25
26 import javax.annotation.Nullable;
27
28 import com.fasterxml.jackson.annotation.JsonInclude;
29 import com.fasterxml.jackson.annotation.JsonInclude.Include;
30 import com.fasterxml.jackson.annotation.JsonProperty;
31 import com.google.common.base.MoreObjects;
32 import com.google.common.base.MoreObjects.ToStringHelper;
33
34 import com.linecorp.centraldogma.common.Author;
35 import com.linecorp.centraldogma.common.Revision;
36
37 @JsonInclude(Include.NON_NULL)
38 public class RepositoryDto {
39
40 private final String name;
41
42 private Author creator;
43
44 private Revision headRevision;
45
46 private String url;
47
48 private String commitsUrl;
49
50 private String compareUrl;
51
52 private String contentsUrl;
53
54 private String createdAt;
55
56 public RepositoryDto(String name) {
57 this.name = requireNonNull(name, "name");
58 }
59
60 public RepositoryDto(String projectName, String repoName, Author creator, Revision headRevision,
61 long creationTimeMillis) {
62 name = requireNonNull(repoName, "repoName");
63 this.creator = requireNonNull(creator, "creator");
64 this.headRevision = requireNonNull(headRevision, "headRevision");
65 url = PROJECTS_PREFIX + '/' + requireNonNull(projectName, "projectName") + REPOS + '/' + repoName;
66 createdAt = ISO_INSTANT.format(Instant.ofEpochMilli(creationTimeMillis));
67 }
68
69 @JsonProperty("name")
70 public String name() {
71 return name;
72 }
73
74 @Nullable
75 @JsonProperty("creator")
76 public Author creator() {
77 return creator;
78 }
79
80 @Nullable
81 @JsonProperty("headRevision")
82 public Revision headRevision() {
83 return headRevision;
84 }
85
86 @Nullable
87 @JsonProperty("url")
88 public String url() {
89 return url;
90 }
91
92 @Nullable
93 @JsonProperty("commitsUrl")
94 public String commitsUrl() {
95 return commitsUrl;
96 }
97
98 @Nullable
99 @JsonProperty("compareUrl")
100 public String compareUrl() {
101 return compareUrl;
102 }
103
104 @Nullable
105 @JsonProperty("contentsUrl")
106 public String contentsUrl() {
107 return contentsUrl;
108 }
109
110 @Nullable
111 @JsonProperty("createdAt")
112 public String createdAt() {
113 return createdAt;
114 }
115
116 @Override
117 public String toString() {
118 final ToStringHelper stringHelper = MoreObjects.toStringHelper(this)
119 .add("name", name());
120 if (creator() != null) {
121 stringHelper.add("creator", creator());
122 }
123
124 if (headRevision() != null) {
125 stringHelper.add("headRevision", headRevision());
126 }
127
128 if (createdAt() != null) {
129 stringHelper.add("createdAt", createdAt());
130 }
131
132 return stringHelper.toString();
133 }
134 }