use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class AttendanceDaoImpl method getAttendanceResultByAttendanceAndStudentId.
@Override
public AttendanceResult getAttendanceResultByAttendanceAndStudentId(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);
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 with id : " + attendanceId + " does not exist");
if (student == null)
throw new GradingFactorDaoException("Attendance's student with id : " + studentId + " does not exist");
if (query.list().size() < 1)
throw new GradingFactorDaoException("No AttendanceResult found. Try use query param " + "(ex. studentId=[id])");
AttendanceResult result = (AttendanceResult) query.list().get(0);
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 AttendanceDaoImpl method deleteAttendanceResultByAttendanceAndStudentId.
@Override
public AttendanceResult deleteAttendanceResultByAttendanceAndStudentId(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);
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() < 1)
throw new GradingFactorDaoException("No result to delete");
AttendanceResult result = (AttendanceResult) query.list().get(0);
session.delete(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 AttendanceDaoImpl method getAttendanceResultById.
@Override
public AttendanceResult getAttendanceResultById(long id) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
AttendanceResult result = session.get(AttendanceResult.class, id);
if (result == null)
throw new GradingFactorDaoException("AttendanceResult with id : " + id + " does not exist");
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 QuizDaoImpl method addQuiz.
@Override
public Quiz addQuiz(Quiz quiz, long classId, long termId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Class _class = session.get(Class.class, classId);
Term term = session.get(Term.class, termId);
if (quiz == null)
throw new GradingFactorDaoException("You tried to add class with a null value");
if (termId < 1)
throw new GradingFactorDaoException("Query param : termId has an invalid input");
if (_class == null)
throw new GradingFactorDaoException("Quiz's class with id : " + classId + " does not exist");
if (term == null)
throw new GradingFactorDaoException("Quiz's term with id : " + termId + " does not exist");
if (quiz.getTitle() == null)
throw new GradingFactorDaoException("Quiz's title is required");
if (quiz.getTitle().trim().equals(""))
throw new GradingFactorDaoException("Quiz can't have an empty title");
if (quiz.getDate() == null)
throw new GradingFactorDaoException("Quiz's date is required");
if (quiz.getDate().trim().equals(""))
throw new GradingFactorDaoException("Quiz can't have an empty date");
if (quiz.getItemTotal() < 0)
throw new GradingFactorDaoException("Quiz's itemTotal is invalid");
quiz.set_class(_class);
quiz.setTerm(term);
session.persist(quiz);
session.getTransaction().commit();
session.close();
return quiz;
} 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 QuizDaoImpl method updateQuizById.
@Override
public Quiz updateQuizById(long id, Quiz newQuiz, long classId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Quiz quiz = session.get(Quiz.class, id);
Class _class = session.get(Class.class, classId);
if (newQuiz == null)
newQuiz = new Quiz();
if (quiz == null)
throw new GradingFactorDaoException("Quiz with id : " + id + " does not exist");
if (_class == null && classId != 0)
throw new GradingFactorDaoException("Quiz's class with id : " + classId + " does not exist");
if (!(newQuiz.getTitle() != null ? newQuiz.getTitle() : "").trim().isEmpty())
quiz.setTitle(newQuiz.getTitle());
if (!(newQuiz.getDate() != null ? newQuiz.getDate() : "").trim().isEmpty())
quiz.setDate(newQuiz.getDate());
if (classId > 0) {
if (classId == (quiz.get_class() != null ? quiz.get_class().getId() : 0))
throw new GradingFactorDaoException("Quiz's class with id : " + classId + " already exist");
quiz.set_class(_class);
}
session.getTransaction().commit();
session.close();
return quiz;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
Aggregations