View Javadoc

1   /*
2    * Copyright (C) 2010 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  
17  package com.atlassian.jira.rest.client.api.domain;
18  
19  import com.atlassian.jira.rest.client.api.ExpandableProperty;
20  import com.google.common.base.Objects;
21  import com.google.common.base.Preconditions;
22  import com.google.common.collect.Maps;
23  
24  import javax.annotation.Nullable;
25  import java.net.URI;
26  import java.util.Map;
27  
28  /**
29   * Complete information about a single JIRA user
30   *
31   * @since v0.1
32   */
33  public class User extends BasicUser {
34  
35      public static String S16_16 = "16x16";
36      public static String S48_48 = "48x48";
37  
38      private final String emailAddress;
39  
40      private final ExpandableProperty<String> groups;
41  
42      private Map<String, URI> avatarUris;
43  
44      /**
45       * @since com.atlassian.jira.rest.client.api 0.5, server: 4.4
46       */
47      @Nullable
48      private String timezone;
49  
50      public User(URI self, String name, String displayName, String emailAddress, @Nullable ExpandableProperty<String> groups,
51                  Map<String, URI> avatarUris, @Nullable String timezone) {
52          super(self, name, displayName);
53          Preconditions.checkNotNull(avatarUris.get(S48_48), "At least one avatar URL is expected - for 48x48");
54          this.timezone = timezone;
55          this.emailAddress = emailAddress;
56          this.avatarUris = Maps.newHashMap(avatarUris);
57          this.groups = groups;
58      }
59  
60      public String getEmailAddress() {
61          return emailAddress;
62      }
63  
64      public URI getAvatarUri() {
65          return avatarUris.get(S48_48);
66      }
67  
68      /**
69       * @return user avatar image URI for 16x16 pixels
70       * @since 0.5 com.atlassian.jira.rest.client.api, 5.0 server
71       */
72      @Nullable
73      public URI getSmallAvatarUri() {
74          return avatarUris.get(S16_16);
75      }
76  
77      /**
78       * As of JIRA 5.0 there can be several different user avatar URIs - for different size.
79       *
80       * @param sizeDefinition size like "16x16" or "48x48". URI for 48x48 should be always defined.
81       * @return URI for specified size or <code>null</code> when there is no avatar image with given dimensions specified for this user
82       */
83      @SuppressWarnings("UnusedDeclaration")
84      @Nullable
85      public URI getAvatarUri(String sizeDefinition) {
86          return avatarUris.get(sizeDefinition);
87      }
88  
89      /**
90       * @return groups given user belongs to
91       */
92      @Nullable
93      public ExpandableProperty<String> getGroups() {
94          return groups;
95      }
96  
97      @Override
98      public boolean equals(Object obj) {
99          if (obj instanceof User) {
100             User that = (User) obj;
101             return super.equals(obj) && Objects.equal(this.emailAddress, that.emailAddress)
102                     && Objects.equal(this.avatarUris, that.avatarUris);
103         }
104         return false;
105     }
106 
107     @Override
108     public int hashCode() {
109         return Objects.hashCode(super.hashCode(), emailAddress, avatarUris, groups, timezone);
110     }
111 
112     /**
113      * @return user timezone, like "Europe/Berlin" or <code>null</code> if timezone info is not available
114      * @since com.atlassian.jira.rest.client.api 0.5, server 4.4
115      */
116     @Nullable
117     public String getTimezone() {
118         return timezone;
119     }
120 
121     @Override
122     protected Objects.ToStringHelper getToStringHelper() {
123         return super.getToStringHelper().add("emailAddress", emailAddress).
124                 add("avatarUris", avatarUris).
125                 add("groups", groups).
126                 add("timezone", timezone);
127     }
128 
129 }