コード例 #1
0
  private static FeedbackQuestionAttributes extractFeedbackQuestionData(
      Map<String, String[]> requestParameters) {
    FeedbackQuestionAttributes newQuestion = new FeedbackQuestionAttributes();

    newQuestion.setId(
        HttpRequestHelper.getValueFromParamMap(
            requestParameters, Const.ParamsNames.FEEDBACK_QUESTION_ID));
    Assumption.assertNotNull("Null question id", newQuestion.getId());

    newQuestion.courseId =
        HttpRequestHelper.getValueFromParamMap(requestParameters, Const.ParamsNames.COURSE_ID);
    Assumption.assertNotNull("Null course id", newQuestion.courseId);

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

    // TODO thoroughly investigate when and why these parameters can be null
    // and check all possibilities in the tests
    // should only be null when deleting. might be good to separate the delete action from this
    // class

    // Can be null
    String giverType =
        HttpRequestHelper.getValueFromParamMap(
            requestParameters, Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE);
    if (giverType != null) {
      newQuestion.giverType = FeedbackParticipantType.valueOf(giverType);
    }

    // Can be null
    String recipientType =
        HttpRequestHelper.getValueFromParamMap(
            requestParameters, Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE);
    if (recipientType != null) {
      newQuestion.recipientType = FeedbackParticipantType.valueOf(recipientType);
    }

    String questionNumber =
        HttpRequestHelper.getValueFromParamMap(
            requestParameters, Const.ParamsNames.FEEDBACK_QUESTION_NUMBER);
    Assumption.assertNotNull("Null question number", questionNumber);
    newQuestion.questionNumber = Integer.parseInt(questionNumber);

    // Can be null
    String nEntityTypes =
        HttpRequestHelper.getValueFromParamMap(
            requestParameters, Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE);
    if (numberOfEntitiesIsUserDefined(newQuestion.recipientType, nEntityTypes)) {
      String nEntities;
      nEntities =
          HttpRequestHelper.getValueFromParamMap(
              requestParameters, Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIES);
      Assumption.assertNotNull(nEntities);
      newQuestion.numberOfEntitiesToGiveFeedbackTo = Integer.parseInt(nEntities);
    } else {
      newQuestion.numberOfEntitiesToGiveFeedbackTo = Const.MAX_POSSIBLE_RECIPIENTS;
    }

    newQuestion.showResponsesTo =
        getParticipantListFromParams(
            HttpRequestHelper.getValueFromParamMap(
                requestParameters, Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO));
    newQuestion.showGiverNameTo =
        getParticipantListFromParams(
            HttpRequestHelper.getValueFromParamMap(
                requestParameters, Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO));
    newQuestion.showRecipientNameTo =
        getParticipantListFromParams(
            HttpRequestHelper.getValueFromParamMap(
                requestParameters, Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO));

    String questionType =
        HttpRequestHelper.getValueFromParamMap(
            requestParameters, Const.ParamsNames.FEEDBACK_QUESTION_TYPE);
    Assumption.assertNotNull(questionType);
    newQuestion.questionType = FeedbackQuestionType.valueOf(questionType);

    // Can be null
    String questionText =
        HttpRequestHelper.getValueFromParamMap(
            requestParameters, Const.ParamsNames.FEEDBACK_QUESTION_TEXT);
    if (questionText != null) {
      FeedbackAbstractQuestionDetails questionDetails =
          FeedbackAbstractQuestionDetails.createQuestionDetails(
              requestParameters, newQuestion.questionType);
      newQuestion.setQuestionDetails(questionDetails);
    }

    return newQuestion;
  }
コード例 #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;
  }