View Javadoc

1   /*
2    * Copyright (C) 2012 Atlassian
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://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,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.atlassian.jira.rest.client.api.domain;
17  
18  import com.atlassian.jira.rest.client.api.NamedEntity;
19  import com.google.common.base.Objects;
20  
21  import javax.annotation.Nullable;
22  import java.net.URI;
23  
24  /**
25   * Association between users and project roles.
26   *
27   * @since 1.0
28   */
29  public class RoleActor implements NamedEntity {
30  
31      /**
32       * Type of a role actor which associates a project with some particular user.
33       */
34      @SuppressWarnings("UnusedDeclaration")
35      private static final String TYPE_ATLASSIAN_USER_ROLE = "atlassian-user-role-actor";
36  
37  
38      /**
39       * Type of a role actor which associates a project with a group of users, for instance: administrators, developers.
40       */
41      @SuppressWarnings("UnusedDeclaration")
42      private static final String TYPE_ATLASSIAN_GROUP_ROLE = "atlassian-group-role-actor";
43  
44      private final Long id;
45      private final String displayName;
46      private final String type;
47      private final String name;
48      private final URI avatarUrl;
49  
50      public RoleActor(Long id, String displayName, String type, String name, @Nullable URI avatarUrl) {
51          this.id = id;
52          this.displayName = displayName;
53          this.type = type;
54          this.name = name;
55          this.avatarUrl = avatarUrl;
56      }
57  
58      @Override
59      public String getName() {
60          return name;
61      }
62  
63      /**
64       * @return the viewable name of this role actor.
65       */
66      public String getDisplayName() {
67          return displayName;
68      }
69  
70      /**
71       * @return string identifying the implementation type.
72       */
73      public String getType() {
74          return type;
75      }
76  
77      /**
78       * @return an URI of the avatar of this role actor.
79       */
80      public URI getAvatarUri() {
81          return avatarUrl;
82      }
83  
84      /**
85       * @return the unique identifier for this role actor.
86       */
87      public Long getId() {
88          return id;
89      }
90  
91      @Override
92      public boolean equals(Object o) {
93          if (o instanceof RoleActor) {
94              RoleActor that = (RoleActor) o;
95              return Objects.equal(this.getName(), that.getName())
96                      && Objects.equal(this.id, that.getId())
97                      && Objects.equal(this.getAvatarUri(), that.getAvatarUri())
98                      && Objects.equal(this.getType(), that.getType())
99                      && Objects.equal(this.getDisplayName(), that.getDisplayName());
100         }
101         return false;
102     }
103 
104     @Override
105     public int hashCode() {
106         return Objects.hashCode(super.hashCode(), name, avatarUrl, type, displayName);
107     }
108 
109     @Override
110     public String toString() {
111         return getToStringHelper().toString();
112     }
113 
114     protected Objects.ToStringHelper getToStringHelper() {
115         return Objects.toStringHelper(this)
116                 .add("displayName", displayName)
117                 .add("type", type)
118                 .add("name", name)
119                 .add("avatarUrl", avatarUrl);
120     }
121 }