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.AddressableEntity;
20  import com.atlassian.jira.rest.client.NamedEntity;
21  import com.google.common.base.Objects;
22  
23  import java.net.URI;
24  
25  /**
26   * Basic information about a JIRA user
27   *
28   * @since v0.1
29   */
30  public class BasicUser implements AddressableEntity, NamedEntity {
31  
32  	/**
33  	 * This value is used to mark incomplete user URI - when server response with user without selfUri set.
34  	 * This may happen due to bug in JIRA REST API - for example in JRA-30263 bug, JIRA REST API will return
35  	 * user without selfUri for deleted author of worklog entry.
36  	 */
37  	public static URI INCOMPLETE_URI = URI.create("incomplete://user");
38  
39      private final String name;
40      private final String displayName;
41      private final URI self;
42  
43      public BasicUser(URI self, String name, String displayName) {
44          this.self = self;
45          this.name = name;
46          this.displayName = displayName;
47      }
48  
49      public String getName() {
50          return name;
51      }
52  
53      public String getDisplayName() {
54          return displayName;
55      }
56  
57      @Override
58  	public URI getSelf() {
59          return self;
60      }
61  
62      @Override
63      public String toString() {
64          return Objects.toStringHelper(this).add("name", name)
65                  .add("displayName", displayName).add("self", self).toString();
66      }
67  
68      @Override
69      public boolean equals(Object obj) {
70          if (obj instanceof BasicUser) {
71              BasicUser that = (BasicUser) obj;
72              return Objects.equal(this.self, that.self)
73                      && Objects.equal(this.name, that.name)
74                      && Objects.equal(this.displayName, that.displayName);
75          }
76          return false;
77      }
78  
79      @Override
80      public int hashCode() {
81          return Objects.hashCode(self, name, displayName);
82      }
83  
84  	/**
85  	 * @return true when URI returned from server was incomplete. See {@link BasicUser#INCOMPLETE_URI} for more detail.
86  	 */
87  	public boolean isSelfUriIncomplete() {
88  		return INCOMPLETE_URI.equals(self);
89  	}
90  
91  }