Search in sources :

Example 11 with Class

use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.

the class ProjectDaoImpl method updateProjectById.

@Override
public Project updateProjectById(long id, Project newProject, long classId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Project project = session.get(Project.class, id);
        Class _class = session.get(Class.class, classId);
        Term term = session.get(Term.class, termId);
        if (newProject == null)
            newProject = new Project();
        if (project == null)
            throw new GradingFactorDaoException("Project with id : " + id + " does not exist");
        if (_class == null && classId != 0)
            throw new GradingFactorDaoException("Project's class with id : " + classId + " does not exist");
        if (term == null && termId > 0)
            throw new GradingFactorDaoException("Project's term with id : " + termId + " does not exist");
        if (!(newProject.getTitle() != null ? newProject.getTitle() : "").trim().isEmpty())
            project.setTitle(newProject.getTitle());
        if (!(newProject.getDate() != null ? newProject.getDate() : "").trim().isEmpty())
            project.setDate(newProject.getDate());
        if (classId > 0) {
            if (classId == (project.get_class() != null ? project.get_class().getId() : 0))
                throw new GradingFactorDaoException("Project's  class with id : " + classId + " already exist");
            project.set_class(_class);
        }
        if (termId > 0) {
            if (termId != (project.getTerm() != null ? project.getTerm().getId() : 0))
                project.setTerm(term);
        }
        session.getTransaction().commit();
        session.close();
        return project;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Class(com.remswork.project.alice.model.Class) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 12 with Class

use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.

the class AttendanceDaoImpl method updateAttendanceById.

@Override
public Attendance updateAttendanceById(long id, Attendance newAttendance, long classId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Attendance attendance = session.get(Attendance.class, id);
        Class _class = session.get(Class.class, classId);
        if (newAttendance == null)
            newAttendance = new Attendance();
        if (attendance == null)
            throw new GradingFactorDaoException("Attendance with id : " + id + " does not exist");
        if (_class == null && classId != 0)
            throw new GradingFactorDaoException("Attendance's class with id : " + classId + " does not exist");
        if (!(newAttendance.getTitle() != null ? newAttendance.getTitle() : "").trim().isEmpty())
            attendance.setTitle(newAttendance.getTitle());
        if (!(newAttendance.getDate() != null ? newAttendance.getDate() : "").trim().isEmpty())
            attendance.setDate(newAttendance.getDate());
        if (classId > 0) {
            if (classId == (attendance.get_class() != null ? attendance.get_class().getId() : 0))
                throw new GradingFactorDaoException("Attendance's  class with id : " + classId + " already exist");
            attendance.set_class(_class);
        }
        session.getTransaction().commit();
        session.close();
        return attendance;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Class(com.remswork.project.alice.model.Class) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 13 with Class

use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.

the class ClassDaoImpl method getClassById.

@Override
public Class getClassById(long id) throws ClassException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Class _class = session.get(Class.class, id);
        if (_class == null)
            throw new ClassDaoException("Class with id : " + id + " does not exist");
        session.getTransaction().commit();
        session.close();
        return _class;
    } catch (ClassDaoException e) {
        session.close();
        throw new ClassException(e.getMessage());
    }
}
Also used : ClassDaoException(com.remswork.project.alice.dao.exception.ClassDaoException) Class(com.remswork.project.alice.model.Class) Session(org.hibernate.Session)

Example 14 with Class

use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.

the class ClassDaoImpl method updateClassById.

@Override
public Class updateClassById(long id, Class newClass, long teacherId, long subjectId, long sectionId) throws ClassException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Class _class = session.get(Class.class, id);
        if (_class == null)
            throw new ClassDaoException("Class with id : " + id + " does not exist");
        if (teacherId != 0) {
            Teacher teacher = teacherDao.getTeacherById(teacherId);
            if ((_class.getTeacher() != null ? _class.getTeacher().getId() : 0) == teacher.getId())
                throw new ClassDaoException("Can't update class's teacher with same teacher");
            _class.setTeacher(teacher);
        }
        if (subjectId != 0) {
            Subject subject = subjectDao.getSubjectById(subjectId);
            if ((_class.getSubject() != null ? _class.getSubject().getId() : 0) == subject.getId())
                throw new ClassDaoException("Can't update class's subject with same subject");
            _class.setSubject(subject);
        }
        if (sectionId != 0) {
            Section section = sectionDao.getSectionById(sectionId);
            if ((_class.getSection() != null ? _class.getSection().getId() : 0) == section.getId())
                throw new ClassDaoException("Can't update class's section with same section");
            _class.setSection(section);
        }
        _class = (Class) session.merge(_class);
        session.getTransaction().commit();
        session.close();
        return _class;
    } catch (ClassDaoException | TeacherException | SubjectException | SectionException e) {
        session.close();
        throw new ClassException(e.getMessage());
    }
}
Also used : ClassDaoException(com.remswork.project.alice.dao.exception.ClassDaoException) Class(com.remswork.project.alice.model.Class) Session(org.hibernate.Session)

Example 15 with Class

use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.

the class ClassDaoImpl method deleteScheduleById.

@Override
public Schedule deleteScheduleById(long classId, long id) throws ClassException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Class _class = session.get(Class.class, classId);
        Schedule schedule = null;
        if (_class == null)
            throw new ClassDaoException("Class with id : " + classId + " does not exist");
        for (Schedule s : _class.getScheduleList()) {
            if (s.getId() == id) {
                _class.getScheduleList().remove(s);
                schedule = s;
                break;
            }
        }
        if (schedule == null)
            throw new ClassDaoException("Class's schedule with id : " + id + " does not exist");
        session.getTransaction().commit();
        session.close();
        return schedule;
    } catch (ClassDaoException e) {
        session.close();
        throw new ClassException(e.getMessage());
    }
}
Also used : ClassDaoException(com.remswork.project.alice.dao.exception.ClassDaoException) Class(com.remswork.project.alice.model.Class) Session(org.hibernate.Session)

Aggregations

Class (com.remswork.project.alice.model.Class)59 Session (org.hibernate.Session)35 ClassException (com.remswork.project.alice.exception.ClassException)18 GradingFactorDaoException (com.remswork.project.alice.dao.exception.GradingFactorDaoException)16 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)16 Message (com.remswork.project.alice.model.support.Message)16 ClassDaoException (com.remswork.project.alice.dao.exception.ClassDaoException)15 Query (org.hibernate.Query)10 Student (com.remswork.project.alice.model.Student)9 ArrayList (java.util.ArrayList)9 ClassServiceException (com.remswork.project.alice.web.service.exception.ClassServiceException)8 Client (javax.ws.rs.client.Client)8 WebTarget (javax.ws.rs.client.WebTarget)8 Response (javax.ws.rs.core.Response)8 Grade (com.remswork.project.alice.model.Grade)7 Formula (com.remswork.project.alice.model.Formula)6 FormulaService (com.remswork.project.alice.service.FormulaService)6 GradeService (com.remswork.project.alice.service.GradeService)6 FormulaServiceImpl (com.remswork.project.alice.service.impl.FormulaServiceImpl)6 GradeServiceImpl (com.remswork.project.alice.service.impl.GradeServiceImpl)6