Search in sources :

Example 61 with GradingFactorDaoException

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

the class GradeDaoImpl method getGradeListByClass.

@Override
public List<Grade> getGradeListByClass(long classId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Grade> gradeList = new ArrayList<>();
        String hql = "from Grade as G where G._class.id = :classId and G.student.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("classId", classId);
        query.setParameter("studentId", studentId);
        for (Object object : query.list()) gradeList.add((Grade) object);
        session.getTransaction().commit();
        session.close();
        return gradeList;
    } 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) Grade(com.remswork.project.alice.model.Grade) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 62 with GradingFactorDaoException

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

the class GradeDaoImpl method updateGrade.

@Override
public Grade updateGrade(long id, Grade newGrade, long classId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Grade grade = session.get(Grade.class, id);
        Class _class = session.get(Class.class, classId);
        Student student = session.get(Student.class, studentId);
        if (newGrade == null)
            newGrade = new Grade();
        if (grade == null)
            throw new GradingFactorDaoException("Grade with id : " + id + " doesn't exist.");
        if (_class == null && classId != 0)
            throw new GradingFactorDaoException("Class with id : " + classId + " doesn't exist.");
        if (student == null && studentId != 0)
            throw new GradingFactorDaoException("Student with id : " + studentId + " doesn't exist.");
        if (classId < 0)
            throw new GradingFactorDaoException("The class id is invalid");
        if (studentId < 0)
            throw new GradingFactorDaoException("The student id is invalid");
        if (newGrade.getTotalScore() >= 0 && grade.getTotalScore() > 0)
            grade.setTotalScore(newGrade.getTotalScore());
        if (newGrade.getActivityScore() > 0 && grade.getActivityScore() > 0)
            grade.setActivityScore(newGrade.getActivityScore());
        if (newGrade.getAssignmentScore() > 0 && grade.getAssignmentScore() > 0)
            grade.setAssignmentScore(newGrade.getAssignmentScore());
        if (newGrade.getAttendanceScore() > 0 && grade.getAttendanceScore() > 0)
            grade.setAttendanceScore(newGrade.getAttendanceScore());
        if (newGrade.getExamScore() > 0 && grade.getExamScore() > 0)
            grade.setExamScore(newGrade.getExamScore());
        if (newGrade.getProjectScore() > 0 && grade.getProjectScore() > 0)
            grade.setProjectScore(newGrade.getProjectScore());
        if (newGrade.getQuizScore() > 0 && grade.getQuizScore() > 0)
            grade.setQuizScore(newGrade.getQuizScore());
        if (classId > 0) {
            if ((grade.get_class() != null ? grade.get_class().getId() : 0) == classId)
                throw new GradingFactorDaoException("The class id is already exist");
            grade.set_class(_class);
        }
        if (studentId > 0) {
            if ((grade.getStudent() != null ? grade.getStudent().getId() : 0) == studentId)
                throw new GradingFactorDaoException("The student id is already exist");
            grade.setStudent(student);
        }
        grade.set_class(_class);
        grade.setStudent(student);
        session.getTransaction().commit();
        session.close();
        return grade;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Grade(com.remswork.project.alice.model.Grade) Class(com.remswork.project.alice.model.Class) Student(com.remswork.project.alice.model.Student) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 63 with GradingFactorDaoException

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

the class GradeDaoImpl method getGradeListByStudentId.

@Override
public List<Grade> getGradeListByStudentId(long studentId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Grade> gradeList = new ArrayList<>();
        String hql = "from Grade as G where G.student.id = :studentId and G.term.id = :termId";
        Query query = session.createQuery(hql);
        query.setParameter("studentId", studentId);
        query.setParameter("termId", termId);
        for (Object object : query.list()) gradeList.add((Grade) object);
        session.getTransaction().commit();
        session.close();
        return gradeList;
    } 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) Grade(com.remswork.project.alice.model.Grade) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 64 with GradingFactorDaoException

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

the class GradeDaoImpl method getGradeById.

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

Example 65 with GradingFactorDaoException

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

the class ProjectDaoImpl method updateProjectResultByProjectAndStudentId.

@Override
public ProjectResult updateProjectResultByProjectAndStudentId(int score, long projectId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Project project = session.get(Project.class, projectId);
        Student student = session.get(Student.class, studentId);
        String hql = "from ProjectResult as R where R.project.id = :projectId and R.student.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("projectId", projectId);
        query.setParameter("studentId", studentId);
        if (project == null)
            throw new GradingFactorDaoException("Project's project with id : " + projectId + " does not exist");
        if (student == null)
            throw new GradingFactorDaoException("Project's student with id : " + studentId + " does not exist");
        if (projectId < 1)
            throw new GradingFactorDaoException("Query param : projectId 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");
        ProjectResult result = (ProjectResult) 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)

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