Esempio n. 1
0
  @Restrict(UnitRole.DEFECTVIEW)
  public static void getComments(Long defectId) {
    List<DefectComment> defectComments = DefectComment.find("defect.id=?", defectId).fetch();
    TMUser tmUser = TMUser.find("id=?", getConnectedUserId()).first();
    JsonArray jsonArray = new JsonArray();
    JsonObject result = new JsonObject();
    for (DefectComment defectComment : defectComments) {
      JsonObject comment = new JsonObject();
      comment.addProperty("id", defectComment.id);
      comment.addProperty("comment", JavaExtensions.nl2br(defectComment.comment).toString());
      comment.addProperty("submittedBy", defectComment.submittedBy.getFullName());
      SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
      comment.addProperty("submittedOn", sdf.format(defectComment.created));

      comment.addProperty("commentText", defectComment.comment);
      comment.addProperty("mainCommentId", "mainCommentId" + defectComment.id);
      comment.addProperty("hiddenDivId", "hiddenDiv" + defectComment.id);
      comment.addProperty("visibleDivId", "visibleDiv" + defectComment.id);
      comment.addProperty("visibleActionsId", "visibleActions" + defectComment.id);
      comment.addProperty("hiddenActionsId", "hiddenActions" + defectComment.id);
      comment.addProperty("commentEditInputId", "commentEditInputId" + defectComment.id);
      comment.addProperty("canEdit", defectComment.submittedBy.equals(tmUser));

      jsonArray.add(comment);
    }
    result.add("comments", jsonArray);
    renderJSON(result.toString());
  }
Esempio n. 2
0
 @Restrict(UnitRole.DEFECTEDIT)
 public static void deleteComment(Long commentId) {
   DefectComment defectComment = DefectComment.find("id=?", commentId).first();
   if (defectComment == null) {
     Logger.error(Logger.LogType.TECHNICAL, "Could not find comment %s for deletion", commentId);
     notFound("Sorry, the selected comment could not be found. Please refresh the page");
   }
   try {
     defectComment.delete();
   } catch (Throwable t) {
     Logger.error(Logger.LogType.DB, "Error deleting comment %s", commentId);
     error("An error occurred while deleting the comment, please try again");
   }
   ok();
 }