Search in sources :

Example 1 with StatusMessage

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

the class AdminInstructorAccountAddAction method execute.

@Override
protected ActionResult execute() {
    gateKeeper.verifyAdminPrivileges(account);
    AdminHomePageData data = new AdminHomePageData(account, sessionToken);
    data.instructorName = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_NAME).trim();
    data.instructorEmail = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_EMAIL).trim();
    data.instructorInstitution = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_INSTITUTION).trim();
    data.isInstructorAddingResultForAjax = true;
    data.statusForAjax = "";
    data.instructorName = data.instructorName.trim();
    data.instructorEmail = data.instructorEmail.trim();
    data.instructorInstitution = data.instructorInstitution.trim();
    try {
        logic.verifyInputForAdminHomePage(data.instructorName, data.instructorInstitution, data.instructorEmail);
    } catch (InvalidParametersException e) {
        data.statusForAjax = e.getMessage().replace(System.lineSeparator(), Const.HTML_BR_TAG);
        data.isInstructorAddingResultForAjax = false;
        statusToUser.add(new StatusMessage(data.statusForAjax, StatusMessageColor.DANGER));
        return createAjaxResult(data);
    }
    String courseId = null;
    try {
        courseId = importDemoData(data);
    } catch (Exception e) {
        String retryUrl = Const.ActionURIs.ADMIN_INSTRUCTORACCOUNT_ADD;
        retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.INSTRUCTOR_NAME, data.instructorName);
        retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.INSTRUCTOR_EMAIL, data.instructorEmail);
        retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.INSTRUCTOR_INSTITUTION, data.instructorInstitution);
        retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.SESSION_TOKEN, data.getSessionToken());
        StringBuilder errorMessage = new StringBuilder(100);
        String retryLink = "<a href=" + retryUrl + ">Exception in Importing Data, Retry</a>";
        errorMessage.append(retryLink);
        statusToUser.add(new StatusMessage(errorMessage.toString(), StatusMessageColor.DANGER));
        String message = "<span class=\"text-danger\">Servlet Action failure in AdminInstructorAccountAddAction" + "<br>" + e.getClass() + ": " + TeammatesException.toStringWithStackTrace(e) + "<br></span>";
        errorMessage.append("<br>").append(message);
        statusToUser.add(new StatusMessage("<br>" + message, StatusMessageColor.DANGER));
        statusToAdmin = message;
        data.isInstructorAddingResultForAjax = false;
        data.statusForAjax = errorMessage.toString();
        return createAjaxResult(data);
    }
    List<InstructorAttributes> instructorList = logic.getInstructorsForCourse(courseId);
    String joinLink = Config.getAppUrl(Const.ActionURIs.INSTRUCTOR_COURSE_JOIN).withRegistrationKey(StringHelper.encrypt(instructorList.get(0).key)).withInstructorInstitution(data.instructorInstitution).toAbsoluteString();
    EmailWrapper email = new EmailGenerator().generateNewInstructorAccountJoinEmail(instructorList.get(0).email, data.instructorName, joinLink);
    try {
        emailSender.sendEmail(email);
    } catch (EmailSendingException e) {
        log.severe("Instructor welcome email failed to send: " + TeammatesException.toStringWithStackTrace(e));
    }
    data.statusForAjax = "Instructor " + SanitizationHelper.sanitizeForHtml(data.instructorName) + " has been successfully created " + "<a href=" + joinLink + ">" + Const.JOIN_LINK + "</a>";
    statusToUser.add(new StatusMessage(data.statusForAjax, StatusMessageColor.SUCCESS));
    statusToAdmin = "A New Instructor <span class=\"bold\">" + SanitizationHelper.sanitizeForHtmlTag(data.instructorName) + "</span> has been created.<br>" + "<span class=\"bold\">Id: </span>" + "ID will be assigned when the verification link was clicked and confirmed" + "<br>" + "<span class=\"bold\">Email: </span>" + SanitizationHelper.sanitizeForHtmlTag(data.instructorEmail) + "<span class=\"bold\">Institution: </span>" + SanitizationHelper.sanitizeForHtmlTag(data.instructorInstitution);
    return createAjaxResult(data);
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) AdminHomePageData(teammates.ui.pagedata.AdminHomePageData) EmailSendingException(teammates.common.exception.EmailSendingException) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) EmailSendingException(teammates.common.exception.EmailSendingException) TeammatesException(teammates.common.exception.TeammatesException) InvalidParametersException(teammates.common.exception.InvalidParametersException) StatusMessage(teammates.common.util.StatusMessage) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper)

Example 2 with StatusMessage

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

the class AdminSearchPageAction method execute.

@Override
protected ActionResult execute() {
    gateKeeper.verifyAdminPrivileges(account);
    String searchKey = getRequestParamValue(Const.ParamsNames.ADMIN_SEARCH_KEY);
    String searchButtonHit = getRequestParamValue(Const.ParamsNames.ADMIN_SEARCH_BUTTON_HIT);
    AdminSearchPageData data = new AdminSearchPageData(account, sessionToken);
    if (searchKey == null || searchKey.trim().isEmpty()) {
        if (searchButtonHit == null) {
            statusToAdmin = "AdminSearchPage Page Load";
        } else {
            statusToUser.add(new StatusMessage("Search key cannot be empty", StatusMessageColor.WARNING));
            statusToAdmin = "Invalid Search: Search key cannot be empty";
            isError = true;
        }
        return createShowPageResult(Const.ViewURIs.ADMIN_SEARCH, data);
    }
    data.searchKey = SanitizationHelper.sanitizeForHtml(searchKey);
    data.studentResultBundle = logic.searchStudentsInWholeSystem(searchKey);
    data = putFeedbackSessionLinkIntoMap(data.studentResultBundle.studentList, data);
    data = putStudentHomePageLinkIntoMap(data.studentResultBundle.studentList, data);
    data = putStudentRecordsPageLinkIntoMap(data.studentResultBundle.studentList, data);
    data = putStudentInstituteIntoMap(data.studentResultBundle.studentList, data);
    data.instructorResultBundle = logic.searchInstructorsInWholeSystem(searchKey);
    data = putInstructorInstituteIntoMap(data.instructorResultBundle.instructorList, data);
    data = putInstructorHomePageLinkIntoMap(data.instructorResultBundle.instructorList, data);
    data = putInstructorCourseJoinLinkIntoMap(data.instructorResultBundle.instructorList, data);
    data = putCourseNameIntoMap(data.studentResultBundle.studentList, data.instructorResultBundle.instructorList, data);
    int numOfResults = data.studentResultBundle.numberOfResults + data.instructorResultBundle.numberOfResults;
    if (numOfResults > 0) {
        statusToUser.add(new StatusMessage("Total results found: " + numOfResults, StatusMessageColor.INFO));
        statusToAdmin = "Search Key: " + data.searchKey + "<br>" + "Total results found: " + numOfResults;
        isError = false;
    } else {
        statusToUser.add(new StatusMessage("No result found, please try again", StatusMessageColor.WARNING));
        statusToAdmin = "Search Key: " + data.searchKey + "<br>" + "No result found";
        isError = true;
    }
    data.init();
    return createShowPageResult(Const.ViewURIs.ADMIN_SEARCH, data);
}
Also used : AdminSearchPageData(teammates.ui.pagedata.AdminSearchPageData) StatusMessage(teammates.common.util.StatusMessage)

Example 3 with StatusMessage

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

the class AdminSessionsPageAction method createShowPageResultIfNoOngoingSession.

private ActionResult createShowPageResultIfNoOngoingSession(List<FeedbackSessionAttributes> allOpenFeedbackSessionsList) {
    if (allOpenFeedbackSessionsList.isEmpty()) {
        isError = false;
        statusToUser.add(new StatusMessage("Currently No Ongoing Sessions", StatusMessageColor.WARNING));
        statusToAdmin = "Admin Sessions Page Load<br>" + "<span class=\"bold\"> No Ongoing Sessions</span>";
        this.map = new HashMap<>();
        this.totalOngoingSessions = 0;
        this.totalOpenStatusSessions = 0;
        this.totalClosedStatusSessions = 0;
        this.totalWaitToOpenStatusSessions = 0;
        this.totalInstitutes = 0;
        data.init(this.map, this.sessionToInstructorIdMap, this.totalOngoingSessions, this.totalOpenStatusSessions, this.totalClosedStatusSessions, this.totalWaitToOpenStatusSessions, this.totalInstitutes, this.rangeStart, this.rangeEnd, this.zone, this.isShowAll);
        return createShowPageResult(Const.ViewURIs.ADMIN_SESSIONS, data);
    }
    return null;
}
Also used : StatusMessage(teammates.common.util.StatusMessage)

Example 4 with StatusMessage

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

the class AdminStudentGoogleIdResetAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    gateKeeper.verifyAdminPrivileges(account);
    String studentEmail = getRequestParamValue(Const.ParamsNames.STUDENT_EMAIL);
    String studentCourseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    String wrongGoogleId = getRequestParamValue(Const.ParamsNames.STUDENT_ID);
    AdminStudentGoogleIdResetPageData data = new AdminStudentGoogleIdResetPageData(account, sessionToken);
    if (studentEmail != null && studentCourseId != null) {
        try {
            logic.resetStudentGoogleId(studentEmail, studentCourseId);
            taskQueuer.scheduleCourseRegistrationInviteToStudent(studentCourseId, studentEmail, true);
        } catch (InvalidParametersException e) {
            statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_GOOGLEID_RESET_FAIL, StatusMessageColor.DANGER));
            statusToAdmin = Const.StatusMessages.STUDENT_GOOGLEID_RESET_FAIL + "<br>" + "Email: " + studentEmail + "<br>" + "CourseId: " + studentCourseId + "<br>" + "Failed with error<br>" + e.getMessage();
            isError = true;
        }
        StudentAttributes updatedStudent = logic.getStudentForEmail(studentCourseId, studentEmail);
        if (updatedStudent.googleId == null || updatedStudent.googleId.isEmpty()) {
            statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_GOOGLEID_RESET, StatusMessageColor.SUCCESS));
            statusToUser.add(new StatusMessage("Email : " + studentEmail, StatusMessageColor.SUCCESS));
            statusToUser.add(new StatusMessage("CourseId : " + studentCourseId, StatusMessageColor.SUCCESS));
            statusToAdmin = Const.StatusMessages.STUDENT_GOOGLEID_RESET + "<br>" + "Email: " + studentEmail + "<br>" + "CourseId: " + studentCourseId;
            data.statusForAjax = Const.StatusMessages.STUDENT_GOOGLEID_RESET + "<br>" + "Email : " + studentEmail + "<br>" + "CourseId : " + studentCourseId;
            data.isGoogleIdReset = true;
            deleteAccountIfNeeded(wrongGoogleId);
        } else {
            data.isGoogleIdReset = false;
            statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_GOOGLEID_RESET_FAIL, StatusMessageColor.DANGER));
            statusToAdmin = Const.StatusMessages.STUDENT_GOOGLEID_RESET_FAIL + "<br>" + "Email: " + studentEmail + "<br>" + "CourseId: " + studentCourseId + "<br>";
            data.statusForAjax = Const.StatusMessages.STUDENT_GOOGLEID_RESET_FAIL + "<br>" + "Email : " + studentEmail + "<br>" + "CourseId : " + studentCourseId;
        }
        isError = false;
        return createAjaxResult(data);
    }
    isError = true;
    return createAjaxResult(data);
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) AdminStudentGoogleIdResetPageData(teammates.ui.pagedata.AdminStudentGoogleIdResetPageData) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 5 with StatusMessage

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

the class ControllerServlet method doPost.

@Override
// used as fallback
@SuppressWarnings("PMD.AvoidCatchingThrowable")
public final void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    UserType userType = new GateKeeper().getCurrentUser();
    String url = HttpRequestHelper.getRequestedUrl(req);
    Map<String, String[]> params = HttpRequestHelper.getParameterMap(req);
    try {
        /* We are using the Template Method Design Pattern here.
             * This method contains the high level logic of the request processing.
             * Concrete details of the processing steps are to be implemented by child
             * classes, based on request-specific needs.
             */
        long startTime = System.currentTimeMillis();
        log.info("Request received : [" + req.getMethod() + "] " + req.getRequestURL().toString() + ":" + HttpRequestHelper.printRequestParameters(req));
        log.info("User agent : " + req.getHeader("User-Agent"));
        Action c = new ActionFactory().getAction(req);
        if (c.isValidUser()) {
            ActionResult actionResult = c.executeAndPostProcess();
            actionResult.writeSessionTokenToCookieIfRequired(req, resp);
            actionResult.send(req, resp);
        } else {
            resp.sendRedirect(c.getAuthenticationRedirectUrl());
        }
        long timeTaken = System.currentTimeMillis() - startTime;
        // This is the log message that is used to generate the 'activity log' for the admin.
        log.info(c.getLogMessage() + "|||" + timeTaken);
    } catch (PageNotFoundException e) {
        log.warning(new LogMessageGenerator().generateActionFailureLogMessage(url, params, e, userType));
        cleanUpStatusMessageInSession(req);
        resp.sendRedirect(appendParamsToErrorPageUrl(Const.ViewURIs.ACTION_NOT_FOUND_PAGE, params, url));
    } catch (EntityNotFoundException e) {
        log.warning(new LogMessageGenerator().generateActionFailureLogMessage(url, params, e, userType));
        cleanUpStatusMessageInSession(req);
        resp.sendRedirect(appendParamsToErrorPageUrl(Const.ViewURIs.ENTITY_NOT_FOUND_PAGE, params, url));
    } catch (FeedbackSessionNotVisibleException e) {
        log.warning(new LogMessageGenerator().generateActionFailureLogMessage(url, params, e, userType));
        cleanUpStatusMessageInSession(req);
        req.getSession().setAttribute(Const.ParamsNames.FEEDBACK_SESSION_NOT_VISIBLE, e.getStartTimeString());
        resp.sendRedirect(appendParamsToErrorPageUrl(Const.ViewURIs.FEEDBACK_SESSION_NOT_VISIBLE, params, url));
    } catch (InvalidOriginException e) {
        log.warning(new LogMessageGenerator().generateActionFailureLogMessage(url, params, e, userType));
        cleanUpStatusMessageInSession(req);
        resp.sendRedirect(appendParamsToErrorPageUrl(Const.ViewURIs.INVALID_ORIGIN, params, url));
    } catch (UnauthorizedAccessException e) {
        log.warning(new LogMessageGenerator().generateActionFailureLogMessage(url, params, e, userType));
        cleanUpStatusMessageInSession(req);
        resp.sendRedirect(appendParamsToErrorPageUrl(Const.ViewURIs.UNAUTHORIZED, params, url));
    } catch (DeadlineExceededException | DatastoreTimeoutException e) {
        /*This exception may not be caught because GAE kills
              the request soon after throwing it. In that case, the error
              message in the log will be emailed to the admin by a separate
              cron job.*/
        cleanUpStatusMessageInSession(req);
        log.severe("Deadline exceeded exception caught by ControllerServlet : " + TeammatesException.toStringWithStackTrace(e));
        resp.sendRedirect(appendParamsToErrorPageUrl(Const.ViewURIs.DEADLINE_EXCEEDED_ERROR_PAGE, params, url));
    } catch (InvalidPostParametersException e) {
        String requestUrl = req.getRequestURL().toString();
        log.info(e.getMessage());
        cleanUpStatusMessageInSession(req);
        List<StatusMessage> statusMessagesToUser = new ArrayList<>();
        statusMessagesToUser.add(new StatusMessage(Const.StatusMessages.NULL_POST_PARAMETER_MESSAGE, StatusMessageColor.WARNING));
        req.getSession().setAttribute(Const.ParamsNames.STATUS_MESSAGES_LIST, statusMessagesToUser);
        if (requestUrl.contains("/instructor")) {
            resp.sendRedirect(Const.ActionURIs.INSTRUCTOR_HOME_PAGE);
        } else if (requestUrl.contains("/student")) {
            resp.sendRedirect(Const.ActionURIs.STUDENT_HOME_PAGE);
        } else if (requestUrl.contains("/admin")) {
            resp.sendRedirect(Const.ActionURIs.ADMIN_HOME_PAGE);
        } else {
            cleanUpStatusMessageInSession(req);
            resp.sendRedirect(appendParamsToErrorPageUrl(Const.ViewURIs.ERROR_PAGE, params, url));
        }
    } catch (Throwable t) {
        /* Log only stack trace to prevent delay in termination of request
             * which can result in GAE shutting down the instance.
             * Note that severe logs are sent by email automatically in the cron job auto/compileLogs.
             */
        log.severe("Unexpected exception caught by ControllerServlet : " + TeammatesException.toStringWithStackTrace(t));
        cleanUpStatusMessageInSession(req);
        resp.sendRedirect(appendParamsToErrorPageUrl(Const.ViewURIs.ERROR_PAGE, params, url));
    }
}
Also used : InvalidPostParametersException(teammates.common.exception.InvalidPostParametersException) LogMessageGenerator(teammates.common.util.LogMessageGenerator) DeadlineExceededException(com.google.apphosting.api.DeadlineExceededException) EntityNotFoundException(teammates.common.exception.EntityNotFoundException) DatastoreTimeoutException(com.google.appengine.api.datastore.DatastoreTimeoutException) StatusMessage(teammates.common.util.StatusMessage) PageNotFoundException(teammates.common.exception.PageNotFoundException) FeedbackSessionNotVisibleException(teammates.common.exception.FeedbackSessionNotVisibleException) InvalidOriginException(teammates.common.exception.InvalidOriginException) UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException) GateKeeper(teammates.logic.api.GateKeeper) ArrayList(java.util.ArrayList) List(java.util.List) UserType(teammates.common.datatransfer.UserType)

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