use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class AttendanceDaoImpl method addAttendanceResult.
@Override
public AttendanceResult addAttendanceResult(int status, long attendanceId, long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Attendance attendance = session.get(Attendance.class, attendanceId);
Student student = session.get(Student.class, studentId);
AttendanceResult result = new AttendanceResult();
String hql = "from AttendanceResult as R where R.attendance.id = :attendanceId and R.student.id = :studentId";
Query query = session.createQuery(hql);
query.setParameter("attendanceId", attendanceId);
query.setParameter("studentId", studentId);
if (attendance == null)
throw new GradingFactorDaoException("Attendance's attendance with id : " + attendanceId + " does not exist");
if (student == null)
throw new GradingFactorDaoException("Attendance's student with id : " + studentId + " does not exist");
if (attendanceId < 1)
throw new GradingFactorDaoException("Query param : attendanceId is required");
if (studentId < 1)
throw new GradingFactorDaoException("Query param : studentId is required");
if (query.list().size() > 0)
throw new GradingFactorDaoException("AttendanceResult's student with id : " + studentId + " already exist");
result.setStatus(status);
result.setAttendance(attendance);
result.setStudent(student);
session.persist(result);
session.getTransaction().commit();
session.close();
return result;
} 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 addFormula.
@Override
public Formula addFormula(Formula formula, long subjectId, long teacherId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Subject subject = session.get(Subject.class, subjectId);
Teacher teacher = session.get(Teacher.class, teacherId);
if (teacherId == 0)
throw new GradingFactorException("Query param : teacherId is required");
if (subjectId == 0)
throw new GradingFactorException("Query param : subjectId is required");
if (formula == null)
throw new GradingFactorDaoException("You tried to add formula with a null value");
if (subject == null)
throw new GradingFactorDaoException("Factor's subject with id : " + subjectId + " does not exist");
if (teacher == null)
throw new GradingFactorDaoException("Factor's teacher with id : " + teacherId + " does not exist");
formula.setSubject(subject);
formula.setTeacher(teacher);
session.persist(formula);
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 RecitationDaoImpl method getRecitationListByStudentId.
@Override
public List<Recitation> getRecitationListByStudentId(long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Student student = session.get(Student.class, studentId);
List<Recitation> recitationList = new ArrayList<>();
String hql = "from RecitationResult as R join R.recitation where R.student.id = :studentId";
if (student == null)
throw new GradingFactorDaoException("Recitation's student with id : " + studentId + " does not exist");
Query query = session.createQuery(hql);
query.setParameter("studentId", studentId);
for (Object object : query.list()) recitationList.add((Recitation) ((Object[]) object)[1]);
session.getTransaction().commit();
session.close();
return recitationList;
} 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 RecitationDaoImpl method updateRecitationById.
@Override
public Recitation updateRecitationById(long id, Recitation newRecitation, long classId, long termId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Recitation recitation = session.get(Recitation.class, id);
Class _class = session.get(Class.class, classId);
Term term = session.get(Term.class, termId);
if (newRecitation == null)
newRecitation = new Recitation();
if (recitation == null)
throw new GradingFactorDaoException("Recitation with id : " + id + " does not exist");
if (_class == null && classId != 0)
throw new GradingFactorDaoException("Recitation's class with id : " + classId + " does not exist");
if (term == null && termId > 0)
throw new GradingFactorDaoException("Recitation's term with id : " + termId + " does not exist");
if (!(newRecitation.getTitle() != null ? newRecitation.getTitle() : "").trim().isEmpty())
recitation.setTitle(newRecitation.getTitle());
if (!(newRecitation.getDate() != null ? newRecitation.getDate() : "").trim().isEmpty())
recitation.setDate(newRecitation.getDate());
if (classId > 0) {
if (classId == (recitation.get_class() != null ? recitation.get_class().getId() : 0))
throw new GradingFactorDaoException("Recitation's class with id : " + classId + " already exist");
recitation.set_class(_class);
}
if (termId > 0) {
if (termId != (recitation.getTerm() != null ? recitation.getTerm().getId() : 0))
recitation.setTerm(term);
}
session.getTransaction().commit();
session.close();
return recitation;
} 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 TermDaoImpl method getTermList.
@Override
public List<Term> getTermList() throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Term> termList = new ArrayList<>();
Query query = session.createQuery("from Term");
for (Object objTerm : query.list()) termList.add((Term) objTerm);
session.getTransaction().commit();
session.close();
return termList;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
Aggregations