Search in sources :

Example 26 with GradingFactorDaoException

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

the class ExamDaoImpl method getExamListByStudentId.

@Override
public List<Exam> getExamListByStudentId(long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Student student = session.get(Student.class, studentId);
        List<Exam> examList = new ArrayList<>();
        String hql = "from ExamResult as R join R.exam where R.student.id = :studentId";
        if (student == null)
            throw new GradingFactorDaoException("Exam's student with id : " + studentId + " does not exist");
        Query query = session.createQuery(hql);
        query.setParameter("studentId", studentId);
        for (Object object : query.list()) examList.add((Exam) ((Object[]) object)[1]);
        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 27 with GradingFactorDaoException

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

the class ExamDaoImpl method deleteExamResultByExamAndStudentId.

@Override
public ExamResult deleteExamResultByExamAndStudentId(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'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 (query.list().size() < 1)
            throw new GradingFactorDaoException("No result to delete");
        ExamResult result = (ExamResult) query.list().get(0);
        session.delete(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 28 with GradingFactorDaoException

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

the class ExamDaoImpl method updateExamResultByExamAndStudentId.

@Override
public ExamResult updateExamResultByExamAndStudentId(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);
        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 (query.list().size() < 1)
            throw new GradingFactorDaoException("No result to delete");
        ExamResult result = (ExamResult) query.list().get(0);
        result.setScore(score);
        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 29 with GradingFactorDaoException

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

the class ExamDaoImpl method getExamResultById.

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

Example 30 with GradingFactorDaoException

use of com.remswork.project.alice.dao.exception.GradingFactorDaoException 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)

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