Search in sources :

Example 81 with AccountAttributes

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

the class CoursesLogic method createCourseAndInstructor.

/**
 * Creates a Course object and an Instructor object for the Course.
 */
public void createCourseAndInstructor(String instructorGoogleId, String courseId, String courseName, String courseTimeZone) throws InvalidParametersException, EntityAlreadyExistsException {
    AccountAttributes courseCreator = accountsLogic.getAccount(instructorGoogleId);
    Assumption.assertNotNull("Trying to create a course for a non-existent instructor :" + instructorGoogleId, courseCreator);
    Assumption.assertTrue("Trying to create a course for a person who doesn't have instructor privileges :" + instructorGoogleId, courseCreator.isInstructor);
    createCourse(courseId, courseName, courseTimeZone);
    /* Create the initial instructor for the course */
    InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    InstructorAttributes instructor = InstructorAttributes.builder(instructorGoogleId, courseId, courseCreator.name, courseCreator.email).withPrivileges(privileges).build();
    try {
        instructorsLogic.createInstructor(instructor);
    } catch (EntityAlreadyExistsException | InvalidParametersException e) {
        // roll back the transaction
        coursesDb.deleteCourse(courseId);
        String errorMessage = "Unexpected exception while trying to create instructor for a new course " + System.lineSeparator() + instructor.toString() + System.lineSeparator() + TeammatesException.toStringWithStackTrace(e);
        Assumption.fail(errorMessage);
    }
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 82 with AccountAttributes

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

the class AdminSearchPageAction method putInstructorInstituteIntoMap.

private AdminSearchPageData putInstructorInstituteIntoMap(List<InstructorAttributes> instructors, AdminSearchPageData data) {
    for (InstructorAttributes instructor : instructors) {
        if (tempCourseIdToInstituteMap.get(instructor.courseId) != null) {
            data.instructorInstituteMap.put(instructor.getIdentificationString(), tempCourseIdToInstituteMap.get(instructor.courseId));
            continue;
        }
        String googleId = findAvailableInstructorGoogleIdForCourse(instructor.courseId);
        AccountAttributes account = logic.getAccount(googleId);
        if (account == null) {
            continue;
        }
        String institute = account.institute.trim().isEmpty() ? "None" : account.institute;
        tempCourseIdToInstituteMap.put(instructor.courseId, institute);
        data.instructorInstituteMap.put(instructor.getIdentificationString(), institute);
    }
    return data;
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 83 with AccountAttributes

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

the class AdminSessionsPageAction method createAdminSessionPageResult.

private ActionResult createAdminSessionPageResult(List<FeedbackSessionAttributes> allOpenFeedbackSessionsList) {
    HashMap<String, List<FeedbackSessionAttributes>> map = new HashMap<>();
    this.totalOngoingSessions = allOpenFeedbackSessionsList.size();
    this.totalOpenStatusSessions = getTotalNumOfOpenStatusSession(allOpenFeedbackSessionsList);
    this.totalClosedStatusSessions = getTotalNumOfCloseStatusSession(allOpenFeedbackSessionsList);
    this.totalWaitToOpenStatusSessions = getTotalNumOfWaitToOpenStatusSession(allOpenFeedbackSessionsList);
    for (FeedbackSessionAttributes fs : allOpenFeedbackSessionsList) {
        List<InstructorAttributes> instructors = logic.getInstructorsForCourse(fs.getCourseId());
        if (instructors.isEmpty()) {
            putIntoUnknownList(map, fs);
        } else {
            AccountAttributes account = getRegisteredInstructorAccountFromInstructors(instructors);
            if (account == null) {
                putIntoUnknownList(map, fs);
                continue;
            }
            if (map.get(account.institute) == null) {
                List<FeedbackSessionAttributes> newList = new ArrayList<>();
                newList.add(fs);
                map.put(account.institute, newList);
            } else {
                map.get(account.institute).add(fs);
            }
        }
    }
    this.map = map;
    this.totalInstitutes = getTotalInstitutes(map);
    statusToAdmin = "Admin Sessions Page Load<br>" + "<span class=\"bold\">Total Ongoing Sessions:</span> " + this.totalOngoingSessions + "<span class=\"bold\">Total Opened Sessions:</span> " + this.totalOpenStatusSessions;
    constructSessionToInstructorIdMap();
    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);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 84 with AccountAttributes

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

the class InstructorCourseJoinEmailWorkerAction method execute.

@Override
public void execute() {
    String inviterId = getRequestParamValue(ParamsNames.INVITER_ID);
    Assumption.assertPostParamNotNull(ParamsNames.INVITER_ID, inviterId);
    String courseId = getRequestParamValue(ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(ParamsNames.COURSE_ID, courseId);
    String instructorEmail = getRequestParamValue(ParamsNames.INSTRUCTOR_EMAIL);
    Assumption.assertPostParamNotNull(ParamsNames.INSTRUCTOR_EMAIL, instructorEmail);
    AccountAttributes inviter = logic.getAccount(inviterId);
    Assumption.assertNotNull(inviter);
    CourseAttributes course = logic.getCourse(courseId);
    Assumption.assertNotNull(course);
    InstructorAttributes instructor = logic.getInstructorForEmail(courseId, instructorEmail);
    Assumption.assertNotNull(instructor);
    EmailWrapper email = new EmailGenerator().generateInstructorCourseJoinEmail(inviter, instructor, course);
    try {
        emailSender.sendEmail(email);
    } catch (Exception e) {
        Assumption.fail("Unexpected error while sending email" + TeammatesException.toStringWithStackTrace(e));
    }
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) TeammatesException(teammates.common.exception.TeammatesException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper)

Aggregations

AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)84 Test (org.testng.annotations.Test)53 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)28 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)16 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)15 ArrayList (java.util.ArrayList)13 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)11 HashMap (java.util.HashMap)7 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)6 InvalidParametersException (teammates.common.exception.InvalidParametersException)6 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)5 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)4 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)4 EmailWrapper (teammates.common.util.EmailWrapper)4 RedirectResult (teammates.ui.controller.RedirectResult)4 List (java.util.List)3 EmailGenerator (teammates.logic.api.EmailGenerator)3 AccountsDb (teammates.storage.api.AccountsDb)3 Account (teammates.storage.entity.Account)3 ShowPageResult (teammates.ui.controller.ShowPageResult)3