/**
   * Creates a new instructor with all information filled in, using request parameters. This
   * includes basic information as well as custom privileges (if applicable).
   *
   * @param courseId Id of the course the instructor is being added to.
   * @param instructorName Name of the instructor.
   * @param instructorEmail Email of the instructor.
   * @return An instructor with all relevant info filled in.
   */
  private InstructorAttributes extractCompleteInstructor(
      String courseId, String instructorName, String instructorEmail) {
    String instructorRole = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_ROLE_NAME);
    Assumption.assertNotNull(instructorRole);
    boolean isDisplayedToStudents =
        getRequestParamValue(Const.ParamsNames.INSTRUCTOR_IS_DISPLAYED_TO_STUDENT) != null;
    String displayedName = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_DISPLAY_NAME);
    if (displayedName == null || displayedName.isEmpty()) {
      displayedName = InstructorAttributes.DEFAULT_DISPLAY_NAME;
    }
    instructorRole = Sanitizer.sanitizeName(instructorRole);
    displayedName = Sanitizer.sanitizeName(displayedName);

    InstructorAttributes instructorToAdd =
        createInstructorWithBasicAttributes(
            courseId,
            instructorName,
            instructorEmail,
            instructorRole,
            isDisplayedToStudents,
            displayedName);

    if (instructorRole.equals(
        Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_CUSTOM)) {
      updateInstructorCourseLevelPrivileges(instructorToAdd);
    }

    updateInstructorWithSectionLevelPrivileges(courseId, instructorToAdd);

    instructorToAdd.privileges.validatePrivileges();

    return instructorToAdd;
  }
  /**
   * Creates a new instructor with basic information. This consists of everything apart from custom
   * privileges.
   *
   * @param courseId Id of the course the instructor is being added to.
   * @param instructorName Name of the instructor.
   * @param instructorEmail Email of the instructor.
   * @param instructorRole Role of the instructor.
   * @param isDisplayedToStudents Whether the instructor should be visible to students.
   * @param displayedName Name to be visible to students. Should not be {@code null} even if {@code
   *     isDisplayedToStudents} is false.
   * @return An instructor with basic info, excluding custom privileges
   */
  private InstructorAttributes createInstructorWithBasicAttributes(
      String courseId,
      String instructorName,
      String instructorEmail,
      String instructorRole,
      boolean isDisplayedToStudents,
      String displayedName) {
    String instrName = Sanitizer.sanitizeName(instructorName);
    String instrEmail = Sanitizer.sanitizeEmail(instructorEmail);
    String instrRole = Sanitizer.sanitizeName(instructorRole);
    String instrDisplayedName = Sanitizer.sanitizeName(displayedName);
    InstructorPrivileges privileges = new InstructorPrivileges(instructorRole);

    InstructorAttributes instructorToAdd =
        new InstructorAttributes(
            null,
            courseId,
            instrName,
            instrEmail,
            instrRole,
            isDisplayedToStudents,
            instrDisplayedName,
            privileges);

    return instructorToAdd;
  }
  @Override
  public String getQuestionResultStatisticsCsv(
      List<FeedbackResponseAttributes> responses,
      FeedbackQuestionAttributes question,
      FeedbackSessionResultsBundle bundle) {
    if (responses.isEmpty()) {
      return "";
    }

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

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

    for (Entry<String, List<Integer>> entry : optionRanks.entrySet()) {
      String option = Sanitizer.sanitizeForCsv(entry.getKey());

      List<Integer> ranksAssigned = entry.getValue();
      double average = computeAverage(ranksAssigned);
      fragments += option + "," + df.format(average) + Const.EOL;
    }

    csv += "Option" + ", Average Rank" + Const.EOL + fragments + Const.EOL;

    return csv;
  }
  @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();
  }
예제 #5
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);
       }
     }
   }
 }
예제 #6
0
 public StudentProfileAttributes(
     String googleId,
     String shortName,
     String email,
     String institute,
     String nationality,
     String gender,
     String moreInfo,
     String pictureKey) {
   this.googleId = googleId;
   this.shortName = Sanitizer.sanitizeName(shortName);
   this.email = Sanitizer.sanitizeEmail(email);
   this.institute = Sanitizer.sanitizeTitle(institute);
   this.nationality = Sanitizer.sanitizeName(nationality);
   this.gender = gender;
   this.moreInfo = moreInfo;
   this.pictureKey = pictureKey;
 }
  @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;
  }
예제 #8
0
 public StudentAttributes(
     String id,
     String email,
     String name,
     String comments,
     String courseId,
     String team,
     String section) {
   this(section, team, name, email, comments, courseId);
   this.googleId = Sanitizer.sanitizeGoogleId(id);
 }
예제 #9
0
 @Override
 public void sanitizeForSaving() {
   googleId = Sanitizer.sanitizeGoogleId(googleId);
   email = Sanitizer.sanitizeEmail(email);
   course = Sanitizer.sanitizeTitle(course);
   name = Sanitizer.sanitizeName(name);
   team = Sanitizer.sanitizeTitle(team);
   section = Sanitizer.sanitizeTitle(section);
   comments = Sanitizer.sanitizeTextField(comments);
 }
예제 #10
0
 @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);
 }
예제 #11
0
  public StudentAttributes(Student student) {
    this();
    this.email = student.getEmail();
    this.course = student.getCourseId();
    this.name = student.getName();
    this.lastName = student.getLastName();
    this.comments = Sanitizer.sanitizeTextField(student.getComments());
    this.team = Sanitizer.sanitizeTitle(student.getTeamName());
    this.section =
        ((student.getSectionName() == null)
            ? Const.DEFAULT_SECTION
            : Sanitizer.sanitizeTitle(student.getSectionName()));
    // TODO: Is this supposed to be null or "" ?? Find out and standardize.
    this.googleId = ((student.getGoogleId() == null) ? "" : student.getGoogleId());
    Long keyAsLong = student.getRegistrationKey();
    this.key = (keyAsLong == null ? null : Student.getStringKeyForLongKey(keyAsLong));

    // TODO: this is for backward compatibility with old system. Old system
    // considers "" as unregistered. It should be changed to consider
    // null as unregistered.
  }
예제 #12
0
 public StudentAttributes(
     String section, String team, String name, String email, String comment, String courseId) {
   this();
   this.section = Sanitizer.sanitizeTitle(section);
   this.team = Sanitizer.sanitizeTitle(team);
   this.lastName = Sanitizer.sanitizeName(StringHelper.splitName(name)[1]);
   this.name = Sanitizer.sanitizeName(name);
   this.email = Sanitizer.sanitizeEmail(email);
   this.comments = Sanitizer.sanitizeTextField(comment);
   this.course = Sanitizer.sanitizeTitle(courseId);
 }
예제 #13
0
  public StudentAttributes(Student student) {
    this();
    this.email = student.getEmail();
    this.course = student.getCourseId();
    this.name = student.getName();
    this.lastName = student.getLastName();
    this.comments = Sanitizer.sanitizeTextField(student.getComments());
    this.team = Sanitizer.sanitizeTitle(student.getTeamName());
    this.section =
        (student.getSectionName() == null)
            ? Const.DEFAULT_SECTION
            : Sanitizer.sanitizeTitle(student.getSectionName());
    this.googleId = (student.getGoogleId() == null) ? "" : student.getGoogleId();
    Long keyAsLong = student.getRegistrationKey();
    this.key = (keyAsLong == null) ? null : Student.getStringKeyForLongKey(keyAsLong);
    /*
     * TODO: this is for backward compatibility with old system.
     * Old system considers "" as unregistered.
     * It should be changed to consider null as unregistered.
     */

    this.createdAt = student.getCreatedAt();
    this.updatedAt = student.getUpdatedAt();
  }
  @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;
  }
  @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 getAnswerCsv(FeedbackAbstractQuestionDetails questionDetails) {
   return Sanitizer.sanitizeForCsv(getAnswerString());
 }
 @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;
    }
  }
예제 #21
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);
 }