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.internal.async;
17  
18  import com.atlassian.jira.rest.client.api.AuditRestClient;
19  import com.atlassian.jira.rest.client.api.ComponentRestClient;
20  import com.atlassian.jira.rest.client.api.IssueRestClient;
21  import com.atlassian.jira.rest.client.api.JiraRestClient;
22  import com.atlassian.jira.rest.client.api.MetadataRestClient;
23  import com.atlassian.jira.rest.client.api.MyPermissionsRestClient;
24  import com.atlassian.jira.rest.client.api.ProjectRestClient;
25  import com.atlassian.jira.rest.client.api.ProjectRolesRestClient;
26  import com.atlassian.jira.rest.client.api.SearchRestClient;
27  import com.atlassian.jira.rest.client.api.SessionRestClient;
28  import com.atlassian.jira.rest.client.api.UserRestClient;
29  import com.atlassian.jira.rest.client.api.VersionRestClient;
30  
31  import javax.ws.rs.core.UriBuilder;
32  import java.io.IOException;
33  import java.net.URI;
34  
35  /**
36   * Asynchronous implementation of JIRA REST com.atlassian.jira.rest.client.
37   *
38   * @since v2.0
39   */
40  public class AsynchronousJiraRestClient implements JiraRestClient {
41  
42      private final IssueRestClient issueRestClient;
43      private final SessionRestClient sessionRestClient;
44      private final UserRestClient userRestClient;
45      private final ProjectRestClient projectRestClient;
46      private final ComponentRestClient componentRestClient;
47      private final MetadataRestClient metadataRestClient;
48      private final SearchRestClient searchRestClient;
49      private final VersionRestClient versionRestClient;
50      private final ProjectRolesRestClient projectRolesRestClient;
51      private final MyPermissionsRestClient myPermissionsRestClient;
52      private final DisposableHttpClient httpClient;
53      private final AuditRestClient auditRestClient;
54  
55      public AsynchronousJiraRestClient(final URI serverUri, final DisposableHttpClient httpClient) {
56          final URI baseUri = UriBuilder.fromUri(serverUri).path("/rest/api/latest").build();
57  
58          this.httpClient = httpClient;
59          metadataRestClient = new AsynchronousMetadataRestClient(baseUri, httpClient);
60          sessionRestClient = new AsynchronousSessionRestClient(serverUri, httpClient);
61          issueRestClient = new AsynchronousIssueRestClient(baseUri, httpClient, sessionRestClient, metadataRestClient);
62          userRestClient = new AsynchronousUserRestClient(baseUri, httpClient);
63          projectRestClient = new AsynchronousProjectRestClient(baseUri, httpClient);
64          componentRestClient = new AsynchronousComponentRestClient(baseUri, httpClient);
65          searchRestClient = new AsynchronousSearchRestClient(baseUri, httpClient);
66          versionRestClient = new AsynchronousVersionRestClient(baseUri, httpClient);
67          projectRolesRestClient = new AsynchronousProjectRolesRestClient(serverUri, httpClient);
68          myPermissionsRestClient = new AsynchronousMyPermissionsRestClient(baseUri, httpClient);
69          auditRestClient = new AsynchronousAuditRestClient(httpClient, baseUri);
70      }
71  
72      @Override
73      public IssueRestClient getIssueClient() {
74          return issueRestClient;
75      }
76  
77      @Override
78      public SessionRestClient getSessionClient() {
79          return sessionRestClient;
80      }
81  
82      @Override
83      public UserRestClient getUserClient() {
84          return userRestClient;
85      }
86  
87      @Override
88      public ProjectRestClient getProjectClient() {
89          return projectRestClient;
90      }
91  
92      @Override
93      public ComponentRestClient getComponentClient() {
94          return componentRestClient;
95      }
96  
97      @Override
98      public MetadataRestClient getMetadataClient() {
99          return metadataRestClient;
100     }
101 
102     @Override
103     public SearchRestClient getSearchClient() {
104         return searchRestClient;
105     }
106 
107     @Override
108     public VersionRestClient getVersionRestClient() {
109         return versionRestClient;
110     }
111 
112     @Override
113     public ProjectRolesRestClient getProjectRolesRestClient() {
114         return projectRolesRestClient;
115     }
116 
117     @Override
118     public MyPermissionsRestClient getMyPermissionsRestClient() {
119         return myPermissionsRestClient;
120     }
121 
122     @Override
123     public AuditRestClient getAuditRestClient() {
124         return auditRestClient;
125     }
126 
127     @Override
128     public void close() throws IOException {
129         try {
130             httpClient.destroy();
131         } catch (Exception e) {
132             throw (e instanceof IOException) ? ((IOException) e) : new IOException(e);
133         }
134     }
135 }
136