1   /*
2    * Copyright 2019 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.metadata;
18  
19  import static java.util.Objects.requireNonNull;
20  
21  import com.fasterxml.jackson.annotation.JsonCreator;
22  import com.fasterxml.jackson.annotation.JsonInclude;
23  import com.fasterxml.jackson.annotation.JsonInclude.Include;
24  import com.fasterxml.jackson.annotation.JsonProperty;
25  import com.google.common.base.MoreObjects;
26  
27  /**
28   * Specifies a registration of a {@link Token}.
29   */
30  @JsonInclude(Include.NON_NULL)
31  public class TokenRegistration implements Identifiable {
32  
33      /**
34       * An application identifier which belongs to a {@link Token}.
35       */
36      private final String appId;
37  
38      /**
39       * A role of the {@link Token} in a project.
40       */
41      private final ProjectRole role;
42  
43      /**
44       * Specifies when the token is registered by whom.
45       */
46      private final UserAndTimestamp creation;
47  
48      /**
49       * Creates a new instance.
50       */
51      @JsonCreator
52      public TokenRegistration(@JsonProperty("appId") String appId,
53                               @JsonProperty("role") ProjectRole role,
54                               @JsonProperty("creation") UserAndTimestamp creation) {
55          this.appId = requireNonNull(appId, "appId");
56          this.role = requireNonNull(role, "role");
57          this.creation = requireNonNull(creation, "creation");
58      }
59  
60      @Override
61      public String id() {
62          return appId;
63      }
64  
65      /**
66       * Returns the ID of the application.
67       */
68      @JsonProperty
69      public String appId() {
70          return appId;
71      }
72  
73      /**
74       * Returns the role of the token in a project.
75       */
76      @JsonProperty
77      public ProjectRole role() {
78          return role;
79      }
80  
81      /**
82       * Returns who creates the token when.
83       */
84      @JsonProperty
85      public UserAndTimestamp creation() {
86          return creation;
87      }
88  
89      @Override
90      public String toString() {
91          return MoreObjects.toStringHelper(this)
92                            .add("appId", appId())
93                            .add("role", role())
94                            .add("creation", creation())
95                            .toString();
96      }
97  }