Search in sources :

Example 46 with Class

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

the class ClassDaoImpl method getStudentList.

@Override
public Set<Student> getStudentList(long classId) throws ClassException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Class _class = session.get(Class.class, classId);
        if (_class == null)
            throw new ClassDaoException("Class with id : " + classId + " does not exist");
        Set<Student> studentSet = _class.getStudentList();
        session.getTransaction().commit();
        session.close();
        return studentSet;
    } 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 47 with Class

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

the class ClassDaoImpl method deleteStudentById.

@Override
public Student deleteStudentById(long classId, long id) throws ClassException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Class _class = session.get(Class.class, classId);
        Student student = null;
        if (_class == null)
            throw new ClassDaoException("Class with id : " + classId + " does not exist");
        for (Student s : _class.getStudentList()) {
            if (s.getId() == id) {
                _class.getStudentList().remove(s);
                student = s;
                break;
            }
        }
        if (student == null)
            throw new ClassDaoException("Class's student with id : " + id + " does not exist");
        session.getTransaction().commit();
        session.close();
        return student;
    } 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 48 with Class

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

the class ClassDaoImpl method getClassListByStudentId.

@Override
public List<Class> getClassListByStudentId(long studentId) throws ClassException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Class> classList = new ArrayList<>();
        Query query = session.createQuery("from Class as c join c.studentList as st where st.id = :studentId");
        query.setParameter("studentId", studentId);
        for (Object classObject : query.list()) classList.add((Class) ((Object[]) classObject)[0]);
        session.getTransaction().commit();
        session.close();
        return classList;
    } catch (ClassDaoException e) {
        session.close();
        throw new ClassException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) ClassDaoException(com.remswork.project.alice.dao.exception.ClassDaoException) ArrayList(java.util.ArrayList) Class(com.remswork.project.alice.model.Class) Session(org.hibernate.Session)

Example 49 with Class

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

the class DepartmentDaoImpl method deleteDepartmentById.

@Override
public Department deleteDepartmentById(long id) throws DepartmentException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Department department = session.get(Department.class, id);
        if (department == null)
            throw new DepartmentDaoException("Department with id : " + id + " does not exist.");
        // to avoid the constraints restriction we meed to remove department from the teacher
        // that having the department
        Query teacherQuery = session.createQuery("from Teacher");
        for (Object teacherObj : teacherQuery.list()) {
            Teacher teacher = (Teacher) teacherObj;
            if (teacher.getDepartment() == null)
                continue;
            if (teacher.getDepartment().equals(department) || (teacher.getDepartment() != null ? teacher.getDepartment().getId() : 0) == department.getId()) {
                teacher.setDepartment(null);
            }
        }
        // to avoid the constraints restriction we meed to delete the section that having the department
        Query sectionQuery = session.createQuery("from Section");
        for (Object sectionObj : sectionQuery.list()) {
            Section section = (Section) sectionObj;
            if (section.getDepartment() == null)
                continue;
            if (section.getDepartment().equals(department) || (section.getDepartment() != null ? section.getDepartment().getId() : 0) == department.getId()) {
                session.delete(section);
            }
        }
        // to avoid the constraints restriction we meed to remove department from the class's teacher and section
        // that having the department
        Query classQuery = session.createQuery("from Class");
        for (Object classObj : classQuery.list()) {
            Class _class = (Class) classObj;
            Teacher teacher = _class.getTeacher();
            Section section = _class.getSection();
            if (teacher != null) {
                if (teacher.getDepartment() != null) {
                    if (teacher.getDepartment().equals(department) || (teacher.getDepartment() != null ? teacher.getDepartment().getId() : 0) == department.getId()) {
                        teacher.setDepartment(null);
                    }
                }
            }
            if (section != null) {
                if (section.getDepartment() != null) {
                    if (section.getDepartment().equals(department) || (section.getDepartment() != null ? section.getDepartment().getId() : 0) == department.getId()) {
                        _class.setSection(null);
                    }
                }
            }
        }
        session.delete(department);
        session.getTransaction().commit();
        session.close();
        return department;
    } catch (DepartmentDaoException e) {
        session.close();
        throw new DepartmentException(e.getMessage());
    }
}
Also used : Department(com.remswork.project.alice.model.Department) Query(org.hibernate.Query) DepartmentException(com.remswork.project.alice.exception.DepartmentException) Teacher(com.remswork.project.alice.model.Teacher) Class(com.remswork.project.alice.model.Class) DepartmentDaoException(com.remswork.project.alice.dao.exception.DepartmentDaoException) Section(com.remswork.project.alice.model.Section) Session(org.hibernate.Session)

Example 50 with Class

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

the class ExamDaoImpl method addExam.

@Override
public Exam addExam(Exam exam, long classId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Class _class = session.get(Class.class, classId);
        if (exam == null)
            throw new GradingFactorDaoException("You tried to add class with a null value");
        if (classId == 0)
            throw new GradingFactorDaoException("Query param : classId is required");
        if (_class == null)
            throw new GradingFactorDaoException("Exam's class with id : " + classId + " does not exist");
        if (exam.getTitle() == null)
            throw new GradingFactorDaoException("Exam's title is required");
        if (exam.getTitle().trim().equals(""))
            throw new GradingFactorDaoException("Exam can't have an empty title");
        if (exam.getDate() == null)
            throw new GradingFactorDaoException("Exam's date is required");
        if (exam.getDate().trim().equals(""))
            throw new GradingFactorDaoException("Exam can't have an empty date");
        if (exam.getItemTotal() < 0)
            throw new GradingFactorDaoException("Exam's itemTotal is invalid");
        exam.set_class(_class);
        session.persist(exam);
        session.getTransaction().commit();
        session.close();
        return exam;
    } 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)

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