Search in sources :

Example 91 with CourseAttributes

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

the class AccountsLogic method getCourseInstitute.

public String getCourseInstitute(String courseId) {
    CourseAttributes cd = coursesLogic.getCourse(courseId);
    Assumption.assertNotNull("Trying to getCourseInstitute for inexistent course with id " + courseId, cd);
    List<InstructorAttributes> instructorList = instructorsLogic.getInstructorsForCourse(cd.getId());
    Assumption.assertTrue("Course has no instructors: " + cd.getId(), !instructorList.isEmpty());
    // Retrieve institute field from one of the instructors of the course
    String institute = "";
    for (int i = 0; i < instructorList.size(); i++) {
        String instructorGoogleId = instructorList.get(i).googleId;
        if (instructorGoogleId == null) {
            continue;
        }
        AccountAttributes instructorAcc = accountsDb.getAccount(instructorGoogleId);
        if (instructorAcc != null) {
            institute = instructorAcc.institute;
            break;
        }
    }
    Assumption.assertNotEmpty("No institute found for the course", institute);
    return institute;
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 92 with CourseAttributes

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

the class CoursesLogic method validateAndCreateCourseAttributes.

/**
 * Checks that {@code courseTimeZone} is valid and then returns a {@link CourseAttributes}.
 * Field validation is usually done in {@link CoursesDb} by calling {@link CourseAttributes#getInvalidityInfo()}.
 * However, a {@link CourseAttributes} cannot be created with an invalid time zone string.
 * Hence, validation of this field is carried out here.
 *
 * @throws InvalidParametersException containing error messages for all fields if {@code courseTimeZone} is invalid
 */
private CourseAttributes validateAndCreateCourseAttributes(String courseId, String courseName, String courseTimeZone) throws InvalidParametersException {
    // Imitate `CourseAttributes.getInvalidityInfo`
    FieldValidator validator = new FieldValidator();
    String timeZoneErrorMessage = validator.getInvalidityInfoForTimeZone(courseTimeZone);
    if (!timeZoneErrorMessage.isEmpty()) {
        // Leave validation of other fields to `CourseAttributes.getInvalidityInfo`
        CourseAttributes dummyCourse = CourseAttributes.builder(courseId, courseName, Const.DEFAULT_TIME_ZONE).build();
        List<String> errors = dummyCourse.getInvalidityInfo();
        errors.add(timeZoneErrorMessage);
        // Imitate exception throwing in `CoursesDb`
        throw new InvalidParametersException(errors);
    }
    // If time zone field is valid, leave validation  of other fields to `CoursesDb` like usual
    return CourseAttributes.builder(courseId, courseName, ZoneId.of(courseTimeZone)).build();
}
Also used : FieldValidator(teammates.common.util.FieldValidator) InvalidParametersException(teammates.common.exception.InvalidParametersException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Example 93 with CourseAttributes

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

the class CoursesLogic method createCourse.

public void createCourse(String courseId, String courseName, String courseTimeZone) throws InvalidParametersException, EntityAlreadyExistsException {
    CourseAttributes courseToAdd = validateAndCreateCourseAttributes(courseId, courseName, courseTimeZone);
    coursesDb.createEntity(courseToAdd);
}
Also used : CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Example 94 with CourseAttributes

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

the class CoursesLogic method updateCourse.

/**
 * Updates the course details.
 * @param courseId Id of the course to update
 * @param courseName new name of the course
 * @param courseTimeZone new time zone of the course
 */
public void updateCourse(String courseId, String courseName, String courseTimeZone) throws InvalidParametersException, EntityDoesNotExistException {
    CourseAttributes newCourse = validateAndCreateCourseAttributes(courseId, courseName, courseTimeZone);
    CourseAttributes oldCourse = coursesDb.getCourse(newCourse.getId());
    if (oldCourse == null) {
        throw new EntityDoesNotExistException("Trying to update a course that does not exist.");
    }
    coursesDb.updateCourse(newCourse);
}
Also used : CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 95 with CourseAttributes

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

the class CoursesLogic method getCourseSummariesForInstructor.

/**
 * Returns course summaries for instructors.<br>
 *
 * @return Map with courseId as key, and CourseDetailsBundle as value.
 *         Does not include details within the course, such as feedback sessions.
 */
public Map<String, CourseDetailsBundle> getCourseSummariesForInstructor(List<InstructorAttributes> instructorAttributesList) {
    HashMap<String, CourseDetailsBundle> courseSummaryList = new HashMap<>();
    List<String> courseIdList = new ArrayList<>();
    for (InstructorAttributes instructor : instructorAttributesList) {
        courseIdList.add(instructor.courseId);
    }
    List<CourseAttributes> courseList = coursesDb.getCourses(courseIdList);
    // Check that all courseIds queried returned a course.
    if (courseIdList.size() > courseList.size()) {
        for (CourseAttributes ca : courseList) {
            courseIdList.remove(ca.getId());
        }
        log.severe("Course(s) was deleted but the instructor still exists: " + System.lineSeparator() + courseIdList.toString());
    }
    for (CourseAttributes ca : courseList) {
        courseSummaryList.put(ca.getId(), getCourseSummary(ca));
    }
    return courseSummaryList;
}
Also used : CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Aggregations

CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)106 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)48 Test (org.testng.annotations.Test)40 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)33 ArrayList (java.util.ArrayList)31 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)19 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)16 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)15 EmailWrapper (teammates.common.util.EmailWrapper)15 HashMap (java.util.HashMap)12 InvalidParametersException (teammates.common.exception.InvalidParametersException)10 EmailGenerator (teammates.logic.api.EmailGenerator)10 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)8 StatusMessage (teammates.common.util.StatusMessage)6 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)5 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)4 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)4 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)4 InstructorCoursesPageData (teammates.ui.pagedata.InstructorCoursesPageData)4 InstructorFeedbackSessionsPageData (teammates.ui.pagedata.InstructorFeedbackSessionsPageData)4