Ejemplo n.º 1
0
 @GET
 @Path("friend/{id}")
 @Produces(MediaType.APPLICATION_JSON)
 public Friend getFriend(@PathParam("id") String id) {
   String jsonString = (String) couchbaseClientService.getCouchbaseClient().get(id);
   return gson.fromJson(jsonString, Friend.class);
 }
Ejemplo n.º 2
0
  @GET
  @Path("friends")
  @Produces(MediaType.APPLICATION_JSON)
  public List<Friend> getFriends() {
    List<Friend> friends = new ArrayList<Friend>();

    View view = couchbaseClientService.getCouchbaseClient().getView("friend", "friendView");

    Query query = new Query();
    query.setIncludeDocs(true);

    ViewResponse results = couchbaseClientService.getCouchbaseClient().query(view, query);
    for (ViewRow row : results) {
      friends.add(gson.fromJson(row.getDocument().toString(), Friend.class));
    }

    return friends;
  }
Ejemplo n.º 3
0
  @POST
  @Path("friend")
  @Consumes(MediaType.APPLICATION_JSON)
  // @Produces(MediaType.TEXT_PLAIN)
  public void addFriend(Friend friend) {
    String jsonString = gson.toJson(friend);
    couchbaseClientService.getCouchbaseClient().set(friend.getId() + "", 0, jsonString);

    // ResponseBuilder responseBuilder = Response.ok("Successfully added new friend",
    // MediaType.TEXT_PLAIN);
    // return responseBuilder.build();
  }