Search in sources :

Example 71 with GradingFactorDaoException

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

the class AssignmentDaoImpl method getAssignmentListByStudentId.

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

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

the class AssignmentDaoImpl method addAssignmentResult.

@Override
public AssignmentResult addAssignmentResult(int score, long assignmentId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Assignment assignment = session.get(Assignment.class, assignmentId);
        Student student = session.get(Student.class, studentId);
        AssignmentResult result = new AssignmentResult();
        String hql = "from AssignmentResult as R where R.assignment.id = :assignmentId and R.student.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("assignmentId", assignmentId);
        query.setParameter("studentId", studentId);
        if (assignment == null)
            throw new GradingFactorDaoException("Assignment's assignment with id : " + assignmentId + " does not exist");
        if (student == null)
            throw new GradingFactorDaoException("Assignment's student with id : " + studentId + " does not exist");
        if (assignmentId < 1)
            throw new GradingFactorDaoException("Query param : assignmentId is required");
        if (studentId < 1)
            throw new GradingFactorDaoException("Query param : studentId is required");
        if (score < 0 && score > assignment.getItemTotal())
            throw new GradingFactorDaoException("AssignmentResult's score is invalid");
        if (query.list().size() > 0)
            throw new GradingFactorDaoException("AssignmentResult's  student with id : " + studentId + " already exist");
        result.setScore(score);
        result.setAssignment(assignment);
        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 73 with GradingFactorDaoException

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

the class AssignmentDaoImpl method addAssignment.

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

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

the class AssignmentDaoImpl method updateAssignmentById.

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

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

the class AttendanceDaoImpl method getAttendanceList.

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