Search in sources :

Example 66 with StatusMessage

use of teammates.common.util.StatusMessage in project teammates by TEAMMATES.

the class AdminEmailComposeSendAction method moveJobToAddressModeTaskQueue.

private void moveJobToAddressModeTaskQueue() {
    if (!isAddressModeOn) {
        return;
    }
    taskQueuer.scheduleAdminEmailPreparationInAddressMode(emailId, addressReceiverListString);
    statusToAdmin += "<br/>" + "Recipient: " + addressReceiverListString;
    statusToUser.add(new StatusMessage("Email will be sent within an hour to " + addressReceiverListString, StatusMessageColor.SUCCESS));
}
Also used : StatusMessage(teammates.common.util.StatusMessage)

Example 67 with StatusMessage

use of teammates.common.util.StatusMessage in project teammates by TEAMMATES.

the class AdminEmailLogPageAction method searchEmailLogsWithExactTimePeriod.

/**
 * Searches all logs in the time period specified in the query.
 */
private void searchEmailLogsWithExactTimePeriod(AdminEmailLogPageData data) {
    List<String> versionToQuery = getVersionsForQuery(data.getVersions());
    AdminLogQuery query = new AdminLogQuery(versionToQuery, data.getFromDate(), data.getToDate());
    List<AppLogLine> searchResult = new GaeLogApi().fetchLogs(query);
    data.setLogs(filterLogsForEmailLogPage(searchResult, data));
    long nextEndTimeToSearch = data.getFromDate() - 1;
    int totalLogsSearched = searchResult.size();
    String status = "&nbsp;&nbsp;Total Logs gone through in last search: " + totalLogsSearched + "<br>" + "<button class=\"btn-link\" id=\"button_older\" data-next-end-time-to-search=\"" + nextEndTimeToSearch + "\">Search More</button>";
    data.setStatusForAjax(status);
    statusToUser.add(new StatusMessage(status, StatusMessageColor.INFO));
}
Also used : AppLogLine(com.google.appengine.api.log.AppLogLine) AdminLogQuery(teammates.common.util.AdminLogQuery) GaeLogApi(teammates.common.util.GaeLogApi) StatusMessage(teammates.common.util.StatusMessage)

Example 68 with StatusMessage

use of teammates.common.util.StatusMessage in project teammates by TEAMMATES.

the class AdminEmailTrashAction method execute.

@Override
protected ActionResult execute() {
    gateKeeper.verifyAdminPrivileges(account);
    String emailId = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_ID);
    String redirect = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_TRASH_ACTION_REDIRECT);
    if (redirect == null) {
        redirect = Const.ActionURIs.ADMIN_EMAIL_TRASH_PAGE;
    }
    if (redirect.contains("sentpage")) {
        redirect = Const.ActionURIs.ADMIN_EMAIL_SENT_PAGE;
    } else if (redirect.contains("draftpage")) {
        redirect = Const.ActionURIs.ADMIN_EMAIL_DRAFT_PAGE;
    } else {
        redirect = Const.ActionURIs.ADMIN_EMAIL_TRASH_PAGE;
    }
    if (emailId == null || emailId.isEmpty()) {
        statusToAdmin = "Invalid parameter : email id cannot be null or empty";
        statusToUser.add(new StatusMessage("Invalid parameter : email id cannot be null or empty", StatusMessageColor.DANGER));
        return createRedirectResult(redirect);
    }
    if (requestUrl.contains(Const.ActionURIs.ADMIN_EMAIL_MOVE_TO_TRASH)) {
        try {
            logic.moveAdminEmailToTrashBin(emailId);
            statusToAdmin = "Email with id" + emailId + " has been moved to trash bin";
            statusToUser.add(new StatusMessage("The item has been moved to trash bin", StatusMessageColor.SUCCESS));
        } catch (InvalidParametersException | EntityDoesNotExistException e) {
            setStatusForException(e, "An error has occurred when moving email to trash bin");
        }
        return createRedirectResult(redirect);
    } else if (requestUrl.contains(Const.ActionURIs.ADMIN_EMAIL_MOVE_OUT_TRASH)) {
        try {
            logic.moveAdminEmailOutOfTrashBin(emailId);
            statusToAdmin = "Email with id" + emailId + " has been moved out of trash bin";
            statusToUser.add(new StatusMessage("The item has been moved out of trash bin", StatusMessageColor.SUCCESS));
        } catch (InvalidParametersException | EntityDoesNotExistException e) {
            setStatusForException(e, "An error has occurred when moving email out of trash bin");
        }
        return createRedirectResult(Const.ActionURIs.ADMIN_EMAIL_TRASH_PAGE);
    }
    return createRedirectResult(redirect);
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) StatusMessage(teammates.common.util.StatusMessage) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 69 with StatusMessage

use of teammates.common.util.StatusMessage in project teammates by TEAMMATES.

the class FeedbackSubmissionEditSaveAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionName);
    setAdditionalParameters();
    verifyAccessibleForSpecificUser();
    String userEmailForCourse = getUserEmailForCourse();
    data = new FeedbackSubmissionEditPageData(account, student, sessionToken);
    data.bundle = getDataBundle(userEmailForCourse);
    Assumption.assertNotNull("Feedback session " + feedbackSessionName + " does not exist in " + courseId + ".", data.bundle);
    checkAdditionalConstraints();
    setStatusToAdmin();
    if (!isSessionOpenForSpecificUser(data.bundle.feedbackSession)) {
        isError = true;
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_SUBMISSIONS_NOT_OPEN, StatusMessageColor.WARNING));
        return createSpecificRedirectResult();
    }
    String userTeamForCourse = getUserTeamForCourse();
    String userSectionForCourse = getUserSectionForCourse();
    int numOfQuestionsToGet = data.bundle.questionResponseBundle.size();
    for (int questionIndx = 1; questionIndx <= numOfQuestionsToGet; questionIndx++) {
        String totalResponsesForQuestion = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-" + questionIndx);
        if (totalResponsesForQuestion == null) {
            // question has been skipped (not displayed).
            continue;
        }
        List<FeedbackResponseAttributes> responsesForQuestion = new ArrayList<>();
        String questionId = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_ID + "-" + questionIndx);
        FeedbackQuestionAttributes questionAttributes = data.bundle.getQuestionAttributes(questionId);
        if (questionAttributes == null) {
            statusToUser.add(new StatusMessage("The feedback session or questions may have changed " + "while you were submitting. Please check your responses " + "to make sure they are saved correctly.", StatusMessageColor.WARNING));
            isError = true;
            log.warning("Question not found. (deleted or invalid id passed?) id: " + questionId + " index: " + questionIndx);
            continue;
        }
        FeedbackQuestionDetails questionDetails = questionAttributes.getQuestionDetails();
        int numOfResponsesToGet = Integer.parseInt(totalResponsesForQuestion);
        Set<String> emailSet = data.bundle.getRecipientEmails(questionAttributes.getId());
        emailSet.add("");
        emailSet = SanitizationHelper.desanitizeFromHtml(emailSet);
        ArrayList<String> responsesRecipients = new ArrayList<>();
        List<String> errors = new ArrayList<>();
        for (int responseIndx = 0; responseIndx < numOfResponsesToGet; responseIndx++) {
            FeedbackResponseAttributes response = extractFeedbackResponseData(requestParameters, questionIndx, responseIndx, questionAttributes);
            if (response.feedbackQuestionType != questionAttributes.questionType) {
                errors.add(String.format(Const.StatusMessages.FEEDBACK_RESPONSES_WRONG_QUESTION_TYPE, questionIndx));
            }
            boolean isExistingResponse = response.getId() != null;
            // came from the original set of existing responses loaded on the submission page
            if (isExistingResponse && !isExistingResponseValid(response)) {
                errors.add(String.format(Const.StatusMessages.FEEDBACK_RESPONSES_INVALID_ID, questionIndx));
                continue;
            }
            responsesRecipients.add(response.recipient);
            // if the answer is not empty but the recipient is empty
            if (response.recipient.isEmpty() && !response.responseMetaData.getValue().isEmpty()) {
                errors.add(String.format(Const.StatusMessages.FEEDBACK_RESPONSES_MISSING_RECIPIENT, questionIndx));
            }
            if (response.responseMetaData.getValue().isEmpty()) {
                // deletes the response since answer is empty
                addToPendingResponses(response);
            } else {
                response.giver = questionAttributes.giverType.isTeam() ? userTeamForCourse : userEmailForCourse;
                response.giverSection = userSectionForCourse;
                responsesForQuestion.add(response);
            }
        }
        List<String> questionSpecificErrors = questionDetails.validateResponseAttributes(responsesForQuestion, data.bundle.recipientList.get(questionId).size());
        errors.addAll(questionSpecificErrors);
        if (!emailSet.containsAll(responsesRecipients)) {
            errors.add(String.format(Const.StatusMessages.FEEDBACK_RESPONSE_INVALID_RECIPIENT, questionIndx));
        }
        if (errors.isEmpty()) {
            for (FeedbackResponseAttributes response : responsesForQuestion) {
                addToPendingResponses(response);
            }
        } else {
            List<StatusMessage> errorMessages = new ArrayList<>();
            for (String error : errors) {
                errorMessages.add(new StatusMessage(error, StatusMessageColor.DANGER));
            }
            statusToUser.addAll(errorMessages);
            isError = true;
        }
    }
    saveNewReponses(responsesToSave);
    deleteResponses(responsesToDelete);
    updateResponses(responsesToUpdate);
    if (!isError) {
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, StatusMessageColor.SUCCESS));
    }
    if (isUserRespondentOfSession()) {
        appendRespondent();
    } else {
        removeRespondent();
    }
    boolean isSubmissionEmailRequested = "on".equals(getRequestParamValue(Const.ParamsNames.SEND_SUBMISSION_EMAIL));
    if (!isError && isSendSubmissionEmail && isSubmissionEmailRequested) {
        FeedbackSessionAttributes session = logic.getFeedbackSession(feedbackSessionName, courseId);
        Assumption.assertNotNull(session);
        String user = account == null ? null : account.googleId;
        String unregisteredStudentEmail = student == null ? null : student.email;
        String unregisteredStudentRegisterationKey = student == null ? null : student.key;
        StudentAttributes student = null;
        InstructorAttributes instructor = null;
        if (user != null) {
            student = logic.getStudentForGoogleId(courseId, user);
            instructor = logic.getInstructorForGoogleId(courseId, user);
        }
        if (student == null && unregisteredStudentEmail != null) {
            student = StudentAttributes.builder("", unregisteredStudentEmail, unregisteredStudentEmail).withKey(unregisteredStudentRegisterationKey).build();
        }
        Assumption.assertFalse(student == null && instructor == null);
        try {
            EmailWrapper email = instructor == null ? new EmailGenerator().generateFeedbackSubmissionConfirmationEmailForStudent(session, student, Instant.now()) : new EmailGenerator().generateFeedbackSubmissionConfirmationEmailForInstructor(session, instructor, Instant.now());
            emailSender.sendEmail(email);
        } catch (EmailSendingException e) {
            log.severe("Submission confirmation email failed to send: " + TeammatesException.toStringWithStackTrace(e));
        }
    }
    // TODO: Refactor to AjaxResult so status messages do not have to be passed by session
    return createSpecificRedirectResult();
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) FeedbackQuestionDetails(teammates.common.datatransfer.questions.FeedbackQuestionDetails) ArrayList(java.util.ArrayList) FeedbackSubmissionEditPageData(teammates.ui.pagedata.FeedbackSubmissionEditPageData) EmailSendingException(teammates.common.exception.EmailSendingException) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) StatusMessage(teammates.common.util.StatusMessage) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)

Example 70 with StatusMessage

use of teammates.common.util.StatusMessage in project teammates by TEAMMATES.

the class InstructorFeedbackRemindParticularStudentsAction method execute.

@Override
protected ActionResult execute() {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    String feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    String nextUrl = getRequestParamValue(Const.ParamsNames.NEXT_URL);
    if (nextUrl == null) {
        nextUrl = Const.ActionURIs.INSTRUCTOR_FEEDBACK_SESSIONS_PAGE;
    }
    FeedbackSessionAttributes feedbackSession = logic.getFeedbackSession(feedbackSessionName, courseId);
    gateKeeper.verifyAccessible(logic.getInstructorForGoogleId(courseId, account.googleId), feedbackSession, false, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION);
    if (!feedbackSession.isOpened()) {
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_SESSION_REMINDERSSESSIONNOTOPEN, StatusMessageColor.DANGER));
        statusToAdmin = "Reminder email could not be sent out as the feedback session is not open for submissions.";
        return createRedirectResult(nextUrl);
    }
    String[] usersToRemind = getRequestParamValues(Const.ParamsNames.SUBMISSION_REMIND_USERLIST);
    if (usersToRemind == null || usersToRemind.length == 0) {
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_SESSION_REMINDERSEMPTYRECIPIENT, StatusMessageColor.DANGER));
        return createRedirectResult(nextUrl);
    }
    taskQueuer.scheduleFeedbackSessionRemindersForParticularUsers(courseId, feedbackSessionName, usersToRemind, account.googleId);
    statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_SESSION_REMINDERSSENT, StatusMessageColor.SUCCESS));
    statusToAdmin = "Email sent out to the selected user(s): ";
    for (String user : usersToRemind) {
        statusToAdmin += "<br>" + user;
    }
    statusToAdmin += "<br>in Feedback Session <span class=\"bold\">(" + feedbackSessionName + ")</span> " + "of Course <span class=\"bold\">[" + courseId + "]</span>";
    return createRedirectResult(nextUrl);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) StatusMessage(teammates.common.util.StatusMessage)

Aggregations

StatusMessage (teammates.common.util.StatusMessage)81 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)34 InvalidParametersException (teammates.common.exception.InvalidParametersException)20 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)18 ArrayList (java.util.ArrayList)14 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)9 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)9 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)7 List (java.util.List)6 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)6 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)6 HashMap (java.util.HashMap)4 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)4 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)3 PageData (teammates.ui.pagedata.PageData)3 BlobInfo (com.google.appengine.api.blobstore.BlobInfo)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)2 BlobstoreFailureException (com.google.appengine.api.blobstore.BlobstoreFailureException)2 Text (com.google.appengine.api.datastore.Text)2 AppLogLine (com.google.appengine.api.log.AppLogLine)2