コード例 #1
0
  @Override
  public boolean execute() {

    log.info(
        "Adjusting submissions for feedback session :" + sessionName + "in course : " + courseId);

    FeedbackSessionAttributes feedbackSession =
        FeedbackSessionsLogic.inst().getFeedbackSession(sessionName, courseId);

    String errorString =
        "Error encountered while adjusting feedback session responses of %s in course : %s : %s\n%s";

    if (feedbackSession == null) {
      log.severe(String.format(errorString, sessionName, courseId, "feedback session is null", ""));
      return false;
    }

    List<FeedbackResponseAttributes> allResponses =
        FeedbackResponsesLogic.inst()
            .getFeedbackResponsesForSession(
                feedbackSession.getFeedbackSessionName(), feedbackSession.getCourseId());
    Gson gsonParser = Utils.getTeammatesGson();
    ArrayList<StudentEnrollDetails> enrollmentList =
        gsonParser.fromJson(
            enrollmentDetails, new TypeToken<ArrayList<StudentEnrollDetails>>() {}.getType());
    for (FeedbackResponseAttributes response : allResponses) {
      try {
        StudentsLogic.inst().adjustFeedbackResponseForEnrollments(enrollmentList, response);
      } catch (Exception e) {
        log.severe(
            String.format(
                errorString,
                sessionName,
                courseId,
                e.getMessage(),
                ActivityLogEntry.generateServletActionFailureLogMessage(request, e)));
        return false;
      }
    }
    return true;
  }
コード例 #2
0
  private FeedbackResponseAttributes extractFeedbackResponseData(
      Map<String, String[]> requestParameters,
      int questionIndx,
      int responseIndx,
      FeedbackQuestionAttributes feedbackQuestionAttributes) {

    FeedbackQuestionDetails questionDetails = feedbackQuestionAttributes.getQuestionDetails();
    FeedbackResponseAttributes response = new FeedbackResponseAttributes();

    // This field can be null if the response is new
    response.setId(
        HttpRequestHelper.getValueFromParamMap(
            requestParameters,
            Const.ParamsNames.FEEDBACK_RESPONSE_ID + "-" + questionIndx + "-" + responseIndx));

    response.feedbackSessionName =
        HttpRequestHelper.getValueFromParamMap(
            requestParameters, Const.ParamsNames.FEEDBACK_SESSION_NAME);
    Assumption.assertNotNull("Null feedback session name", response.feedbackSessionName);

    response.courseId =
        HttpRequestHelper.getValueFromParamMap(requestParameters, Const.ParamsNames.COURSE_ID);
    Assumption.assertNotNull("Null feedback courseId", response.courseId);

    response.feedbackQuestionId =
        HttpRequestHelper.getValueFromParamMap(
            requestParameters, Const.ParamsNames.FEEDBACK_QUESTION_ID + "-" + questionIndx);
    Assumption.assertNotNull("Null feedbackQuestionId", response.feedbackQuestionId);
    Assumption.assertEquals(
        "feedbackQuestionId Mismatch",
        feedbackQuestionAttributes.getId(),
        response.feedbackQuestionId);

    response.recipientEmail =
        HttpRequestHelper.getValueFromParamMap(
            requestParameters,
            Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT
                + "-"
                + questionIndx
                + "-"
                + responseIndx);
    Assumption.assertNotNull("Null feedback recipientEmail", response.recipientEmail);

    String feedbackQuestionType =
        HttpRequestHelper.getValueFromParamMap(
            requestParameters, Const.ParamsNames.FEEDBACK_QUESTION_TYPE + "-" + questionIndx);
    Assumption.assertNotNull("Null feedbackQuestionType", feedbackQuestionType);
    response.feedbackQuestionType = FeedbackQuestionType.valueOf(feedbackQuestionType);

    FeedbackParticipantType recipientType = feedbackQuestionAttributes.recipientType;
    if (recipientType == FeedbackParticipantType.INSTRUCTORS
        || recipientType == FeedbackParticipantType.NONE) {
      response.recipientSection = Const.DEFAULT_SECTION;
    } else if (recipientType == FeedbackParticipantType.TEAMS) {
      response.recipientSection =
          StudentsLogic.inst().getSectionForTeam(courseId, response.recipientEmail);
    } else if (recipientType == FeedbackParticipantType.STUDENTS) {
      StudentAttributes student = logic.getStudentForEmail(courseId, response.recipientEmail);
      response.recipientSection = (student == null) ? Const.DEFAULT_SECTION : student.section;
    } else {
      response.recipientSection = getUserSectionForCourse();
    }

    // This field can be null if the question is skipped
    String[] answer =
        HttpRequestHelper.getValuesFromParamMap(
            requestParameters,
            Const.ParamsNames.FEEDBACK_RESPONSE_TEXT + "-" + questionIndx + "-" + responseIndx);

    if (!questionDetails.isQuestionSkipped(answer)) {
      FeedbackResponseDetails responseDetails =
          FeedbackResponseDetails.createResponseDetails(
              answer,
              questionDetails.questionType,
              questionDetails,
              requestParameters,
              questionIndx,
              responseIndx);
      response.setResponseDetails(responseDetails);
    } else {
      response.responseMetaData = new Text("");
    }

    return response;
  }
コード例 #3
0
  @Test
  public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor = dataBundle.instructors.get("instructor3OfCourse1");
    StudentAttributes student = dataBundle.students.get("student2InCourse1");
    String instructorId = instructor.googleId;

    gaeSimulation.loginAsInstructor(instructorId);

    ______TS("Invalid parameters");

    // no params
    verifyAssumptionFailure();

    // null courseId
    String[] invalidParams = new String[] {Const.ParamsNames.STUDENT_EMAIL, student.email};

    verifyAssumptionFailure(invalidParams);

    // null student email
    invalidParams = new String[] {Const.ParamsNames.COURSE_ID, instructor.courseId};

    verifyAssumptionFailure(invalidParams);

    // student not in course
    String studentEmailOfStudent1InCourse2 = dataBundle.students.get("student1InCourse2").email;
    invalidParams =
        new String[] {
          Const.ParamsNames.COURSE_ID,
          instructor.courseId,
          Const.ParamsNames.STUDENT_EMAIL,
          studentEmailOfStudent1InCourse2
        };

    RedirectResult redirect = getRedirectResult(getAction(invalidParams));

    AssertHelper.assertContains(
        Const.ActionURIs.INSTRUCTOR_HOME_PAGE, redirect.getDestinationWithParams());
    AssertHelper.assertContains(
        Const.StatusMessages.STUDENT_NOT_FOUND_FOR_RECORDS, redirect.getStatusMessage());

    ______TS("Typical case: student has some records and has profile");

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

    InstructorStudentRecordsPageAction a = getAction(submissionParams);
    ShowPageResult r = getShowPageResult(a);

    assertEquals(
        Const.ViewURIs.INSTRUCTOR_STUDENT_RECORDS + "?error=false&user=idOfInstructor3",
        r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("", r.getStatusMessage());

    InstructorStudentRecordsPageData actualData = (InstructorStudentRecordsPageData) r.data;
    StudentProfileAttributes expectedProfile = new StudentProfileAttributes();
    expectedProfile.googleId = student.googleId;
    expectedProfile.modifiedDate = actualData.spa.modifiedDate;
    expectedProfile.pictureKey = actualData.spa.pictureKey;

    assertEquals(instructorId, actualData.account.googleId);
    assertEquals(instructor.courseId, actualData.getCourseId());
    assertEquals(1, actualData.getCommentsForStudentTable().get(0).getRows().size());
    assertEquals(6, actualData.getSessionNames().size());
    assertEquals(student.googleId, actualData.spa.googleId);

    String expectedLogMessage =
        "TEAMMATESLOG|||instructorStudentRecordsPage|||instructorStudentRecordsPage"
            + "|||true|||Instructor|||Instructor 3 of Course 1 and 2|||idOfInstructor3"
            + "|||[email protected]|||instructorStudentRecords Page Load<br>"
            + "Viewing <span class=\"bold\">"
            + student.email
            + "'s</span> records "
            + "for Course <span class=\"bold\">["
            + instructor.courseId
            + "]</span><br>"
            + "Number of sessions: 6<br>"
            + "Student Profile: "
            + expectedProfile.toString()
            + "|||/page/instructorStudentRecordsPage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());

    ______TS("Typical case: instructor cannot view sections");

    instructor = dataBundle.instructors.get("helperOfCourse1");
    gaeSimulation.loginAsInstructor(instructor.googleId);

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

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

    assertEquals(
        Const.ViewURIs.INSTRUCTOR_STUDENT_RECORDS + "?error=false&user=idOfHelperOfCourse1",
        r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals(
        "Normally, we would show the student’s profile here. "
            + "However, you do not have access to view this student's profile<br>"
            + "No records were found for this student",
        r.getStatusMessage());

    ______TS("Typical case: student has no records, no profiles");

    String instructor4Id = dataBundle.instructors.get("instructor4").googleId;
    // re-login as another instructor for new test
    gaeSimulation.loginAsInstructor(instructor4Id);
    String courseIdWithNoSession = "idOfCourseNoEvals";

    StudentAttributes testStudent = createStudentInTypicalDataBundleForCourseWithNoSession();

    String[] submissionParamsWithNoSession =
        new String[] {
          Const.ParamsNames.COURSE_ID,
          courseIdWithNoSession,
          Const.ParamsNames.STUDENT_EMAIL,
          "*****@*****.**"
        };

    InstructorStudentRecordsPageAction aWithNoSession = getAction(submissionParamsWithNoSession);
    ShowPageResult rWithNoSession = getShowPageResult(aWithNoSession);
    List<String> expectedMessages = new ArrayList<String>();
    expectedMessages.add("No records were found for this student");
    expectedMessages.add(Const.StatusMessages.STUDENT_NOT_JOINED_YET_FOR_RECORDS);
    AssertHelper.assertContains(expectedMessages, rWithNoSession.getStatusMessage());

    ______TS("Typical case: student has profile but no records");

    testStudent.googleId = "valid.no.sessions";
    StudentsLogic.inst().updateStudentCascadeWithoutDocument(testStudent.email, testStudent);
    logic.createAccount(
        testStudent.googleId, testStudent.name, false, testStudent.email, "valid institute");

    a = getAction(submissionParamsWithNoSession);
    r = getShowPageResult(a);

    AssertHelper.assertContains("No records were found for this student", r.getStatusMessage());
  }
コード例 #4
0
  public void testDeleteCourse() throws Exception {

    ______TS("typical case");

    CourseAttributes course1OfInstructor = dataBundle.courses.get("typicalCourse1");
    StudentAttributes studentInCourse = dataBundle.students.get("student1InCourse1");

    // Ensure there are entities in the datastore under this course
    assertTrue(StudentsLogic.inst().getStudentsForCourse(course1OfInstructor.id).size() != 0);

    TestHelper.verifyPresentInDatastore(course1OfInstructor);
    TestHelper.verifyPresentInDatastore(studentInCourse);
    TestHelper.verifyPresentInDatastore(dataBundle.evaluations.get("evaluation1InCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.evaluations.get("evaluation2InCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.instructors.get("instructor1OfCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.instructors.get("instructor3OfCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.students.get("student1InCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.students.get("student5InCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.feedbackSessions.get("session1InCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.feedbackSessions.get("session2InCourse1"));
    assertEquals(course1OfInstructor.id, studentInCourse.course);

    coursesLogic.deleteCourseCascade(course1OfInstructor.id);

    // Ensure the course and related entities are deleted
    TestHelper.verifyAbsentInDatastore(course1OfInstructor);
    TestHelper.verifyAbsentInDatastore(studentInCourse);
    TestHelper.verifyAbsentInDatastore(dataBundle.evaluations.get("evaluation1InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.evaluations.get("evaluation2InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.instructors.get("instructor1OfCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.instructors.get("instructor3OfCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.students.get("student1InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.students.get("student5InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.feedbackSessions.get("session1InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.feedbackSessions.get("session2InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.comments.get("comment1FromI1C1toS1C1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.comments.get("comment2FromI1C1toS1C1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.comments.get("comment1FromI3C1toS2C1"));

    ArrayList<SubmissionAttributes> submissionsOfCourse =
        new ArrayList<SubmissionAttributes>(dataBundle.submissions.values());
    for (SubmissionAttributes s : submissionsOfCourse) {
      if (s.course.equals(course1OfInstructor.id)) {
        TestHelper.verifyAbsentInDatastore(s);
      }
    }

    ______TS("non-existent");

    // try to delete again. Should fail silently.
    coursesLogic.deleteCourseCascade(course1OfInstructor.id);

    ______TS("null parameter");

    try {
      coursesLogic.deleteCourseCascade(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }