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 java.time.format.DateTimeFormatter.ISO_INSTANT;
20  import static java.util.Objects.requireNonNull;
21  
22  import java.time.Instant;
23  
24  import com.fasterxml.jackson.annotation.JsonInclude;
25  import com.fasterxml.jackson.annotation.JsonInclude.Include;
26  import com.fasterxml.jackson.annotation.JsonProperty;
27  import com.google.common.base.MoreObjects;
28  
29  import com.linecorp.centraldogma.common.Author;
30  import com.linecorp.centraldogma.common.Revision;
31  
32  @JsonInclude(Include.NON_EMPTY)
33  public class CommitDto {
34  
35      private final Revision revision;
36  
37      private final Author author;
38  
39      private final CommitMessageDto commitMessage;
40  
41      private final String pushedAt;
42  
43      public CommitDto(Revision revision, Author author, CommitMessageDto commitMessage, long commitTimeMillis) {
44          this.revision = requireNonNull(revision, "revision");
45          this.author = requireNonNull(author, "author");
46          this.commitMessage = requireNonNull(commitMessage, "commitMessage");
47          pushedAt = ISO_INSTANT.format(Instant.ofEpochMilli(commitTimeMillis));
48      }
49  
50      @JsonProperty("revision")
51      public Revision revision() {
52          return revision;
53      }
54  
55      @JsonProperty("author")
56      public Author author() {
57          return author;
58      }
59  
60      @JsonProperty("commitMessage")
61      public CommitMessageDto commitMessage() {
62          return commitMessage;
63      }
64  
65      @JsonProperty("pushedAt")
66      public String pushedAt() {
67          return pushedAt;
68      }
69  
70      @Override
71      public String toString() {
72          return MoreObjects.toStringHelper(this)
73                            .add("revision", revision())
74                            .add("author", author())
75                            .add("commitMessage", commitMessage())
76                            .add("pushedAt", pushedAt())
77                            .toString();
78      }
79  }