Пример #1
0
  @POST
  @Path("/feeds")
  @Consumes(MediaType.APPLICATION_JSON)
  public Response add(RssFeed rssFeed) {
    if (dao.getByLink(rssFeed.getLink()) == null) {
      dao.add(rssFeed);
      URI location = URI.create("/rss/feeds" + rssFeed.getId());
      return Response.created(location).build();

    } else {
      FeedInfo feedInfo = new FeedInfo();
      feedInfo.setInfo(rssFeed);

      System.err.println("Such feed is already in the DB");
      throw new DataBaseFeedException("Such feed is already in the DB", feedInfo);
    }
  }
Пример #2
0
  @PUT
  @Consumes(MediaType.APPLICATION_JSON)
  @Path("/feeds/{id}")
  public Response update(@PathParam("id") Long id, RssFeed rssFeed) {
    RssFeed originRssFeed = dao.getById(id);

    if (originRssFeed == null) {
      System.err.println("Nothing to update: no such element by this ID.");
      throw new FeedNotFoundException("Nothing to update: no such element by this ID.");
    } else {
      System.err.print("RSS Feed was found.");
      originRssFeed.setName(rssFeed.getName());
      originRssFeed.setLink(rssFeed.getLink());

      dao.update(originRssFeed);
      System.err.println("Updated.");
      return Response.ok().build();
    }
  }