Search in sources :

Example 56 with GradingFactorDaoException

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

the class FormulaDaoImpl method getFormulaBySubjectAndTeacherId.

@Override
public Formula getFormulaBySubjectAndTeacherId(long subjectId, long teacherId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        String hql = "from Formula where subject.id = :subjectId and teacher.id = :teacherId and term.id = :termId";
        Query query = session.createQuery(hql);
        query.setParameter("subjectId", subjectId);
        query.setParameter("teacherId", teacherId);
        query.setParameter("termId", termId);
        Formula formula;
        if (query.list().size() < 1)
            throw new GradingFactorDaoException("Formula with subjectId : " + subjectId + ", teacherId : " + teacherId + " or termId : " + termId + " does not exist");
        formula = (Formula) query.list().get(0);
        session.getTransaction().commit();
        session.close();
        return formula;
    } 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) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 57 with GradingFactorDaoException

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

the class FormulaDaoImpl method getFormulaById.

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

Example 58 with GradingFactorDaoException

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

the class FormulaDaoImpl method updateFormulaById.

@Override
public Formula updateFormulaById(long id, Formula newFormula, long subjectId, long teacherId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Formula formula = session.get(Formula.class, id);
        Subject subject = session.get(Subject.class, subjectId);
        Teacher teacher = session.get(Teacher.class, teacherId);
        Term term = session.get(Term.class, termId);
        if (newFormula == null)
            newFormula = new Formula();
        if (formula == null)
            throw new GradingFactorDaoException("Formula with id : " + id + " does not exist");
        if (subject == null && subjectId != 0)
            throw new GradingFactorDaoException("Factor's subject with id : " + subjectId + " does not exist");
        if (teacher == null && teacherId != 0)
            throw new GradingFactorDaoException("Factor's teacher with id : " + teacherId + " does not exist");
        if (term == null && termId != 0)
            throw new GradingFactorDaoException("Factor's term with id : " + termId + " does not exist");
        formula.setActivityPercentage(newFormula.getActivityPercentage());
        formula.setAssignmentPercentage(newFormula.getAssignmentPercentage());
        formula.setAttendancePercentage(newFormula.getAttendancePercentage());
        formula.setExamPercentage(newFormula.getExamPercentage());
        formula.setProjectPercentage(newFormula.getProjectPercentage());
        formula.setQuizPercentage(newFormula.getQuizPercentage());
        formula.setRecitationPercentage(newFormula.getRecitationPercentage());
        if (subjectId > 0) {
            if (subjectId == (formula.getSubject() != null ? formula.getSubject().getId() : 0))
                throw new GradingFactorException("Formula's  subject with id : " + subjectId + " already exist");
            formula.setSubject(subject);
        }
        if (teacherId > 0) {
            if (teacherId == (formula.getTeacher() != null ? formula.getTeacher().getId() : 0))
                throw new GradingFactorException("Formula's  teacher with id : " + teacherId + " already exist");
            formula.setTeacher(teacher);
        }
        if (termId > 0) {
            if (termId == (formula.getTerm() != null ? formula.getTerm().getId() : 0))
                throw new GradingFactorException("Formula's  term with id : " + termId + " already exist");
            formula.setTerm(term);
        }
        session.getTransaction().commit();
        session.close();
        return formula;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : Formula(com.remswork.project.alice.model.Formula) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Teacher(com.remswork.project.alice.model.Teacher) Term(com.remswork.project.alice.model.Term) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Subject(com.remswork.project.alice.model.Subject) Session(org.hibernate.Session)

Example 59 with GradingFactorDaoException

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

the class FormulaDaoImpl method getFormulaListByTeacherId.

@Override
public List<Formula> getFormulaListByTeacherId(long teacherId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Formula> formulaList = new ArrayList<>();
        String hql = "from Formula where teacher.id = :teacherId";
        Query query = session.createQuery(hql);
        query.setParameter("teacherId", teacherId);
        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 60 with GradingFactorDaoException

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

the class FormulaDaoImpl method deleteFormulaById.

@Override
public Formula deleteFormulaById(long id) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Formula formula = session.get(Formula.class, id);
        if (formula == null)
            throw new GradingFactorDaoException("Formula with id : " + id + " does not exist");
        session.delete(formula);
        session.getTransaction().commit();
        session.close();
        return formula;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : Formula(com.remswork.project.alice.model.Formula) 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