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());
}
}
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());
}
}
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());
}
}
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());
}
}
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());
}
}
Aggregations