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.server.internal.admin.dto;
18  
19  import static java.util.Objects.requireNonNull;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  import java.util.stream.Collectors;
24  
25  import com.google.common.base.MoreObjects;
26  
27  import com.linecorp.centraldogma.internal.thrift.Commit;
28  
29  public class CommitDto {
30      private RevisionDto revision;
31      private AuthorDto author;
32      private String timestamp;
33      private String summary;
34      private CommentDto detail;
35      private List<ChangeDto> diffs = new ArrayList<>();
36  
37      public CommitDto() {}
38  
39      public CommitDto(Commit commit) {
40          requireNonNull(commit, "commit");
41  
42          revision = new RevisionDto(commit.getRevision());
43          author = new AuthorDto(commit.getAuthor());
44          timestamp = commit.getTimestamp();
45          summary = commit.getSummary();
46          detail = new CommentDto(commit.getDetail());
47          diffs = commit.getDiffs().stream().map(ChangeDto::new).collect(Collectors.toList());
48      }
49  
50      public RevisionDto getRevision() {
51          return revision;
52      }
53  
54      public void setRevision(RevisionDto revision) {
55          this.revision = revision;
56      }
57  
58      public AuthorDto getAuthor() {
59          return author;
60      }
61  
62      public void setAuthor(AuthorDto author) {
63          this.author = author;
64      }
65  
66      public String getTimestamp() {
67          return timestamp;
68      }
69  
70      public void setTimestamp(String timestamp) {
71          this.timestamp = timestamp;
72      }
73  
74      public String getSummary() {
75          return summary;
76      }
77  
78      public void setSummary(String summary) {
79          this.summary = summary;
80      }
81  
82      public CommentDto getDetail() {
83          return detail;
84      }
85  
86      public void setDetail(CommentDto detail) {
87          this.detail = detail;
88      }
89  
90      public List<ChangeDto> getDiffs() {
91          return diffs;
92      }
93  
94      public void setDiffs(List<ChangeDto> diffs) {
95          this.diffs = diffs;
96      }
97  
98      @Override
99      public String toString() {
100         return MoreObjects.toStringHelper(this)
101                           .add("revision", revision)
102                           .add("author", author)
103                           .add("timestamp", timestamp)
104                           .add("summary", summary)
105                           .add("detail", detail)
106                           .add("diffs", diffs)
107                           .toString();
108     }
109 }