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.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       * @return version of this JIRA instance (like "4.2.1")
60       */
61      public String getVersion() {
62          return version;
63      }
64  
65      /**
66       * @return build number
67       */
68      public int getBuildNumber() {
69          return buildNumber;
70      }
71  
72      /**
73       * @return date when the version of this JIRA instance has been built
74       */
75      public DateTime getBuildDate() {
76          return buildDate;
77      }
78  
79      /**
80       * @return current time (when the response is generated) on the server side or <code>null</code>
81       * when the user is not authenticated.
82       */
83      @Nullable
84      public DateTime getServerTime() {
85          return serverTime;
86      }
87  
88      /**
89       * @return SCM information (like SVN revision) indicated from which sources this JIRA server has been built.
90       */
91      public String getScmInfo() {
92          return scmInfo;
93      }
94  
95      /**
96       * @return name of this JIRA instance (as defined by JIRA admin)
97       */
98      public String getServerTitle() {
99          return serverTitle;
100     }
101 
102     @Override
103     public String toString() {
104         return Objects.toStringHelper(this).addValue(super.toString()).
105                 add("baseUri", baseUri).
106                 add("version", version).
107                 add("buildNumber", buildNumber).
108                 add("buildDate", buildDate).
109                 add("serverTime", serverTime).
110                 add("svnRevision", scmInfo).
111                 add("serverTitle", serverTitle).
112                 toString();
113     }
114 
115 
116     @Override
117     public boolean equals(Object obj) {
118         if (obj instanceof ServerInfo) {
119             ServerInfo that = (ServerInfo) obj;
120             return Objects.equal(this.baseUri, that.baseUri)
121                     && Objects.equal(this.version, that.version)
122                     && Objects.equal(this.buildNumber, that.buildNumber)
123                     && Objects.equal(this.buildDate, that.buildDate)
124                     && Objects.equal(this.serverTime, that.serverTime)
125                     && Objects.equal(this.scmInfo, that.scmInfo)
126                     && Objects.equal(this.serverTitle, that.serverTitle);
127         }
128         return false;
129     }
130 
131     @Override
132     public int hashCode() {
133         return Objects.hashCode(baseUri, version, buildNumber, buildDate, serverTime, scmInfo, serverTitle);
134     }
135 
136 }