Ejemplo n.º 1
0
  public Result approve(Long key) {
    if (log.isDebugEnabled()) log.debug("approve <- " + key);

    Post post = postDAO.get(key);
    if (log.isDebugEnabled()) log.debug("post : " + post);
    if (post == null) return notFound();

    ContentStatus status = post.getStatus();
    if (status == NEW || status == UPDATED) {
      User user = HttpUtils.loginUser(ctx());
      post.setStatus(APPROVED);
      post.setApprovedBy(user);
      post.setApprovedOn(new Date());
      postDAO.update(post);

      List<ContentReport> reports = contentReportDAO.findForContent(ContentType.POST, key);
      for (ContentReport report : reports) {
        if (report.getStatus() == ContentReport.Status.NEW) {
          report.setStatus(ContentReport.Status.IGNORED);
          report.setUpdatedBy(user);
          contentReportDAO.update(report);
        }
      }
      return ok(toJson(ImmutableMap.of("status", "ok", "key", key)));
    } else {
      return badRequest(
          toJson(
              ImmutableMap.of(
                  "status", "error", "message", "wrong status", "status", status.name())));
    }
  }
Ejemplo n.º 2
0
  public Result remove(Long key) {
    if (log.isDebugEnabled()) log.debug("remove <- " + key);

    Post post = postDAO.get(key);
    if (log.isDebugEnabled()) log.debug("post : " + post);
    if (post == null) return notFound();

    User user = HttpUtils.loginUser(ctx());
    post.setStatus(REMOVED);
    post.setUpdatedBy(user);
    postDAO.update(post);

    List<ContentReport> reports = contentReportDAO.findForContent(ContentType.POST, key);
    for (ContentReport report : reports) {
      if (report.getStatus() == ContentReport.Status.NEW) {
        report.setStatus(ContentReport.Status.PROCESSED);
        report.setUpdatedBy(user);
        contentReportDAO.update(report);
      }
    }
    return ok(toJson(ImmutableMap.of("status", "ok", "key", key)));
  }