Search in sources :

Example 26 with FeedbackQuestionAttributes

use of teammates.common.datatransfer.attributes.FeedbackQuestionAttributes in project teammates by TEAMMATES.

the class InstructorFeedbackQuestionAddAction method extractFeedbackQuestionData.

private FeedbackQuestionAttributes extractFeedbackQuestionData(String creatorEmail) {
    FeedbackQuestionAttributes newQuestion = new FeedbackQuestionAttributes();
    newQuestion.creatorEmail = creatorEmail;
    newQuestion.courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, newQuestion.courseId);
    newQuestion.feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, newQuestion.feedbackSessionName);
    String feedbackQuestionGiverType = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE, feedbackQuestionGiverType);
    newQuestion.giverType = FeedbackParticipantType.valueOf(feedbackQuestionGiverType);
    String feedbackQuestionRecipientType = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE, feedbackQuestionRecipientType);
    newQuestion.recipientType = FeedbackParticipantType.valueOf(feedbackQuestionRecipientType);
    String feedbackQuestionNumber = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_NUMBER);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_QUESTION_NUMBER, feedbackQuestionNumber);
    newQuestion.questionNumber = Integer.parseInt(feedbackQuestionNumber);
    Assumption.assertTrue("Invalid question number", newQuestion.questionNumber >= 1);
    String numberOfEntityTypes = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE, numberOfEntityTypes);
    if ("custom".equals(numberOfEntityTypes) && (newQuestion.recipientType == FeedbackParticipantType.STUDENTS || newQuestion.recipientType == FeedbackParticipantType.TEAMS)) {
        String numberOfEntities = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIES);
        Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIES, numberOfEntities);
        newQuestion.numberOfEntitiesToGiveFeedbackTo = Integer.parseInt(numberOfEntities);
    } else {
        newQuestion.numberOfEntitiesToGiveFeedbackTo = Const.MAX_POSSIBLE_RECIPIENTS;
    }
    newQuestion.showResponsesTo = FeedbackParticipantType.getParticipantListFromCommaSeparatedValues(getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO));
    newQuestion.showGiverNameTo = FeedbackParticipantType.getParticipantListFromCommaSeparatedValues(getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO));
    newQuestion.showRecipientNameTo = FeedbackParticipantType.getParticipantListFromCommaSeparatedValues(getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO));
    String questionType = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_TYPE);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_QUESTION_TYPE, questionType);
    questionType = FeedbackQuestionType.standardizeIfConstSum(questionType);
    newQuestion.questionType = FeedbackQuestionType.valueOf(questionType);
    FeedbackQuestionDetails questionDetails = FeedbackQuestionDetails.createQuestionDetails(requestParameters, newQuestion.questionType);
    newQuestion.setQuestionDetails(questionDetails);
    String questionDescription = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION);
    newQuestion.setQuestionDescription(new Text(questionDescription));
    return newQuestion;
}
Also used : FeedbackQuestionDetails(teammates.common.datatransfer.questions.FeedbackQuestionDetails) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) Text(com.google.appengine.api.datastore.Text)

Example 27 with FeedbackQuestionAttributes

use of teammates.common.datatransfer.attributes.FeedbackQuestionAttributes in project teammates by TEAMMATES.

the class InstructorFeedbackQuestionAddAction method execute.

@Override
protected ActionResult execute() {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    String feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    InstructorAttributes instructorDetailForCourse = logic.getInstructorForGoogleId(courseId, account.googleId);
    gateKeeper.verifyAccessible(instructorDetailForCourse, logic.getFeedbackSession(feedbackSessionName, courseId), false, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION);
    FeedbackQuestionAttributes feedbackQuestion = extractFeedbackQuestionData(instructorDetailForCourse.email);
    List<String> questionDetailsErrors = feedbackQuestion.getQuestionDetails().validateQuestionDetails();
    List<StatusMessage> questionDetailsErrorsMessages = new ArrayList<>();
    for (String error : questionDetailsErrors) {
        questionDetailsErrorsMessages.add(new StatusMessage(error, StatusMessageColor.DANGER));
    }
    RedirectResult redirectResult = createRedirectResult(new PageData(account, sessionToken).getInstructorFeedbackEditLink(courseId, feedbackSessionName));
    if (!questionDetailsErrors.isEmpty()) {
        statusToUser.addAll(questionDetailsErrorsMessages);
        isError = true;
        return redirectResult;
    }
    String err = validateQuestionGiverRecipientVisibility(feedbackQuestion);
    if (!err.isEmpty()) {
        statusToUser.add(new StatusMessage(err, StatusMessageColor.DANGER));
        isError = true;
    }
    try {
        logic.createFeedbackQuestion(feedbackQuestion);
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_QUESTION_ADDED, StatusMessageColor.SUCCESS));
        statusToAdmin = "Created Feedback Question for Feedback Session:<span class=\"bold\">(" + feedbackQuestion.feedbackSessionName + ")</span> for Course <span class=\"bold\">[" + feedbackQuestion.courseId + "]</span> created.<br>" + "<span class=\"bold\">" + feedbackQuestion.getQuestionDetails().getQuestionTypeDisplayName() + ":</span> " + SanitizationHelper.sanitizeForHtml(feedbackQuestion.getQuestionDetails().getQuestionText());
    } catch (InvalidParametersException e) {
        statusToUser.add(new StatusMessage(e.getMessage(), StatusMessageColor.DANGER));
        statusToAdmin = e.getMessage();
        isError = true;
    }
    return redirectResult;
}
Also used : PageData(teammates.ui.pagedata.PageData) ArrayList(java.util.ArrayList) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 28 with FeedbackQuestionAttributes

use of teammates.common.datatransfer.attributes.FeedbackQuestionAttributes in project teammates by TEAMMATES.

the class InstructorFeedbackQuestionCopyPageAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionName);
    FeedbackSessionAttributes feedbackSession = logic.getFeedbackSession(feedbackSessionName, courseId);
    gateKeeper.verifyAccessible(logic.getInstructorForGoogleId(courseId, account.googleId), feedbackSession, false, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION);
    List<FeedbackQuestionAttributes> copiableQuestions = null;
    copiableQuestions = logic.getCopiableFeedbackQuestionsForInstructor(account.googleId);
    InstructorFeedbackQuestionCopyPageData data = new InstructorFeedbackQuestionCopyPageData(account, sessionToken, copiableQuestions);
    return createShowPageResult(Const.ViewURIs.INSTRUCTOR_FEEDBACK_QUESTION_COPY_MODAL, data);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) InstructorFeedbackQuestionCopyPageData(teammates.ui.pagedata.InstructorFeedbackQuestionCopyPageData) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)

Example 29 with FeedbackQuestionAttributes

use of teammates.common.datatransfer.attributes.FeedbackQuestionAttributes in project teammates by TEAMMATES.

the class InstructorFeedbackQuestionEditAction method extractFeedbackQuestionData.

private FeedbackQuestionAttributes extractFeedbackQuestionData() {
    FeedbackQuestionAttributes newQuestion = new FeedbackQuestionAttributes();
    newQuestion.setId(getNonNullRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_ID));
    newQuestion.courseId = getNonNullRequestParamValue(Const.ParamsNames.COURSE_ID);
    newQuestion.feedbackSessionName = getNonNullRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    // 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
    // When editing, usually the following fields are not null. If they are null somehow(edit from browser),
    // Then the field will not update and take on its old value.
    // When deleting, the following fields are null.
    // numofrecipients
    // questiontext
    // numofrecipientstype
    // recipienttype
    // receiverLeaderCheckbox
    // givertype
    // Can be null
    String giverType = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_GIVERTYPE);
    if (giverType != null) {
        newQuestion.giverType = FeedbackParticipantType.valueOf(giverType);
    }
    // Can be null
    String recipientType = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_RECIPIENTTYPE);
    if (recipientType != null) {
        newQuestion.recipientType = FeedbackParticipantType.valueOf(recipientType);
    }
    String questionNumber = getNonNullRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_NUMBER);
    newQuestion.questionNumber = Integer.parseInt(questionNumber);
    Assumption.assertTrue("Invalid question number", newQuestion.questionNumber >= 1);
    // Can be null
    String nEntityTypes = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIESTYPE);
    if (numberOfEntitiesIsUserDefined(newQuestion.recipientType, nEntityTypes)) {
        String nEntities = getNonNullRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_NUMBEROFENTITIES);
        newQuestion.numberOfEntitiesToGiveFeedbackTo = Integer.parseInt(nEntities);
    } else {
        newQuestion.numberOfEntitiesToGiveFeedbackTo = Const.MAX_POSSIBLE_RECIPIENTS;
    }
    newQuestion.showResponsesTo = FeedbackParticipantType.getParticipantListFromCommaSeparatedValues(getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_SHOWRESPONSESTO));
    newQuestion.showGiverNameTo = FeedbackParticipantType.getParticipantListFromCommaSeparatedValues(getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_SHOWGIVERTO));
    newQuestion.showRecipientNameTo = FeedbackParticipantType.getParticipantListFromCommaSeparatedValues(getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_SHOWRECIPIENTTO));
    String questionType = getNonNullRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_TYPE);
    newQuestion.questionType = FeedbackQuestionType.valueOf(questionType);
    // Can be null
    String questionText = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_TEXT);
    if (questionText != null && !questionText.isEmpty()) {
        FeedbackQuestionDetails questionDetails = FeedbackQuestionDetails.createQuestionDetails(requestParameters, newQuestion.questionType);
        newQuestion.setQuestionDetails(questionDetails);
    }
    String questionDescription = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_DESCRIPTION);
    newQuestion.setQuestionDescription(new Text(questionDescription));
    return newQuestion;
}
Also used : FeedbackQuestionDetails(teammates.common.datatransfer.questions.FeedbackQuestionDetails) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) Text(com.google.appengine.api.datastore.Text)

Example 30 with FeedbackQuestionAttributes

use of teammates.common.datatransfer.attributes.FeedbackQuestionAttributes in project teammates by TEAMMATES.

the class InstructorFeedbackQuestionVisibilityMessageAction method execute.

@Override
protected ActionResult execute() {
    FeedbackQuestionAttributes feedbackQuestion = extractFeedbackQuestionData(account.email);
    List<String> message = feedbackQuestion.getVisibilityMessage();
    InstructorFeedbackQuestionVisibilityMessagePageData data = new InstructorFeedbackQuestionVisibilityMessagePageData(account, sessionToken);
    data.visibilityMessage = message;
    return createAjaxResult(data);
}
Also used : InstructorFeedbackQuestionVisibilityMessagePageData(teammates.ui.pagedata.InstructorFeedbackQuestionVisibilityMessagePageData) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)

Aggregations

FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)154 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)64 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)48 ArrayList (java.util.ArrayList)47 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)38 Test (org.testng.annotations.Test)35 FeedbackResponsesDb (teammates.storage.api.FeedbackResponsesDb)25 List (java.util.List)23 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)23 FeedbackQuestionsDb (teammates.storage.api.FeedbackQuestionsDb)19 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)18 HashMap (java.util.HashMap)17 RedirectResult (teammates.ui.controller.RedirectResult)17 HashSet (java.util.HashSet)12 FeedbackResponseCommentAttributes (teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)12 Text (com.google.appengine.api.datastore.Text)11 Map (java.util.Map)10 FeedbackQuestionDetails (teammates.common.datatransfer.questions.FeedbackQuestionDetails)10 LinkedHashMap (java.util.LinkedHashMap)9 DataBundle (teammates.common.datatransfer.DataBundle)9