Search in sources :

Example 1 with ExceedingRangeException

use of teammates.common.exception.ExceedingRangeException in project teammates by TEAMMATES.

the class InstructorFeedbackResultsDownloadAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    String feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    String section = getRequestParamValue(Const.ParamsNames.SECTION_NAME);
    boolean isMissingResponsesShown = getRequestParamAsBoolean(Const.ParamsNames.FEEDBACK_RESULTS_INDICATE_MISSING_RESPONSES);
    boolean isStatsShown = getRequestParamAsBoolean(Const.ParamsNames.FEEDBACK_RESULTS_SHOWSTATS);
    String questionId = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_ID);
    String questionNumber = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_NUMBER);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionName);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    FeedbackSessionAttributes session = logic.getFeedbackSession(feedbackSessionName, courseId);
    boolean isCreatorOnly = true;
    gateKeeper.verifyAccessible(instructor, session, !isCreatorOnly);
    String fileContent;
    String fileName;
    try {
        String questionName = "";
        if (questionNumber != null) {
            questionName = "_question" + questionNumber;
        }
        if (section == null || "All".equals(section)) {
            fileContent = logic.getFeedbackSessionResultSummaryAsCsv(courseId, feedbackSessionName, instructor.email, isMissingResponsesShown, isStatsShown, questionId);
            fileName = courseId + "_" + feedbackSessionName + questionName;
            statusToAdmin = "Summary data for Feedback Session " + feedbackSessionName + " in Course " + courseId + " was downloaded";
        } else {
            fileContent = logic.getFeedbackSessionResultSummaryInSectionAsCsv(courseId, feedbackSessionName, instructor.email, section, questionId, isMissingResponsesShown, isStatsShown);
            fileName = courseId + "_" + feedbackSessionName + "_" + section + questionName;
            statusToAdmin = "Summary data for Feedback Session " + feedbackSessionName + " in Course " + courseId + " within " + section + " was downloaded";
        }
    } catch (ExceedingRangeException e) {
        // not tested as the test file is not large enough to reach this catch block
        statusToUser.add(new StatusMessage("This session has more responses than that can be downloaded in one go. " + "Please download responses for " + (questionNumber == null ? "one question at a time instead. " + "To download responses for a specific question, click on the corresponding question number." : "section instead."), StatusMessageColor.DANGER));
        isError = true;
        RedirectResult result = createRedirectResult(Const.ActionURIs.INSTRUCTOR_FEEDBACK_RESULTS_PAGE);
        result.addResponseParam(Const.ParamsNames.COURSE_ID, courseId);
        result.addResponseParam(Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionName);
        return result;
    }
    return createFileDownloadResult(fileName, fileContent);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) ExceedingRangeException(teammates.common.exception.ExceedingRangeException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 2 with ExceedingRangeException

use of teammates.common.exception.ExceedingRangeException in project teammates by TEAMMATES.

the class GenerateFeedbackReport method doOperation.

@Override
protected void doOperation() {
    Logic logic = new Logic();
    try {
        String fileContent = logic.getFeedbackSessionResultSummaryAsCsv("CourseID", "Session Name", "instructor@email.com", true, true, null);
        writeToFile("result.csv", fileContent);
    } catch (EntityDoesNotExistException | ExceedingRangeException e) {
        e.printStackTrace();
    }
}
Also used : ExceedingRangeException(teammates.common.exception.ExceedingRangeException) Logic(teammates.logic.api.Logic) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 3 with ExceedingRangeException

use of teammates.common.exception.ExceedingRangeException in project teammates by TEAMMATES.

the class FeedbackSessionsLogic method getFeedbackSessionResultsSummaryInSectionAsCsv.

public String getFeedbackSessionResultsSummaryInSectionAsCsv(String feedbackSessionName, String courseId, String userEmail, String section, String questionId, boolean isMissingResponsesShown, boolean isStatsShown) throws EntityDoesNotExistException, ExceedingRangeException {
    FeedbackSessionResultsBundle results;
    int indicatedRange = section == null ? Const.INSTRUCTOR_VIEW_RESPONSE_LIMIT : -1;
    if (questionId == null) {
        results = getFeedbackSessionResultsForInstructorInSectionWithinRangeFromView(feedbackSessionName, courseId, userEmail, section, indicatedRange, Const.FeedbackSessionResults.GRQ_SORT_TYPE);
    } else if (section == null) {
        results = getFeedbackSessionResultsForInstructorFromQuestion(feedbackSessionName, courseId, userEmail, questionId);
    } else {
        results = getFeedbackSessionResultsForInstructorFromQuestionInSection(feedbackSessionName, courseId, userEmail, questionId, section);
    }
    if (!results.isComplete) {
        throw new ExceedingRangeException(ERROR_NUMBER_OF_RESPONSES_EXCEEDS_RANGE);
    }
    // sort responses by giver > recipient > qnNumber
    results.responses.sort(results.compareByGiverRecipientQuestion);
    StringBuilder exportBuilder = new StringBuilder(100);
    exportBuilder.append(String.format("Course,%s", SanitizationHelper.sanitizeForCsv(results.feedbackSession.getCourseId()))).append(System.lineSeparator()).append(String.format("Session Name,%s", SanitizationHelper.sanitizeForCsv(results.feedbackSession.getFeedbackSessionName()))).append(System.lineSeparator());
    if (section != null) {
        exportBuilder.append(String.format("Section Name,%s", SanitizationHelper.sanitizeForCsv(section))).append(System.lineSeparator());
    }
    exportBuilder.append(System.lineSeparator()).append(System.lineSeparator());
    Set<Entry<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>>> entrySet = results.getQuestionResponseMap().entrySet();
    for (Map.Entry<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>> entry : entrySet) {
        exportBuilder.append(getFeedbackSessionResultsForQuestionInCsvFormat(results, entry, isMissingResponsesShown, isStatsShown, section));
    }
    return exportBuilder.toString();
}
Also used : Entry(java.util.Map.Entry) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) ExceedingRangeException(teammates.common.exception.ExceedingRangeException) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) FeedbackSessionResultsBundle(teammates.common.datatransfer.FeedbackSessionResultsBundle)

Aggregations

ExceedingRangeException (teammates.common.exception.ExceedingRangeException)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 FeedbackSessionResultsBundle (teammates.common.datatransfer.FeedbackSessionResultsBundle)1 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)1 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)1 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)1 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)1 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)1 StatusMessage (teammates.common.util.StatusMessage)1 Logic (teammates.logic.api.Logic)1