Esempio n. 1
0
 private void removeNonVisibleCommentsForTeam(
     List<CommentAttributes> commentsForTeam,
     StudentAttributes student,
     List<String> teammates,
     HashSet<String> commentsVisitedSet,
     List<CommentAttributes> comments) {
   for (CommentAttributes c : commentsForTeam) {
     // for teammates
     if (c.recipientType == CommentParticipantType.PERSON
         && isCommentRecipientsWithinGroup(teammates, c)) {
       if (c.showCommentTo.contains(CommentParticipantType.TEAM)) {
         removeGiverAndRecipientNameByVisibilityOptions(c, CommentParticipantType.TEAM);
         appendComments(c, comments, commentsVisitedSet);
       } else {
         preventAppendingThisCommentAgain(commentsVisitedSet, c);
       }
       // for team
     } else if (c.recipientType == CommentParticipantType.TEAM
         && c.recipients.contains(Sanitizer.sanitizeForHtml(student.team))) {
       if (c.showCommentTo.contains(CommentParticipantType.TEAM)) {
         removeGiverNameByVisibilityOptions(c, CommentParticipantType.TEAM);
         appendComments(c, comments, commentsVisitedSet);
       } else {
         preventAppendingThisCommentAgain(commentsVisitedSet, c);
       }
     }
   }
 }
  @Override
  public String getAnswerHtml(FeedbackQuestionDetails questionDetails) {
    FeedbackRubricQuestionDetails fqd = (FeedbackRubricQuestionDetails) questionDetails;
    StringBuilder html = new StringBuilder(100);
    for (int i = 0; i < answer.size(); i++) {
      int chosenIndex = answer.get(i);
      String chosenChoice = "";
      if (chosenIndex == -1) {
        chosenChoice =
            "<span class=\"color_neutral\"><i>"
                + Const.INSTRUCTOR_FEEDBACK_RESULTS_MISSING_RESPONSE
                + "</i></span>";
        html.append(
            StringHelper.integerToLowerCaseAlphabeticalIndex(i + 1) + ") " + chosenChoice + "<br>");
      } else {
        chosenChoice = Sanitizer.sanitizeForHtml(fqd.getRubricChoices().get(answer.get(i)));
        html.append(
            StringHelper.integerToLowerCaseAlphabeticalIndex(i + 1)
                + ") "
                + chosenChoice
                + " <span class=\"color_neutral\"><i>(Choice "
                + (chosenIndex + 1)
                + ")</i></span><br>");
      }
    }

    return html.toString();
  }
  @Override
  public String getQuestionWithoutExistingResponseSubmissionFormHtml(
      boolean sessionIsOpen, int qnIdx, int responseIdx, String courseId, int totalNumRecipients) {

    StringBuilder optionListHtml = new StringBuilder();
    String optionFragmentTemplate =
        FeedbackQuestionFormTemplates.RANK_SUBMISSION_FORM_OPTIONFRAGMENT;

    for (int i = 0; i < options.size(); i++) {
      String optionFragment =
          FeedbackQuestionFormTemplates.populateTemplate(
              optionFragmentTemplate,
              "${qnIdx}",
              Integer.toString(qnIdx),
              "${responseIdx}",
              Integer.toString(responseIdx),
              "${optionIdx}",
              Integer.toString(i),
              "${disabled}",
              sessionIsOpen ? "" : "disabled=\"disabled\"",
              "${rankOptionVisibility}",
              "",
              "${options}",
              getSubmissionOptionsHtmlForRankingOptions(Const.INT_UNINITIALIZED),
              "${Const.ParamsNames.FEEDBACK_RESPONSE_TEXT}",
              Const.ParamsNames.FEEDBACK_RESPONSE_TEXT,
              "${rankOptionValue}",
              Sanitizer.sanitizeForHtml(options.get(i)));
      optionListHtml.append(optionFragment + Const.EOL);
    }

    String html =
        FeedbackQuestionFormTemplates.populateTemplate(
            FeedbackQuestionFormTemplates.RANK_SUBMISSION_FORM,
            "${rankSubmissionFormOptionFragments}",
            optionListHtml.toString(),
            "${qnIdx}",
            Integer.toString(qnIdx),
            "${responseIdx}",
            Integer.toString(responseIdx),
            "${rankOptionVisibility}",
            "",
            "${rankToRecipientsValue}",
            "false",
            "${Const.ParamsNames.FEEDBACK_QUESTION_RANKTORECIPIENTS}",
            Const.ParamsNames.FEEDBACK_QUESTION_RANKTORECIPIENTS,
            "${Const.ParamsNames.FEEDBACK_QUESTION_RANKNUMOPTION}",
            Const.ParamsNames.FEEDBACK_QUESTION_RANKNUMOPTIONS,
            "${rankNumOptionValue}",
            Integer.toString(options.size()),
            "${Const.ParamsNames.FEEDBACK_QUESTION_RANKISDUPLICATESALLOWED}",
            Const.ParamsNames.FEEDBACK_QUESTION_RANKISDUPLICATESALLOWED,
            "${areDuplicatesAllowedValue}",
            Boolean.toString(areDuplicatesAllowed));

    return html;
  }
 @Override
 public void sanitizeForSaving() {
   this.googleId = Sanitizer.sanitizeGoogleId(this.googleId);
   this.shortName = Sanitizer.sanitizeForHtml(this.shortName);
   this.email = Sanitizer.sanitizeForHtml(this.email);
   this.institute = Sanitizer.sanitizeForHtml(this.institute);
   this.nationality = Sanitizer.sanitizeForHtml(this.nationality);
   this.gender = Sanitizer.sanitizeForHtml(this.gender);
   this.moreInfo = Sanitizer.sanitizeForHtml(this.moreInfo);
 }
  @Override
  public String getQuestionResultStatisticsHtml(
      List<FeedbackResponseAttributes> responses,
      FeedbackQuestionAttributes question,
      String studentEmail,
      FeedbackSessionResultsBundle bundle,
      String view) {

    if (view.equals("student") || responses.isEmpty()) {
      return "";
    }

    String html = "";
    String fragments = "";

    Map<String, List<Integer>> optionRanks = generateOptionRanksMapping(responses);

    DecimalFormat df = new DecimalFormat("#.##");

    for (Entry<String, List<Integer>> entry : optionRanks.entrySet()) {

      List<Integer> ranks = entry.getValue();
      double average = computeAverage(ranks);
      String ranksReceived = getListOfRanksReceivedAsString(ranks);

      String option = entry.getKey();

      fragments +=
          FeedbackQuestionFormTemplates.populateTemplate(
              FeedbackQuestionFormTemplates.RANK_RESULT_STATS_OPTIONFRAGMENT,
              "${rankOptionValue}",
              Sanitizer.sanitizeForHtml(option),
              "${ranksReceived}",
              ranksReceived,
              "${averageRank}",
              df.format(average));
    }

    html =
        FeedbackQuestionFormTemplates.populateTemplate(
            FeedbackQuestionFormTemplates.RANK_RESULT_OPTION_STATS,
            "${optionRecipientDisplayName}",
            "Option",
            "${fragments}",
            fragments);

    return html;
  }
Esempio n. 6
0
 @Override
 public void sanitizeForSaving() {
   this.googleId = Sanitizer.sanitizeGoogleId(this.googleId);
   this.email = Sanitizer.sanitizeEmail(this.email);
   this.course = Sanitizer.sanitizeTitle(this.course);
   this.name = Sanitizer.sanitizeName(this.name);
   this.team = Sanitizer.sanitizeTitle(this.team);
   this.section = Sanitizer.sanitizeTitle(this.section);
   this.comments = Sanitizer.sanitizeTextField(this.comments);
   this.googleId = Sanitizer.sanitizeForHtml(this.googleId);
   this.email = Sanitizer.sanitizeForHtml(this.email);
   this.course = Sanitizer.sanitizeForHtml(this.course);
   this.name = Sanitizer.sanitizeForHtml(this.name);
   this.team = Sanitizer.sanitizeForHtml(this.team);
   this.section = Sanitizer.sanitizeForHtml(this.section);
   this.comments = Sanitizer.sanitizeForHtml(this.comments);
 }
  @Override
  public String getQuestionSpecificEditFormHtml(int questionNumber) {
    StringBuilder optionListHtml = new StringBuilder();
    String optionFragmentTemplate = FeedbackQuestionFormTemplates.RANK_EDIT_FORM_OPTIONFRAGMENT;

    for (int i = 0; i < options.size(); i++) {
      String optionFragment =
          FeedbackQuestionFormTemplates.populateTemplate(
              optionFragmentTemplate,
              "${i}",
              Integer.toString(i),
              "${rankOptionValue}",
              Sanitizer.sanitizeForHtml(options.get(i)),
              "${Const.ParamsNames.FEEDBACK_QUESTION_RANKOPTION}",
              Const.ParamsNames.FEEDBACK_QUESTION_RANKOPTION);

      optionListHtml.append(optionFragment + Const.EOL);
    }

    return FeedbackQuestionFormTemplates.populateTemplate(
        FeedbackQuestionFormTemplates.RANK_EDIT_OPTIONS_FORM,
        "${rankEditFormOptionFragments}",
        optionListHtml.toString(),
        "${questionNumber}",
        Integer.toString(questionNumber),
        "${Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED}",
        Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFCHOICECREATED,
        "${numOfRankOptions}",
        String.valueOf(options.size()),
        "${optionRecipientDisplayName}",
        "option",
        "${Const.ParamsNames.FEEDBACK_QUESTION_RANKISDUPLICATESALLOWED}",
        Const.ParamsNames.FEEDBACK_QUESTION_RANKISDUPLICATESALLOWED,
        "${areDuplicatesAllowedChecked}",
        areDuplicatesAllowed ? "checked=\"checked\"" : "");
  }
  @Test
  public void testExecuteAndPostProcess() {
    InstructorAttributes instructor = dataBundle.instructors.get("instructor3OfCourse1");
    StudentAttributes student = dataBundle.students.get("student3InCourse1");
    String instructorId = instructor.googleId;

    gaeSimulation.loginAsInstructor(instructorId);

    ______TS("Unsuccessful case: test empty course id parameter");

    String[] submissionParams =
        new String[] {
          Const.ParamsNames.STUDENT_EMAIL,
          student.email,
          Const.ParamsNames.COMMENT_TEXT,
          "A typical comment to be added"
        };

    InstructorStudentCommentAddAction a;
    RedirectResult r;

    try {
      a = getAction(submissionParams);
      r = (RedirectResult) a.executeAndPostProcess();
      signalFailureToDetectException("Did not detect that parameters are null.");
    } catch (NullPostParameterException e) {
      assertEquals(
          String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.COURSE_ID),
          e.getMessage());
    }

    ______TS("Unsuccessful case: test empty student email parameter");

    submissionParams =
        new String[] {
          Const.ParamsNames.COURSE_ID,
          instructor.courseId,
          Const.ParamsNames.COMMENT_TEXT,
          "A typical comment to be added"
        };

    try {
      a = getAction(submissionParams);
      r = (RedirectResult) a.executeAndPostProcess();
      signalFailureToDetectException("Did not detect that parameters are null.");
    } catch (NullPostParameterException e) {
      assertEquals(
          String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.STUDENT_EMAIL),
          e.getMessage());
    }

    ______TS("Unsuccessful case: test empty comment text parameter");

    submissionParams =
        new String[] {
          Const.ParamsNames.COURSE_ID, instructor.courseId,
          Const.ParamsNames.STUDENT_EMAIL, student.email
        };

    try {
      a = getAction(submissionParams);
      r = (RedirectResult) a.executeAndPostProcess();
      signalFailureToDetectException("Did not detect that parameters are null.");
    } catch (NullPostParameterException e) {
      assertEquals(
          String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.COMMENT_TEXT),
          e.getMessage());
    }

    ______TS("Unsuccessful case: non-existent team");

    submissionParams =
        new String[] {
          Const.ParamsNames.COMMENT_TEXT, "A typical comment to be added",
          Const.ParamsNames.COURSE_ID, instructor.courseId,
          Const.ParamsNames.STUDENT_EMAIL, student.email,
          Const.ParamsNames.RECIPIENT_TYPE, "TEAM",
          Const.ParamsNames.RECIPIENTS, "non-existent team"
        };

    try {
      a = getAction(submissionParams);
      r = (RedirectResult) a.executeAndPostProcess();
      signalFailureToDetectException("Did not detect that team does not exist.");
    } catch (AssertionError e) {
      assertEquals("null", e.getMessage());
    }

    ______TS("Unsuccessful case: non-existent student");

    submissionParams =
        new String[] {
          Const.ParamsNames.COMMENT_TEXT, "A typical comment to be added",
          Const.ParamsNames.COURSE_ID, instructor.courseId,
          Const.ParamsNames.STUDENT_EMAIL, "non-existent student",
          Const.ParamsNames.RECIPIENT_TYPE, "TEAM",
          Const.ParamsNames.RECIPIENTS, "non-existent student"
        };

    try {
      a = getAction(submissionParams);
      r = (RedirectResult) a.executeAndPostProcess();
      signalFailureToDetectException("Did not detect that student does not exist.");
    } catch (AssertionError e) {
      assertEquals("null", e.getMessage());
    }

    ______TS("Typical success case from student records page");

    submissionParams =
        new String[] {
          Const.ParamsNames.COMMENT_TEXT, "A typical comment to be added",
          Const.ParamsNames.COURSE_ID, instructor.courseId,
          Const.ParamsNames.STUDENT_EMAIL, student.email,
          Const.ParamsNames.RECIPIENT_TYPE, "PERSON",
          Const.ParamsNames.RECIPIENTS, student.email
        };

    a = getAction(submissionParams);
    r = getRedirectResult(a);

    assertEquals(
        Const.ActionURIs.INSTRUCTOR_STUDENT_RECORDS_PAGE
            + "?courseid=idOfTypicalCourse1&"
            + "studentemail=student3InCourse1%40gmail.tmt&"
            + "user=idOfInstructor3&"
            + "error=false",
        r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("New comment has been added", r.getStatusMessage());

    String expectedLogMessage =
        "TEAMMATESLOG|||instructorStudentCommentAdd|||instructorStudentCommentAdd"
            + "|||true|||Instructor|||Instructor 3 of Course 1 and 2|||idOfInstructor3"
            + "|||[email protected]|||"
            + "Created Comment for Student:<span class=\"bold\">(["
            + student.email
            + "])</span> "
            + "for Course <span class=\"bold\">["
            + instructor.courseId
            + "]</span><br>"
            + "<span class=\"bold\">Comment:</span> "
            + "<Text: A typical comment to be added>"
            + "|||/page/instructorStudentCommentAdd";

    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());

    ______TS("Typical success case from comments page");

    submissionParams =
        new String[] {
          Const.ParamsNames.COMMENT_TEXT,
          "A typical comment to be added",
          Const.ParamsNames.COURSE_ID,
          instructor.courseId,
          Const.ParamsNames.STUDENT_EMAIL,
          student.email,
          Const.ParamsNames.RECIPIENT_TYPE,
          "PERSON",
          Const.ParamsNames.RECIPIENTS,
          student.email,
          Const.ParamsNames.FROM_COMMENTS_PAGE,
          "true"
        };

    a = getAction(submissionParams);
    r = getRedirectResult(a);

    assertEquals(
        Const.ActionURIs.INSTRUCTOR_COMMENTS_PAGE
            + "?user=idOfInstructor3&"
            + "courseid=idOfTypicalCourse1&"
            + "error=false",
        r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("New comment has been added", r.getStatusMessage());

    expectedLogMessage =
        "TEAMMATESLOG|||instructorStudentCommentAdd|||instructorStudentCommentAdd"
            + "|||true|||Instructor|||Instructor 3 of Course 1 and 2|||idOfInstructor3"
            + "|||[email protected]|||"
            + "Created Comment for Student:<span class=\"bold\">(["
            + student.email
            + "])</span> "
            + "for Course <span class=\"bold\">["
            + instructor.courseId
            + "]</span><br>"
            + "<span class=\"bold\">Comment:</span> "
            + "<Text: A typical comment to be added>"
            + "|||/page/instructorStudentCommentAdd";

    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());

    ______TS("Typical success case from student details page");

    submissionParams =
        new String[] {
          Const.ParamsNames.COMMENT_TEXT,
          "A typical comment to be added",
          Const.ParamsNames.COURSE_ID,
          instructor.courseId,
          Const.ParamsNames.STUDENT_EMAIL,
          student.email,
          Const.ParamsNames.RECIPIENT_TYPE,
          "PERSON",
          Const.ParamsNames.RECIPIENTS,
          student.email,
          Const.ParamsNames.FROM_STUDENT_DETAILS_PAGE,
          "true"
        };

    a = getAction(submissionParams);
    r = getRedirectResult(a);

    assertEquals(
        Const.ActionURIs.INSTRUCTOR_COURSE_STUDENT_DETAILS_PAGE
            + "?courseid=idOfTypicalCourse1&"
            + "studentemail=student3InCourse1%40gmail.tmt&"
            + "user=idOfInstructor3&"
            + "error=false",
        r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("New comment has been added", r.getStatusMessage());

    expectedLogMessage =
        "TEAMMATESLOG|||instructorStudentCommentAdd|||instructorStudentCommentAdd"
            + "|||true|||Instructor|||Instructor 3 of Course 1 and 2|||idOfInstructor3"
            + "|||[email protected]|||"
            + "Created Comment for Student:<span class=\"bold\">(["
            + student.email
            + "])</span> "
            + "for Course <span class=\"bold\">["
            + instructor.courseId
            + "]</span><br>"
            + "<span class=\"bold\">Comment:</span> "
            + "<Text: A typical comment to be added>"
            + "|||/page/instructorStudentCommentAdd";

    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());

    ______TS("Typical success case from course details page");

    submissionParams =
        new String[] {
          Const.ParamsNames.COMMENT_TEXT,
          "A typical comment to be added",
          Const.ParamsNames.COURSE_ID,
          instructor.courseId,
          Const.ParamsNames.STUDENT_EMAIL,
          student.email,
          Const.ParamsNames.RECIPIENT_TYPE,
          "PERSON",
          Const.ParamsNames.RECIPIENTS,
          student.email,
          Const.ParamsNames.FROM_COURSE_DETAILS_PAGE,
          "true"
        };

    a = getAction(submissionParams);
    r = getRedirectResult(a);

    assertEquals(
        Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE
            + "?courseid=idOfTypicalCourse1&"
            + "user=idOfInstructor3&"
            + "error=false",
        r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("New comment has been added", r.getStatusMessage());

    expectedLogMessage =
        "TEAMMATESLOG|||instructorStudentCommentAdd|||instructorStudentCommentAdd"
            + "|||true|||Instructor|||Instructor 3 of Course 1 and 2|||idOfInstructor3"
            + "|||[email protected]|||"
            + "Created Comment for Student:<span class=\"bold\">(["
            + student.email
            + "])</span> "
            + "for Course <span class=\"bold\">["
            + instructor.courseId
            + "]</span><br>"
            + "<span class=\"bold\">Comment:</span> "
            + "<Text: A typical comment to be added>"
            + "|||/page/instructorStudentCommentAdd";

    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());

    ______TS("Typical success case for course as recipient");

    submissionParams =
        new String[] {
          Const.ParamsNames.COMMENT_TEXT, "A typical comment to be added",
          Const.ParamsNames.COURSE_ID, instructor.courseId,
          Const.ParamsNames.STUDENT_EMAIL, student.email,
          Const.ParamsNames.RECIPIENT_TYPE, "COURSE",
          Const.ParamsNames.RECIPIENTS, student.course
        };

    a = getAction(submissionParams);
    r = getRedirectResult(a);

    assertEquals(
        Const.ActionURIs.INSTRUCTOR_STUDENT_RECORDS_PAGE
            + "?courseid=idOfTypicalCourse1&"
            + "studentemail=student3InCourse1%40gmail.tmt&"
            + "user=idOfInstructor3&"
            + "error=false",
        r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("New comment has been added", r.getStatusMessage());

    expectedLogMessage =
        "TEAMMATESLOG|||instructorStudentCommentAdd|||instructorStudentCommentAdd"
            + "|||true|||Instructor|||Instructor 3 of Course 1 and 2|||idOfInstructor3"
            + "|||[email protected]|||"
            + "Created Comment for Student:<span class=\"bold\">(["
            + student.course
            + "])</span> "
            + "for Course <span class=\"bold\">["
            + instructor.courseId
            + "]</span><br>"
            + "<span class=\"bold\">Comment:</span> "
            + "<Text: A typical comment to be added>"
            + "|||/page/instructorStudentCommentAdd";

    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());

    ______TS("Typical success case for section as recipient");

    submissionParams =
        new String[] {
          Const.ParamsNames.COMMENT_TEXT, "A typical comment to be added",
          Const.ParamsNames.COURSE_ID, instructor.courseId,
          Const.ParamsNames.STUDENT_EMAIL, student.email,
          Const.ParamsNames.RECIPIENT_TYPE, "SECTION",
          Const.ParamsNames.RECIPIENTS, student.section
        };

    a = getAction(submissionParams);
    r = getRedirectResult(a);

    assertEquals(
        Const.ActionURIs.INSTRUCTOR_STUDENT_RECORDS_PAGE
            + "?courseid=idOfTypicalCourse1&"
            + "studentemail=student3InCourse1%40gmail.tmt&"
            + "user=idOfInstructor3&"
            + "error=false",
        r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("New comment has been added", r.getStatusMessage());

    expectedLogMessage =
        "TEAMMATESLOG|||instructorStudentCommentAdd|||instructorStudentCommentAdd"
            + "|||true|||Instructor|||Instructor 3 of Course 1 and 2|||idOfInstructor3"
            + "|||[email protected]|||"
            + "Created Comment for Student:<span class=\"bold\">(["
            + student.section
            + "])</span> "
            + "for Course <span class=\"bold\">["
            + instructor.courseId
            + "]</span><br>"
            + "<span class=\"bold\">Comment:</span> "
            + "<Text: A typical comment to be added>"
            + "|||/page/instructorStudentCommentAdd";

    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());

    ______TS("Typical success case for team as recipient");

    submissionParams =
        new String[] {
          Const.ParamsNames.COMMENT_TEXT, "A typical comment to be added",
          Const.ParamsNames.COURSE_ID, instructor.courseId,
          Const.ParamsNames.STUDENT_EMAIL, student.email,
          Const.ParamsNames.RECIPIENT_TYPE, "TEAM",
          Const.ParamsNames.RECIPIENTS, student.team
        };

    a = getAction(submissionParams);
    r = getRedirectResult(a);

    assertEquals(
        Const.ActionURIs.INSTRUCTOR_STUDENT_RECORDS_PAGE
            + "?courseid=idOfTypicalCourse1&"
            + "studentemail=student3InCourse1%40gmail.tmt&"
            + "user=idOfInstructor3&"
            + "error=false",
        r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("New comment has been added", r.getStatusMessage());

    expectedLogMessage =
        "TEAMMATESLOG|||instructorStudentCommentAdd|||instructorStudentCommentAdd"
            + "|||true|||Instructor|||Instructor 3 of Course 1 and 2|||idOfInstructor3"
            + "|||[email protected]|||"
            + "Created Comment for Student:"
            + "<span class=\"bold\">(["
            + Sanitizer.sanitizeForHtml(student.team)
            + "])</span> "
            + "for Course <span class=\"bold\">["
            + instructor.courseId
            + "]</span><br>"
            + "<span class=\"bold\">Comment:</span> "
            + "<Text: A typical comment to be added>"
            + "|||/page/instructorStudentCommentAdd";

    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());

    ______TS("Success case for null recipient type");

    submissionParams =
        new String[] {
          Const.ParamsNames.COMMENT_TEXT, "A typical comment to be added",
          Const.ParamsNames.COURSE_ID, instructor.courseId,
          Const.ParamsNames.STUDENT_EMAIL, student.email,
          Const.ParamsNames.RECIPIENTS, student.email
        };

    a = getAction(submissionParams);
    r = getRedirectResult(a);

    assertEquals(
        Const.ActionURIs.INSTRUCTOR_STUDENT_RECORDS_PAGE
            + "?courseid=idOfTypicalCourse1&"
            + "studentemail=student3InCourse1%40gmail.tmt&"
            + "user=idOfInstructor3&"
            + "error=false",
        r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("New comment has been added", r.getStatusMessage());

    expectedLogMessage =
        "TEAMMATESLOG|||instructorStudentCommentAdd|||instructorStudentCommentAdd"
            + "|||true|||Instructor|||Instructor 3 of Course 1 and 2|||idOfInstructor3"
            + "|||[email protected]|||"
            + "Created Comment for Student:<span class=\"bold\">(["
            + student.email
            + "])</span> "
            + "for Course <span class=\"bold\">["
            + instructor.courseId
            + "]</span><br>"
            + "<span class=\"bold\">Comment:</span> "
            + "<Text: A typical comment to be added>"
            + "|||/page/instructorStudentCommentAdd";

    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());

    ______TS("Success case for show comment to recipient");

    submissionParams =
        new String[] {
          Const.ParamsNames.COMMENT_TEXT,
          "A typical comment to be added",
          Const.ParamsNames.COURSE_ID,
          instructor.courseId,
          Const.ParamsNames.STUDENT_EMAIL,
          student.email,
          Const.ParamsNames.RECIPIENT_TYPE,
          "PERSON",
          Const.ParamsNames.RECIPIENTS,
          student.email,
          Const.ParamsNames.COMMENTS_SHOWCOMMENTSTO,
          "PERSON"
        };

    a = getAction(submissionParams);
    r = getRedirectResult(a);

    assertEquals(
        Const.ActionURIs.INSTRUCTOR_STUDENT_RECORDS_PAGE
            + "?courseid=idOfTypicalCourse1&"
            + "studentemail=student3InCourse1%40gmail.tmt&"
            + "user=idOfInstructor3&"
            + "error=false",
        r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("New comment has been added", r.getStatusMessage());

    expectedLogMessage =
        "TEAMMATESLOG|||instructorStudentCommentAdd|||instructorStudentCommentAdd"
            + "|||true|||Instructor|||Instructor 3 of Course 1 and 2|||idOfInstructor3"
            + "|||[email protected]|||"
            + "Created Comment for Student:<span class=\"bold\">(["
            + student.email
            + "])</span> "
            + "for Course <span class=\"bold\">["
            + instructor.courseId
            + "]</span><br>"
            + "<span class=\"bold\">Comment:</span> "
            + "<Text: A typical comment to be added>"
            + "|||/page/instructorStudentCommentAdd";

    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());

    ______TS("Success case for show giver to recipient");

    submissionParams =
        new String[] {
          Const.ParamsNames.COMMENT_TEXT,
          "A typical comment to be added",
          Const.ParamsNames.COURSE_ID,
          instructor.courseId,
          Const.ParamsNames.STUDENT_EMAIL,
          student.email,
          Const.ParamsNames.RECIPIENT_TYPE,
          "PERSON",
          Const.ParamsNames.RECIPIENTS,
          student.email,
          Const.ParamsNames.COMMENTS_SHOWGIVERTO,
          "PERSON"
        };

    a = getAction(submissionParams);
    r = getRedirectResult(a);

    assertEquals(
        Const.ActionURIs.INSTRUCTOR_STUDENT_RECORDS_PAGE
            + "?courseid=idOfTypicalCourse1&"
            + "studentemail=student3InCourse1%40gmail.tmt&"
            + "user=idOfInstructor3&"
            + "error=false",
        r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("New comment has been added", r.getStatusMessage());

    expectedLogMessage =
        "TEAMMATESLOG|||instructorStudentCommentAdd|||instructorStudentCommentAdd"
            + "|||true|||Instructor|||Instructor 3 of Course 1 and 2|||idOfInstructor3"
            + "|||[email protected]|||"
            + "Created Comment for Student:<span class=\"bold\">(["
            + student.email
            + "])</span> "
            + "for Course <span class=\"bold\">["
            + instructor.courseId
            + "]</span><br>"
            + "<span class=\"bold\">Comment:</span> "
            + "<Text: A typical comment to be added>"
            + "|||/page/instructorStudentCommentAdd";

    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
  }
 @Override
 public String getAnswerHtml() {
   return Sanitizer.sanitizeForHtml(getAnswerString());
 }
  @Override
  public ActionResult execute() throws EntityDoesNotExistException {
    String newCourseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertNotNull(newCourseId);
    String newCourseName = getRequestParamValue(Const.ParamsNames.COURSE_NAME);
    Assumption.assertNotNull(newCourseName);

    /* Check if user has the right to execute the action */
    new GateKeeper().verifyInstructorPrivileges(account);

    /* Create a new course in the database */
    data = new InstructorCoursesPageData(account);
    CourseAttributes newCourse = new CourseAttributes(newCourseId, newCourseName);
    createCourse(newCourse);

    /* Prepare data for the refreshed page after executing the adding action */
    List<CourseDetailsBundle> allCourses =
        new ArrayList<CourseDetailsBundle>(
            logic.getCourseSummariesForInstructor(data.account.googleId).values());
    CourseDetailsBundle.sortDetailedCoursesByCourseId(allCourses);
    List<CourseDetailsBundle> activeCourses =
        logic.extractActiveCourses(allCourses, data.account.googleId);
    List<CourseDetailsBundle> archivedCourses =
        logic.extractArchivedCourses(allCourses, data.account.googleId);

    String CourseIdToShowParam = "";
    String CourseNameToShowParam = "";

    if (isError) { // there is error in adding the course
      CourseIdToShowParam = Sanitizer.sanitizeForHtml(newCourse.id);
      CourseNameToShowParam = Sanitizer.sanitizeForHtml(newCourse.name);

      List<String> statusMessageTexts = new ArrayList<String>();

      for (StatusMessage msg : statusToUser) {
        statusMessageTexts.add(msg.getText());
      }

      statusToAdmin = StringHelper.toString(statusMessageTexts, "<br>");
    } else {
      statusToAdmin = "Course added : " + newCourse.id;
      statusToAdmin += "<br>Total courses: " + allCourses.size();
    }

    List<CourseAttributes> courseList = logic.getCoursesForInstructor(data.account.googleId);
    Map<String, InstructorAttributes> instructorsForCourses =
        new HashMap<String, InstructorAttributes>();
    for (CourseAttributes course : courseList) {
      instructorsForCourses.put(
          course.id, logic.getInstructorForGoogleId(course.id, data.account.googleId));
    }

    data.init(
        activeCourses,
        archivedCourses,
        instructorsForCourses,
        CourseIdToShowParam,
        CourseNameToShowParam);

    return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSES, data);
  }
  @Override
  public ActionResult execute() throws EntityDoesNotExistException {

    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    String evalName = getRequestParamValue(Const.ParamsNames.EVALUATION_NAME);
    String fromEmail = getRequestParamValue(Const.ParamsNames.FROM_EMAIL);
    String teamName = getRequestParamValue(Const.ParamsNames.TEAM_NAME);

    if (isParameterNull(courseId)
        || isParameterNull(evalName)
        || isParameterNull(fromEmail)
        || isParameterNull(teamName)) {
      return redirectAndShowExpiredRequest();
    } else {

      String[] toEmails = getRequestParamValues(Const.ParamsNames.TO_EMAIL);
      String[] points = getRequestParamValues(Const.ParamsNames.POINTS);
      String[] justifications = getRequestParamValues(Const.ParamsNames.JUSTIFICATION);
      String[] comments = getRequestParamValues(Const.ParamsNames.COMMENTS);

      EvaluationAttributes eval = logic.getEvaluation(courseId, evalName);

      if (eval.getStatus() == EvalStatus.PUBLISHED) {
        throw new UnauthorizedAccessException(Const.Tooltips.EVALUATION_STATUS_PUBLISHED);
      } else if (eval.getStatus() == EvalStatus.CLOSED) {
        throw new UnauthorizedAccessException(Const.Tooltips.EVALUATION_STATUS_CLOSED);
      } else if (eval.getStatus() == EvalStatus.AWAITING) {
        throw new UnauthorizedAccessException(Const.Tooltips.EVALUATION_STATUS_AWAITING);
      } else if (eval.getStatus() == EvalStatus.DOES_NOT_EXIST) {
        throw new UnauthorizedAccessException(Const.StatusMessages.EVALUATION_DELETED);
      }

      // extract submission data
      ArrayList<SubmissionAttributes> submissionData = new ArrayList<SubmissionAttributes>();
      int submissionCount = (toEmails == null ? 0 : toEmails.length);
      boolean emptyPointExists = false;
      for (int i = 0; i < submissionCount; i++) {
        SubmissionAttributes sub = new SubmissionAttributes();
        sub.course = courseId;
        sub.evaluation = evalName;
        sub.justification = new Text(justifications[i]);

        if (eval.p2pEnabled) {
          sub.p2pFeedback = new Text(comments[i]);
        }

        try {
          sub.points = Integer.parseInt(points[i]);
        } catch (NumberFormatException e) {
          // The point dropdown is unfilled and is blank
          sub.points = Const.POINTS_NOT_SUBMITTED;
          emptyPointExists = true;
        }

        sub.reviewee = toEmails[i];
        sub.reviewer = fromEmail;
        sub.team = teamName;
        submissionData.add(sub);
      }

      if (emptyPointExists) {
        isError = true;
        statusToUser.add("Please give contribution scale to everyone");
      }

      new GateKeeper()
          .verifyAccessible(
              logic.getStudentForGoogleId(courseId, account.googleId), submissionData);

      try {
        logic.updateSubmissions(submissionData);
        statusToAdmin =
            createLogMesage(
                courseId,
                evalName,
                teamName,
                fromEmail,
                toEmails,
                points,
                justifications,
                comments);
      } catch (InvalidParametersException e) {
        // TODO: Let the user retry?
        setStatusForException(e);
      }

      RedirectResult response;
      if (isError) {
        String submissionUrl = Const.ActionURIs.STUDENT_EVAL_SUBMISSION_EDIT_PAGE;
        submissionUrl = Url.addParamToUrl(submissionUrl, Const.ParamsNames.COURSE_ID, courseId);
        submissionUrl =
            Url.addParamToUrl(submissionUrl, Const.ParamsNames.EVALUATION_NAME, evalName);
        submissionUrl =
            Url.addParamToUrl(submissionUrl, Const.ParamsNames.USER_ID, account.googleId);
        response = createRedirectResult(submissionUrl);
      } else {
        statusToUser.add(
            String.format(
                Const.StatusMessages.STUDENT_EVALUATION_SUBMISSION_RECEIVED,
                Sanitizer.sanitizeForHtml(evalName),
                courseId));
        String submissionUrl = Const.ActionURIs.STUDENT_HOME_PAGE;

        String submittedEvaluationName = courseId + evalName;
        submissionUrl =
            Url.addParamToUrl(
                submissionUrl,
                Const.ParamsNames.CHECK_PERSISTENCE_EVALUATION,
                submittedEvaluationName);
        log.info(submittedEvaluationName);
        response = createRedirectResult(submissionUrl);
      }
      return response;
    }
  }