Search in sources :

Example 16 with Class

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

the class ClassDaoImpl method getStudentById.

@Override
public Student getStudentById(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)
                student = s;
        }
        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 17 with Class

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

the class ClassDaoImpl method deleteClassById.

@Override
public Class deleteClassById(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");
        _class.setTeacher(null);
        _class.setSubject(null);
        _class.setScheduleList(null);
        _class.setSection(null);
        _class.setStudentList(null);
        for (Object object : session.createQuery("from Activity where _class.id = '" + id + "'").list()) {
            Activity activity = (Activity) object;
            String hql = "delete from ActivityResult where activity.id = :activityId";
            Query query = session.createQuery(hql);
            query.setParameter("activityId", activity.getId());
            query.executeUpdate();
            session.delete(activity);
        }
        for (Object object : session.createQuery("from Assignment where _class.id = '" + id + "'").list()) {
            Assignment assignment = (Assignment) object;
            String hql = "delete from AssignmentResult where assignment.id = :assignmentId";
            Query query = session.createQuery(hql);
            query.setParameter("assignmentId", assignment.getId());
            query.executeUpdate();
            session.delete(assignment);
        }
        for (Object object : session.createQuery("from Attendance where _class.id = '" + id + "'").list()) {
            Attendance attendance = (Attendance) object;
            String hql = "delete from AttendanceResult where attendance.id = :attendanceId";
            Query query = session.createQuery(hql);
            query.setParameter("attendanceId", attendance.getId());
            query.executeUpdate();
            session.delete(attendance);
        }
        for (Object object : session.createQuery("from Exam where _class.id = '" + id + "'").list()) {
            Exam exam = (Exam) object;
            String hql = "delete from ExamResult where exam.id = :examId";
            Query query = session.createQuery(hql);
            query.setParameter("examId", exam.getId());
            query.executeUpdate();
            session.delete(exam);
        }
        for (Object object : session.createQuery("from Project where _class.id = '" + id + "'").list()) {
            Project project = (Project) object;
            String hql = "delete from ProjectResult where project.id = :projectId";
            Query query = session.createQuery(hql);
            query.setParameter("projectId", project.getId());
            query.executeUpdate();
            session.delete(project);
        }
        for (Object object : session.createQuery("from Quiz where _class.id = '" + id + "'").list()) {
            Quiz quiz = (Quiz) object;
            String hql = "delete from QuizResult where quiz.id = :quizId";
            Query query = session.createQuery(hql);
            query.setParameter("quizId", quiz.getId());
            query.executeUpdate();
            session.delete(quiz);
        }
        for (Object object : session.createQuery("from Recitation where _class.id = '" + id + "'").list()) {
            Recitation recitation = (Recitation) object;
            String hql = "delete from RecitationResult where recitation.id = :recitationId";
            Query query = session.createQuery(hql);
            query.setParameter("recitationId", recitation.getId());
            query.executeUpdate();
            session.delete(recitation);
        }
        String hql = "delete from Grade as G where G._class.id = :classId";
        Query query = session.createQuery(hql);
        query.setParameter("classId", id);
        query.executeUpdate();
        session.delete(_class);
        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) Query(org.hibernate.Query) Class(com.remswork.project.alice.model.Class) Session(org.hibernate.Session)

Example 18 with Class

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

the class ClassDaoImpl method addStudentById.

@Override
public Student addStudentById(long classId, long id) 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");
        Student student = studentDao.getStudentById(id);
        for (Student s : _class.getStudentList()) {
            if (s.getId() == id)
                throw new ClassDaoException("Class's student with id : " + id + " already exist");
        }
        _class.getStudentList().add(student);
        session.merge(_class);
        session.getTransaction().commit();
        session.close();
        return student;
    } catch (ClassDaoException | StudentException 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 19 with Class

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

the class ClassDaoImpl method getClassList.

@Override
public List<Class> getClassList() throws ClassException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Class> classList = new ArrayList<>();
        Query query = session.createQuery("from Class");
        for (Object classObject : query.list()) classList.add((Class) classObject);
        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 20 with Class

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

the class ClassDaoImpl method getScheduleById.

@Override
public Schedule getScheduleById(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)
                schedule = s;
        }
        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