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;
}
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();
}
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);
}
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);
}
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;
}
Aggregations