Beispiel #1
0
  @Override
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    Gson gson = gsonBuilder.create();

    String stringKey = req.getParameter("group");
    Key<Group> groupKey = Key.create(Group.class, Long.valueOf(stringKey));

    Movie movie = gson.fromJson(req.getReader(), Movie.class);
    movie.setGroup(groupKey);

    ofy().save().entity(movie);

    resp.setStatus(HttpServletResponse.SC_CREATED);
  }
Beispiel #2
0
  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    Gson gson = gsonBuilder.create();

    String stringKey = req.getParameter("group");
    Key<Group> groupKey = Key.create(Group.class, Long.valueOf(stringKey));

    List<Movie> movies = ofy().load().type(Movie.class).ancestor(groupKey).list();

    resp.setContentType("application/json");
    resp.getWriter().println(gson.toJson(movies));

    resp.setStatus(HttpServletResponse.SC_OK);
  }