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