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.google.common.base.Objects;
20  import org.joda.time.DateTime;
21  
22  import javax.annotation.Nullable;
23  import java.net.URI;
24  
25  /**
26   * Basic information about JIRA server
27   *
28   * @since v0.1
29   */
30  public class ServerInfo {
31  	private final URI baseUri;
32  	private final String version;
33  	private final int buildNumber;
34  	private final DateTime buildDate;
35  	@Nullable
36  	private final DateTime serverTime;
37  	private final String scmInfo;
38  	private final String serverTitle;
39  
40  	public ServerInfo(URI baseUri, String version, int buildNumber, DateTime buildDate, @Nullable DateTime serverTime,
41  					  String scmInfo, String serverTitle) {
42  		this.baseUri = baseUri;
43  		this.version = version;
44  		this.buildNumber = buildNumber;
45  		this.buildDate = buildDate;
46  		this.serverTime = serverTime;
47  		this.scmInfo = scmInfo;
48  		this.serverTitle = serverTitle;
49  	}
50  
51  	/**
52  	 * @return base URI of this JIRA instance
53  	 */
54  	public URI getBaseUri() {
55  		return baseUri;
56  	}
57  
58  	/**
59  	 *
60  	 * @return version of this JIRA instance (like "4.2.1")
61  	 */
62  	public String getVersion() {
63  		return version;
64  	}
65  
66  	/**
67  	 * @return build number
68  	 */
69  	public int getBuildNumber() {
70  		return buildNumber;
71  	}
72  
73  	/**
74  	 * @return date when the version of this JIRA instance has been built
75  	 */
76  	public DateTime getBuildDate() {
77  		return buildDate;
78  	}
79  
80  	/**
81  	 * @return current time (when the response is generated) on the server side or <code>null</code>
82  	 * when the user is not authenticated.
83  	 */
84  	@Nullable
85  	public DateTime getServerTime() {
86  		return serverTime;
87  	}
88  
89  	/**
90  	 * @return SCM information (like SVN revision) indicated from which sources this JIRA server has been built.
91  	 */
92  	public String getScmInfo() {
93  		return scmInfo;
94  	}
95  
96  	/**
97  	 * @return name of this JIRA instance (as defined by JIRA admin)
98  	 */
99  	public String getServerTitle() {
100 		return serverTitle;
101 	}
102 
103 	@Override
104 	public String toString() {
105 		return Objects.toStringHelper(this).addValue(super.toString()).
106 				add("baseUri", baseUri).
107 				add("version", version).
108 				add("buildNumber", buildNumber).
109 				add("buildDate", buildDate).
110 				add("serverTime", serverTime).
111 				add("svnRevision", scmInfo).
112 				add("serverTitle", serverTitle).
113 				toString();
114 	}
115 
116 
117 	@Override
118 	public boolean equals(Object obj) {
119 		if (obj instanceof ServerInfo) {
120 			ServerInfo that = (ServerInfo) obj;
121 			return Objects.equal(this.baseUri, that.baseUri)
122 					&& Objects.equal(this.version, that.version)
123 					&& Objects.equal(this.buildNumber, that.buildNumber)
124 					&& Objects.equal(this.buildDate, that.buildDate)
125 					&& Objects.equal(this.serverTime, that.serverTime)
126 					&& Objects.equal(this.scmInfo, that.scmInfo)
127 					&& Objects.equal(this.serverTitle, that.serverTitle);
128 		}
129 		return false;
130 	}
131 
132 	@Override
133 	public int hashCode() {
134 		return Objects.hashCode(baseUri, version, buildNumber, buildDate, serverTime, scmInfo, serverTitle);
135 	}
136 
137 }