View Javadoc

1   package com.atlassian.plugins.rest.sample.expansion.resource;
2   
3   import javax.ws.rs.*;
4   import javax.ws.rs.core.Context;
5   
6   import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
7   import static javax.ws.rs.core.MediaType.APPLICATION_XML;
8   
9   import javax.ws.rs.core.Response;
10  import javax.ws.rs.core.UriBuilder;
11  import javax.ws.rs.core.UriInfo;
12  
13  /**
14   * A resource used to show details of a player and optionally an expandable player record element.  The
15   * {@link DataStore} will provide data of two player, one which has a player record and which doesn't.
16   *
17   * When viewing player with the record the client has the option to expand it.
18   */
19  @Path("/player")
20  @Consumes({APPLICATION_XML, APPLICATION_JSON})
21  @Produces({APPLICATION_XML, APPLICATION_JSON})
22  public class PlayerResource {
23      @Context
24      private UriInfo uriInfo;
25  
26      @GET
27      @Path("/{id}")
28      public Response getPlayer(@PathParam("id") Integer id) throws Exception {
29          return Response.ok(DataStore.getInstance().getPlayer(id, getPlayerUriBuilder(uriInfo))).build();
30      }
31  
32      static UriBuilder getPlayerUriBuilder(UriInfo uriInfo) {
33          return uriInfo.getBaseUriBuilder().path("player").path("{id}");
34      }
35  }
36