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.CONTENTS;
20  import static com.linecorp.centraldogma.internal.api.v1.HttpApiV1Constants.PROJECTS_PREFIX;
21  import static com.linecorp.centraldogma.internal.api.v1.HttpApiV1Constants.REPOS;
22  import static java.util.Objects.requireNonNull;
23  
24  import javax.annotation.Nullable;
25  
26  import com.fasterxml.jackson.annotation.JsonInclude;
27  import com.fasterxml.jackson.annotation.JsonInclude.Include;
28  import com.fasterxml.jackson.annotation.JsonProperty;
29  import com.google.common.base.MoreObjects;
30  
31  import com.linecorp.centraldogma.common.EntryType;
32  import com.linecorp.centraldogma.common.Revision;
33  
34  @JsonInclude(Include.NON_NULL)
35  public class EntryDto<T> {
36  
37      private final Revision revision;
38  
39      private final String path;
40  
41      private final EntryType type;
42  
43      private final T content;
44  
45      private final String url;
46  
47      public EntryDto(Revision revision, String path, EntryType type,
48                      String projectName, String repoName, @Nullable T content) {
49          this.revision = requireNonNull(revision, "revision");
50          this.path = requireNonNull(path, "path");
51          this.type = requireNonNull(type, "type");
52          this.content = content;
53          url = PROJECTS_PREFIX + '/' + projectName + REPOS + '/' + repoName + CONTENTS + path;
54      }
55  
56      @JsonProperty
57      public Revision revision() {
58          return revision;
59      }
60  
61      @JsonProperty
62      public String path() {
63          return path;
64      }
65  
66      @JsonProperty
67      public EntryType type() {
68          return type;
69      }
70  
71      @JsonProperty
72      @Nullable
73      public T content() {
74          return content;
75      }
76  
77      @JsonProperty
78      @Nullable
79      public String url() {
80          return url;
81      }
82  
83      @Override
84      public String toString() {
85          return MoreObjects.toStringHelper(this).omitNullValues()
86                            .add("revision", revision)
87                            .add("path", path)
88                            .add("type", type)
89                            .add("content", content).toString();
90      }
91  }