Search in sources :

Example 6 with GradingFactorDaoException

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

the class RecitationDaoImpl method addRecitationResult.

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

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

the class ExamDaoImpl method updateExamById.

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

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

the class FormulaDaoImpl method getFormulaList.

@Override
public List<Formula> getFormulaList() throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Formula> formulaList = new ArrayList<>();
        Query query = session.createQuery("from Formula");
        for (Object objFormula : query.list()) formulaList.add((Formula) objFormula);
        session.getTransaction().commit();
        session.close();
        return formulaList;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : Formula(com.remswork.project.alice.model.Formula) 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 9 with GradingFactorDaoException

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

the class GradeDaoImpl method addGrade.

@Override
public Grade addGrade(Grade grade, long classId, long studentId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Class _class = session.get(Class.class, classId);
        Student student = session.get(Student.class, studentId);
        Term term = session.get(Term.class, termId);
        if (grade == null)
            throw new GradingFactorDaoException("You tried to add grade with a null value");
        if (grade.getTotalScore() < 0)
            throw new GradingFactorDaoException("Grade's total score is not valid");
        if (grade.getActivityScore() < 0)
            throw new GradingFactorDaoException("Grade's activity score is not valid");
        if (grade.getAssignmentScore() < 0)
            throw new GradingFactorDaoException("Grade's assignment score is not valid");
        if (grade.getAttendanceScore() < 0)
            throw new GradingFactorDaoException("Grade's attendance score is not valid");
        if (grade.getExamScore() < 0)
            throw new GradingFactorDaoException("Grade's exam score is not valid");
        if (grade.getProjectScore() < 0)
            throw new GradingFactorDaoException("Grade's project score is not valid");
        if (grade.getQuizScore() < 0)
            throw new GradingFactorDaoException("Grade's quiz score is not valid");
        if (classId < 1)
            throw new GradingFactorDaoException("Query param : classId is required.");
        if (studentId < 1)
            throw new GradingFactorDaoException("Query param : studentId is required.");
        if (termId < 1)
            throw new GradingFactorDaoException("Query param : termId is required.");
        if (_class == null)
            throw new GradingFactorDaoException("Class with id : " + classId + " doesn't exist.");
        if (student == null)
            throw new GradingFactorDaoException("Student with id : " + studentId + " doesn't exist.");
        if (term == null)
            throw new GradingFactorDaoException("Term with id : " + termId + " doesn't exist.");
        grade.set_class(_class);
        grade.setStudent(student);
        grade.setTerm(term);
        session.persist(grade);
        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) Class(com.remswork.project.alice.model.Class) Term(com.remswork.project.alice.model.Term) Student(com.remswork.project.alice.model.Student) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 10 with GradingFactorDaoException

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

the class GradeDaoImpl method getGradeList.

@Override
public List<Grade> getGradeList() throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Grade> gradeList = new ArrayList<>();
        Query query = session.createQuery("from Grade");
        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)

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