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.httpclient.api.HttpClient;
19  import com.atlassian.jira.rest.client.api.UserRestClient;
20  import com.atlassian.jira.rest.client.api.domain.User;
21  import com.atlassian.jira.rest.client.internal.json.UserJsonParser;
22  import com.atlassian.util.concurrent.Promise;
23  
24  import javax.ws.rs.core.UriBuilder;
25  import java.net.URI;
26  
27  /**
28   * Asynchronous implementation of UserRestClient.
29   *
30   * @since v2.0
31   */
32  public class AsynchronousUserRestClient extends AbstractAsynchronousRestClient implements UserRestClient {
33  
34      private static final String USER_URI_PREFIX = "user";
35      private final UserJsonParser userJsonParser = new UserJsonParser();
36  
37      private final URI baseUri;
38  
39      public AsynchronousUserRestClient(final URI baseUri, final HttpClient client) {
40          super(client);
41          this.baseUri = baseUri;
42      }
43  
44      @Override
45      public Promise<User> getUser(final String username) {
46          final URI userUri = UriBuilder.fromUri(baseUri).path(USER_URI_PREFIX)
47                  .queryParam("username", username).queryParam("expand", "groups").build();
48          return getUser(userUri);
49      }
50  
51      @Override
52      public Promise<User> getUser(final URI userUri) {
53          return getAndParse(userUri, userJsonParser);
54      }
55  }