Search in sources :

Example 6 with DuplicateCourseStudentException

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.");
    }
}
Also used : DuplicateCourseStudentException(fi.otavanopisto.pyramus.exception.DuplicateCourseStudentException) InvalidScriptException(fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) BigDecimal(java.math.BigDecimal) Date(java.util.Date) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) Defaults(fi.otavanopisto.pyramus.domainmodel.base.Defaults) Currency(java.util.Currency) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) Room(fi.otavanopisto.pyramus.domainmodel.accommodation.Room)

Example 7 with DuplicateCourseStudentException

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;
}
Also used : EntityManager(javax.persistence.EntityManager) DuplicateCourseStudentException(fi.otavanopisto.pyramus.exception.DuplicateCourseStudentException) CourseStudentUpdatedEvent(fi.otavanopisto.pyramus.events.CourseStudentUpdatedEvent) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)

Aggregations

DuplicateCourseStudentException (fi.otavanopisto.pyramus.exception.DuplicateCourseStudentException)7 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)6 Room (fi.otavanopisto.pyramus.domainmodel.accommodation.Room)5 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)5 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)5 BigDecimal (java.math.BigDecimal)5 Currency (java.util.Currency)5 CourseDAO (fi.otavanopisto.pyramus.dao.courses.CourseDAO)4 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)4 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)4 Date (java.util.Date)4 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)3 DefaultsDAO (fi.otavanopisto.pyramus.dao.base.DefaultsDAO)3 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)3 TagDAO (fi.otavanopisto.pyramus.dao.base.TagDAO)3 ModuleDAO (fi.otavanopisto.pyramus.dao.modules.ModuleDAO)3 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)3 CourseEducationSubtypeDAO (fi.otavanopisto.pyramus.dao.base.CourseEducationSubtypeDAO)2 CourseEducationTypeDAO (fi.otavanopisto.pyramus.dao.base.CourseEducationTypeDAO)2 CurriculumDAO (fi.otavanopisto.pyramus.dao.base.CurriculumDAO)2