use of fi.otavanopisto.pyramus.exception.DuplicateCourseStudentException in project pyramus by otavanopisto.
the class CourseStudentAPI method create.
public Long create(Long courseId, Long studentId) throws InvalidScriptException {
CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
Defaults defaults = DAOFactory.getInstance().getDefaultsDAO().getDefaults();
Course course = courseDAO.findById(courseId);
if (course == null) {
throw new InvalidScriptException("Course #" + courseId + " not found.");
}
Student student = studentDAO.findById(studentId);
if (student == null) {
throw new InvalidScriptException("Student #" + studentId + " not found.");
}
Room room = null;
BigDecimal lodgingFee = null;
Currency lodgingFeeCurrency = null;
BigDecimal reservationFee = null;
Currency reservationFeeCurrency = null;
String organization = null;
String additionalInfo = null;
try {
return courseStudentDAO.create(course, student, defaults.getInitialCourseEnrolmentType(), defaults.getInitialCourseParticipationType(), new Date(), false, CourseOptionality.OPTIONAL, null, organization, additionalInfo, room, lodgingFee, lodgingFeeCurrency, reservationFee, reservationFeeCurrency, Boolean.FALSE).getId();
} catch (DuplicateCourseStudentException dcse) {
throw new InvalidScriptException("Student #" + studentId + " has an already existing coursestudent.");
}
}
use of fi.otavanopisto.pyramus.exception.DuplicateCourseStudentException in project pyramus by otavanopisto.
the class CourseStudentDAO method update.
/**
* Updates a course student to the database.
*
* @param courseStudent The course student to be updated
* @param courseEnrolmentType Student enrolment type
* @param participationType Student participation type
* @param enrolmentDate Student enrolment date
* @param optionality
* @throws DuplicateCourseStudentException
*/
public CourseStudent update(CourseStudent courseStudent, Student student, CourseEnrolmentType courseEnrolmentType, CourseParticipationType participationType, Date enrolmentDate, Boolean lodging, CourseOptionality optionality) throws DuplicateCourseStudentException {
EntityManager entityManager = getEntityManager();
List<CourseStudent> courseStudents = listByCourseAndStudent(courseStudent.getCourse(), student);
if (!courseStudents.isEmpty()) {
for (CourseStudent courseStudent2 : courseStudents) {
if (courseStudent2.getId() != courseStudent.getId())
throw new DuplicateCourseStudentException();
}
}
courseStudent.setStudent(student);
courseStudent.setCourseEnrolmentType(courseEnrolmentType);
courseStudent.setEnrolmentTime(enrolmentDate);
courseStudent.setParticipationType(participationType);
courseStudent.setLodging(lodging);
courseStudent.setOptionality(optionality);
entityManager.persist(courseStudent);
courseStudentUpdatedEvent.fire(new CourseStudentUpdatedEvent(courseStudent.getId(), courseStudent.getCourse().getId(), courseStudent.getStudent().getId()));
return courseStudent;
}
Aggregations