Search in sources :

Example 96 with GradingFactorDaoException

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

the class AttendanceDaoImpl method addAttendanceResult.

@Override
public AttendanceResult addAttendanceResult(int status, long attendanceId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Attendance attendance = session.get(Attendance.class, attendanceId);
        Student student = session.get(Student.class, studentId);
        AttendanceResult result = new AttendanceResult();
        String hql = "from AttendanceResult as R where R.attendance.id = :attendanceId and R.student.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("attendanceId", attendanceId);
        query.setParameter("studentId", studentId);
        if (attendance == null)
            throw new GradingFactorDaoException("Attendance's attendance with id : " + attendanceId + " does not exist");
        if (student == null)
            throw new GradingFactorDaoException("Attendance's student with id : " + studentId + " does not exist");
        if (attendanceId < 1)
            throw new GradingFactorDaoException("Query param : attendanceId is required");
        if (studentId < 1)
            throw new GradingFactorDaoException("Query param : studentId is required");
        if (query.list().size() > 0)
            throw new GradingFactorDaoException("AttendanceResult's  student with id : " + studentId + " already exist");
        result.setStatus(status);
        result.setAttendance(attendance);
        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 97 with GradingFactorDaoException

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

the class FormulaDaoImpl method addFormula.

@Override
public Formula addFormula(Formula formula, long subjectId, long teacherId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Subject subject = session.get(Subject.class, subjectId);
        Teacher teacher = session.get(Teacher.class, teacherId);
        if (teacherId == 0)
            throw new GradingFactorException("Query param : teacherId is required");
        if (subjectId == 0)
            throw new GradingFactorException("Query param : subjectId is required");
        if (formula == null)
            throw new GradingFactorDaoException("You tried to add formula with a null value");
        if (subject == null)
            throw new GradingFactorDaoException("Factor's subject with id : " + subjectId + " does not exist");
        if (teacher == null)
            throw new GradingFactorDaoException("Factor's teacher with id : " + teacherId + " does not exist");
        formula.setSubject(subject);
        formula.setTeacher(teacher);
        session.persist(formula);
        session.getTransaction().commit();
        session.close();
        return formula;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Teacher(com.remswork.project.alice.model.Teacher) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Subject(com.remswork.project.alice.model.Subject) Session(org.hibernate.Session)

Example 98 with GradingFactorDaoException

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

the class RecitationDaoImpl method getRecitationListByStudentId.

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

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

the class RecitationDaoImpl method updateRecitationById.

@Override
public Recitation updateRecitationById(long id, Recitation newRecitation, long classId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Recitation recitation = session.get(Recitation.class, id);
        Class _class = session.get(Class.class, classId);
        Term term = session.get(Term.class, termId);
        if (newRecitation == null)
            newRecitation = new Recitation();
        if (recitation == null)
            throw new GradingFactorDaoException("Recitation with id : " + id + " does not exist");
        if (_class == null && classId != 0)
            throw new GradingFactorDaoException("Recitation's class with id : " + classId + " does not exist");
        if (term == null && termId > 0)
            throw new GradingFactorDaoException("Recitation's term with id : " + termId + " does not exist");
        if (!(newRecitation.getTitle() != null ? newRecitation.getTitle() : "").trim().isEmpty())
            recitation.setTitle(newRecitation.getTitle());
        if (!(newRecitation.getDate() != null ? newRecitation.getDate() : "").trim().isEmpty())
            recitation.setDate(newRecitation.getDate());
        if (classId > 0) {
            if (classId == (recitation.get_class() != null ? recitation.get_class().getId() : 0))
                throw new GradingFactorDaoException("Recitation's  class with id : " + classId + " already exist");
            recitation.set_class(_class);
        }
        if (termId > 0) {
            if (termId != (recitation.getTerm() != null ? recitation.getTerm().getId() : 0))
                recitation.setTerm(term);
        }
        session.getTransaction().commit();
        session.close();
        return recitation;
    } 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 100 with GradingFactorDaoException

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

the class TermDaoImpl method getTermList.

@Override
public List<Term> getTermList() throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Term> termList = new ArrayList<>();
        Query query = session.createQuery("from Term");
        for (Object objTerm : query.list()) termList.add((Term) objTerm);
        session.getTransaction().commit();
        session.close();
        return termList;
    } 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