1   /*
2    * Copyright 2017 LINE Corporation
3    *
4    * LINE Corporation licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
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 java.time.format.DateTimeFormatter.ISO_INSTANT;
21  import static java.util.Objects.requireNonNull;
22  
23  import java.time.Instant;
24  
25  import javax.annotation.Nullable;
26  
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;
31  import com.google.common.base.MoreObjects.ToStringHelper;
32  
33  import com.linecorp.centraldogma.common.Author;
34  
35  @JsonInclude(Include.NON_NULL)
36  public class ProjectDto {
37  
38      private final String name;
39  
40      private Author creator;
41  
42      private String url;
43  
44      private String reposUrl;
45  
46      private String createdAt;
47  
48      public ProjectDto(String name) {
49          this.name = requireNonNull(name, "name");
50      }
51  
52      public ProjectDto(String name, Author creator, long creationTimeMillis) {
53          this.name = requireNonNull(name, "name");
54          this.creator = requireNonNull(creator, "creator");
55          createdAt = ISO_INSTANT.format(Instant.ofEpochMilli(creationTimeMillis));
56          url = PROJECTS_PREFIX + '/' + name;
57      }
58  
59      @JsonProperty("name")
60      public String name() {
61          return name;
62      }
63  
64      @Nullable
65      @JsonProperty("creator")
66      public Author creator() {
67          return creator;
68      }
69  
70      @Nullable
71      @JsonProperty("url")
72      public String url() {
73          return url;
74      }
75  
76      @Nullable
77      @JsonProperty("reposUrl")
78      public String reposUrl() {
79          return reposUrl;
80      }
81  
82      @Nullable
83      @JsonProperty("createdAt")
84      public String createdAt() {
85          return createdAt;
86      }
87  
88      @Override
89      public String toString() {
90          final ToStringHelper stringHelper = MoreObjects.toStringHelper(this)
91                                                         .add("name", name());
92          if (creator() != null) {
93              stringHelper.add("creator", creator());
94          }
95  
96          if (createdAt() != null) {
97              stringHelper.add("createdAt", createdAt());
98          }
99          return stringHelper.toString();
100     }
101 }
102