use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.
the class AssignmentDaoImpl method getAssignmentList.
@Override
public List<Assignment> getAssignmentList() throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Assignment> assignmentList = new ArrayList<>();
Query query = session.createQuery("from Assignment");
for (Object objAssignment : query.list()) assignmentList.add((Assignment) objAssignment);
session.getTransaction().commit();
session.close();
return assignmentList;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.
the class AttendanceDaoImpl method getAttendanceListByStudentId.
@Override
public List<Attendance> getAttendanceListByStudentId(long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Student student = session.get(Student.class, studentId);
List<Attendance> attendanceList = new ArrayList<>();
String hql = "from AttendanceResult as R join R.attendance where R.student.id = :studentId";
if (student == null)
throw new GradingFactorDaoException("Attendance's student with id : " + studentId + " does not exist");
Query query = session.createQuery(hql);
query.setParameter("studentId", studentId);
for (Object object : query.list()) attendanceList.add((Attendance) ((Object[]) object)[1]);
session.getTransaction().commit();
session.close();
return attendanceList;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.
the class AttendanceDaoImpl method updateAttendanceResultByAttendanceAndStudentId.
@Override
public AttendanceResult updateAttendanceResultByAttendanceAndStudentId(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);
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);
result.setStatus(status);
session.getTransaction().commit();
session.close();
return result;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.
the class AttendanceDaoImpl method deleteAttendanceById.
@Override
public Attendance deleteAttendanceById(long id) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
String[] table = new String[1];
table[0] = AttendanceResult.class.getSimpleName();
Attendance attendance = session.get(Attendance.class, id);
if (attendance == null)
throw new GradingFactorDaoException("Attendance with id : " + id + " does not exist");
for (String cell : table) {
String hql = "delete from ".concat(cell).concat(" where attendance.id = :attendanceId");
Query query = session.createQuery(hql);
query.setParameter("attendanceId", id);
query.executeUpdate();
}
session.delete(attendance);
session.getTransaction().commit();
session.close();
return attendance;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.
the class ActivityDaoImpl method updateActivityById.
@Override
public Activity updateActivityById(long id, Activity newActivity, long classId, long termId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Activity activity = session.get(Activity.class, id);
Class _class = session.get(Class.class, classId);
Term term = session.get(Term.class, termId);
if (newActivity == null)
newActivity = new Activity();
if (activity == null)
throw new GradingFactorDaoException("Activity with id : " + id + " does not exist");
if (_class == null && classId != 0)
throw new GradingFactorDaoException("Activity's class with id : " + classId + " does not exist");
if (term == null && termId > 0)
throw new GradingFactorDaoException("Activity's term with id : " + termId + " does not exist");
if (!(newActivity.getTitle() != null ? newActivity.getTitle() : "").trim().isEmpty())
activity.setTitle(newActivity.getTitle());
if (!(newActivity.getDate() != null ? newActivity.getDate() : "").trim().isEmpty())
activity.setDate(newActivity.getDate());
if (classId > 0) {
if (classId == (activity.get_class() != null ? activity.get_class().getId() : 0))
throw new GradingFactorDaoException("Activity's class with id : " + classId + " already exist");
activity.set_class(_class);
}
if (termId > 0) {
if (termId != (activity.getTerm() != null ? activity.getTerm().getId() : 0))
activity.setTerm(term);
}
session.getTransaction().commit();
session.close();
return activity;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
Aggregations