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.domain;
17  
18  import com.atlassian.jira.rest.client.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   * @since 1.0
27   */
28  public class RoleActor implements NamedEntity {
29  
30  	/**
31  	 * Type of a role actor which associates a project with some particular user.
32  	 */
33  	@SuppressWarnings("UnusedDeclaration")
34  	private static final String TYPE_ATLASSIAN_USER_ROLE = "atlassian-user-role-actor";
35  
36  
37  	/**
38  	 * Type of a role actor which associates a project with a group of users, for instance: administrators, developers.
39  	 */
40  	@SuppressWarnings("UnusedDeclaration")
41  	private static final String TYPE_ATLASSIAN_GROUP_ROLE = "atlassian-group-role-actor";
42  
43  	private final Long id;
44  	private final String displayName;
45  	private final String type;
46  	private final String name;
47  	private final URI avatarUrl;
48  
49  	public RoleActor(Long id, String displayName, String type, String name, @Nullable URI avatarUrl) {
50  		this.id = id;
51  		this.displayName = displayName;
52  		this.type = type;
53  		this.name = name;
54  		this.avatarUrl = avatarUrl;
55  	}
56  
57  	@Override
58  	public String getName() {
59  		return name;
60  	}
61  
62  	/**
63  	 * @return the viewable name of this role actor.
64  	 */
65  	public String getDisplayName() {
66  		return displayName;
67  	}
68  
69  	/**
70  	 * @return string identifying the implementation type.
71  	 */
72  	public String getType() {
73  		return type;
74  	}
75  
76  	/**
77  	 * @return an URI of the avatar of this role actor.
78  	 */
79  	public URI getAvatarUri() {
80  		return avatarUrl;
81  	}
82  
83  	/**
84  	 * @return the unique identifier for this role actor.
85  	 */
86  	public Long getId() {
87  		return id;
88  	}
89  
90  	@Override
91  	public boolean equals(Object o) {
92  		if (o instanceof RoleActor) {
93  			RoleActor that = (RoleActor) o;
94  			return Objects.equal(this.getName(), that.getName())
95  					&& Objects.equal(this.id, that.getId())
96  					&& Objects.equal(this.getAvatarUri(), that.getAvatarUri())
97  					&& Objects.equal(this.getType(), that.getType())
98  					&& Objects.equal(this.getDisplayName(), that.getDisplayName());
99  		}
100 		return false;
101 	}
102 
103 	@Override
104 	public int hashCode() {
105 		return Objects.hashCode(super.hashCode(), name, avatarUrl, type, displayName);
106 	}
107 
108 	@Override
109 	public String toString() {
110 		return getToStringHelper().toString();
111 	}
112 
113 	protected Objects.ToStringHelper getToStringHelper() {
114 		return Objects.toStringHelper(this)
115 				.add("displayName", displayName)
116 				.add("type", type)
117 				.add("name", name)
118 				.add("avatarUrl", avatarUrl);
119 	}
120 }