コード例 #1
0
  /**
   * Updates a {@link FeedbackResponse} based on it's {@code id}.<br>
   * If the giver/recipient field is changed, the {@link FeedbackResponse} is updated by recreating
   * the response<br>
   * in order to prevent an id clash if the previous email is reused later on.
   */
  public void updateFeedbackResponse(FeedbackResponseAttributes responseToUpdate)
      throws InvalidParametersException, EntityDoesNotExistException, EntityAlreadyExistsException {

    // Create a copy.
    FeedbackResponseAttributes newResponse = new FeedbackResponseAttributes(responseToUpdate);
    FeedbackResponseAttributes oldResponse = null;
    if (newResponse.getId() == null) {
      oldResponse =
          frDb.getFeedbackResponse(
              newResponse.feedbackQuestionId, newResponse.giverEmail, newResponse.recipientEmail);
    } else {
      oldResponse = frDb.getFeedbackResponse(newResponse.getId());
    }

    if (oldResponse == null) {
      throw new EntityDoesNotExistException(
          "Trying to update a feedback response that does not exist.");
    }

    // Copy values that cannot be changed to defensively avoid invalid
    // parameters.
    newResponse.courseId = oldResponse.courseId;
    newResponse.feedbackSessionName = oldResponse.feedbackSessionName;
    newResponse.feedbackQuestionId = oldResponse.feedbackQuestionId;
    newResponse.feedbackQuestionType = oldResponse.feedbackQuestionType;

    if (newResponse.responseMetaData == null) {
      newResponse.responseMetaData = oldResponse.responseMetaData;
    }
    if (newResponse.giverEmail == null) {
      newResponse.giverEmail = oldResponse.giverEmail;
    }
    if (newResponse.recipientEmail == null) {
      newResponse.recipientEmail = oldResponse.recipientEmail;
    }
    if (newResponse.giverSection == null) {
      newResponse.giverSection = oldResponse.giverSection;
    }
    if (newResponse.recipientSection == null) {
      newResponse.recipientSection = oldResponse.recipientSection;
    }

    if (!newResponse.recipientEmail.equals(oldResponse.recipientEmail)
        || !newResponse.giverEmail.equals(oldResponse.giverEmail)) {
      // Recreate response to prevent possible future id conflict.
      try {
        newResponse.setId(null);
        frDb.createEntity(newResponse);
        frDb.deleteEntity(oldResponse);
      } catch (EntityAlreadyExistsException e) {
        log.warning("Trying to update an existing response to one that already exists.");
        throw new EntityAlreadyExistsException(
            e.getMessage()
                + Const.EOL
                + "Trying to update recipient for response to one that already exists for this giver.");
      }
    } else {
      frDb.updateFeedbackResponse(newResponse);
    }
  }
コード例 #2
0
  public void createFeedbackResponse(FeedbackResponseAttributes fra)
      throws InvalidParametersException {
    try {
      frDb.createEntity(fra);
    } catch (Exception EntityAlreadyExistsException) {
      try {
        FeedbackResponseAttributes existingFeedback = new FeedbackResponseAttributes();

        existingFeedback =
            frDb.getFeedbackResponse(fra.feedbackQuestionId, fra.giverEmail, fra.recipientEmail);
        fra.setId(existingFeedback.getId());

        frDb.updateFeedbackResponse(fra);
      } catch (Exception EntityDoesNotExistException) {
        Assumption.fail();
      }
    }
  }
コード例 #3
0
 /**
  * Creates a single FeedbackSessionResultsBundle object which comprises a single feedback session,
  * a single question, a single response and a single response comment
  */
 private static FeedbackSessionResultsBundle getSingleFeedbackSessionResultsBundle(
     CourseRoster roster) {
   FeedbackSessionAttributes session = dataBundle.feedbackSessions.get("session1InCourse1");
   FeedbackResponseAttributes response = dataBundle.feedbackResponses.get("response1ForQ1S1C1");
   response.setId("1");
   List<FeedbackResponseAttributes> responses = Arrays.asList(response);
   Map<String, FeedbackQuestionAttributes> relevantQuestions =
       new HashMap<String, FeedbackQuestionAttributes>();
   FeedbackQuestionAttributes question =
       dataBundle.feedbackQuestions.get("qn1InSession1InCourse1");
   question.setId("1");
   relevantQuestions.put(question.getId(), question);
   Map<String, String> emailNameTable = new HashMap<String, String>();
   Map<String, String> emailLastNameTable = new HashMap<String, String>();
   Map<String, String> emailTeamNameTable = new HashMap<String, String>();
   Map<String, boolean[]> visibilityTable = new HashMap<String, boolean[]>();
   Map<String, List<FeedbackResponseCommentAttributes>> responseComments =
       new HashMap<String, List<FeedbackResponseCommentAttributes>>();
   emailNameTable.put(sampleStudent.email, sampleStudent.name);
   emailLastNameTable.put(sampleStudent.email, sampleStudent.lastName);
   emailTeamNameTable.put(sampleStudent.email, sampleStudent.team);
   boolean[] visibility = {true, true};
   visibilityTable.put(response.getId(), visibility);
   FeedbackSessionResponseStatus responseStatus = new FeedbackSessionResponseStatus();
   responseStatus.emailNameTable.put(sampleStudent.email, sampleStudent.name);
   responseStatus.emailTeamNameTable.put(sampleStudent.email, sampleStudent.team);
   FeedbackResponseCommentAttributes responseComment =
       dataBundle.feedbackResponseComments.get("comment1FromT1C1ToR1Q1S1C1");
   List<FeedbackResponseCommentAttributes> responseCommentsList = Arrays.asList(responseComment);
   responseComments.put(response.getId(), responseCommentsList);
   boolean isComplete = true;
   return new FeedbackSessionResultsBundle(
       session,
       responses,
       relevantQuestions,
       emailNameTable,
       emailLastNameTable,
       emailTeamNameTable,
       visibilityTable,
       responseStatus,
       roster,
       responseComments,
       isComplete);
 }
コード例 #4
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;
  }