Search in sources :

Example 86 with GradingFactorDaoException

use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.

the class ExamDaoImpl method getExamList.

@Override
public List<Exam> getExamList() throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Exam> examList = new ArrayList<>();
        Query query = session.createQuery("from Exam");
        for (Object objExam : query.list()) examList.add((Exam) objExam);
        session.getTransaction().commit();
        session.close();
        return examList;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) ArrayList(java.util.ArrayList) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 87 with GradingFactorDaoException

use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.

the class ExamDaoImpl method addExamResult.

@Override
public ExamResult addExamResult(int score, long examId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Exam exam = session.get(Exam.class, examId);
        Student student = session.get(Student.class, studentId);
        ExamResult result = new ExamResult();
        String hql = "from ExamResult as R where R.exam.id = :examId and R.student.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("examId", examId);
        query.setParameter("studentId", studentId);
        if (exam == null)
            throw new GradingFactorDaoException("Exam's exam with id : " + examId + " does not exist");
        if (student == null)
            throw new GradingFactorDaoException("Exam's student with id : " + studentId + " does not exist");
        if (examId < 1)
            throw new GradingFactorDaoException("Query param : examId is required");
        if (studentId < 1)
            throw new GradingFactorDaoException("Query param : studentId is required");
        if (score < 0 && score > exam.getItemTotal())
            throw new GradingFactorDaoException("ExamResult's score is invalid");
        if (query.list().size() > 0)
            throw new GradingFactorDaoException("ExamResult's  student with id : " + studentId + " already exist");
        result.setScore(score);
        result.setExam(exam);
        result.setStudent(student);
        session.persist(result);
        session.getTransaction().commit();
        session.close();
        return result;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 88 with GradingFactorDaoException

use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.

the class ExamDaoImpl method getExamListByClassId.

@Override
public List<Exam> getExamListByClassId(long classId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Exam> examList = new ArrayList<>();
        String hql = "from Exam where _class.id = :classId and term.id = :termId";
        Query query = session.createQuery(hql);
        query.setParameter("classId", classId);
        query.setParameter("termId", termId);
        for (Object objExam : query.list()) examList.add((Exam) objExam);
        session.getTransaction().commit();
        session.close();
        return examList;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) ArrayList(java.util.ArrayList) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 89 with GradingFactorDaoException

use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.

the class ExamDaoImpl method getExamResultByExamAndStudentId.

@Override
public ExamResult getExamResultByExamAndStudentId(long examId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Exam exam = session.get(Exam.class, examId);
        Student student = session.get(Student.class, studentId);
        String hql = "from ExamResult as R where R.exam.id = :examId and R.student.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("examId", examId);
        query.setParameter("studentId", studentId);
        if (exam == null)
            throw new GradingFactorDaoException("Exam with id : " + examId + " does not exist");
        if (student == null)
            throw new GradingFactorDaoException("Exam's student with id : " + studentId + " does not exist");
        if (query.list().size() < 1)
            throw new GradingFactorDaoException("No ExamResult found. Try use query param " + "(ex. studentId=[id])");
        ExamResult result = (ExamResult) query.list().get(0);
        session.getTransaction().commit();
        session.close();
        return result;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 90 with GradingFactorDaoException

use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.

the class ProjectDaoImpl method getProjectListByStudentId.

@Override
public List<Project> getProjectListByStudentId(long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Student student = session.get(Student.class, studentId);
        List<Project> projectList = new ArrayList<>();
        String hql = "from ProjectResult as R join R.project where R.student.id = :studentId";
        if (student == null)
            throw new GradingFactorDaoException("Project's student with id : " + studentId + " does not exist");
        Query query = session.createQuery(hql);
        query.setParameter("studentId", studentId);
        for (Object object : query.list()) projectList.add((Project) ((Object[]) object)[1]);
        session.getTransaction().commit();
        session.close();
        return projectList;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) ArrayList(java.util.ArrayList) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Aggregations

GradingFactorDaoException (com.remswork.project.alice.dao.exception.GradingFactorDaoException)104 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)104 Session (org.hibernate.Session)104 Query (org.hibernate.Query)64 ArrayList (java.util.ArrayList)27 Class (com.remswork.project.alice.model.Class)16 Grade (com.remswork.project.alice.model.Grade)7 Formula (com.remswork.project.alice.model.Formula)6 Student (com.remswork.project.alice.model.Student)2 Subject (com.remswork.project.alice.model.Subject)2 Teacher (com.remswork.project.alice.model.Teacher)2 Term (com.remswork.project.alice.model.Term)2