use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class ExamDaoImpl method getExamListByStudentId.
@Override
public List<Exam> getExamListByStudentId(long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Student student = session.get(Student.class, studentId);
List<Exam> examList = new ArrayList<>();
String hql = "from ExamResult as R join R.exam where R.student.id = :studentId";
if (student == null)
throw new GradingFactorDaoException("Exam's student with id : " + studentId + " does not exist");
Query query = session.createQuery(hql);
query.setParameter("studentId", studentId);
for (Object object : query.list()) examList.add((Exam) ((Object[]) object)[1]);
session.getTransaction().commit();
session.close();
return examList;
} 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 ExamDaoImpl method deleteExamResultByExamAndStudentId.
@Override
public ExamResult deleteExamResultByExamAndStudentId(long examId, long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Exam exam = session.get(Exam.class, examId);
Student student = session.get(Student.class, studentId);
String hql = "from ExamResult as R where R.exam.id = :examId and R.student.id = :studentId";
Query query = session.createQuery(hql);
query.setParameter("examId", examId);
query.setParameter("studentId", studentId);
if (exam == null)
throw new GradingFactorDaoException("Exam's exam with id : " + examId + " does not exist");
if (student == null)
throw new GradingFactorDaoException("Exam's student with id : " + studentId + " does not exist");
if (examId < 1)
throw new GradingFactorDaoException("Query param : examId 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");
ExamResult result = (ExamResult) 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 ExamDaoImpl method updateExamResultByExamAndStudentId.
@Override
public ExamResult updateExamResultByExamAndStudentId(int score, long examId, long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Exam exam = session.get(Exam.class, examId);
Student student = session.get(Student.class, studentId);
String hql = "from ExamResult as R where R.exam.id = :examId and R.student.id = :studentId";
Query query = session.createQuery(hql);
query.setParameter("examId", examId);
query.setParameter("studentId", studentId);
if (exam == null)
throw new GradingFactorDaoException("Exam's exam with id : " + examId + " does not exist");
if (student == null)
throw new GradingFactorDaoException("Exam's student with id : " + studentId + " does not exist");
if (examId < 1)
throw new GradingFactorDaoException("Query param : examId 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");
ExamResult result = (ExamResult) query.list().get(0);
result.setScore(score);
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 ExamDaoImpl method getExamResultById.
@Override
public ExamResult getExamResultById(long id) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
ExamResult result = session.get(ExamResult.class, id);
if (result == null)
throw new GradingFactorDaoException("ExamResult 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 ProjectDaoImpl method updateProjectById.
@Override
public Project updateProjectById(long id, Project newProject, long classId, long termId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Project project = session.get(Project.class, id);
Class _class = session.get(Class.class, classId);
Term term = session.get(Term.class, termId);
if (newProject == null)
newProject = new Project();
if (project == null)
throw new GradingFactorDaoException("Project with id : " + id + " does not exist");
if (_class == null && classId != 0)
throw new GradingFactorDaoException("Project's class with id : " + classId + " does not exist");
if (term == null && termId > 0)
throw new GradingFactorDaoException("Project's term with id : " + termId + " does not exist");
if (!(newProject.getTitle() != null ? newProject.getTitle() : "").trim().isEmpty())
project.setTitle(newProject.getTitle());
if (!(newProject.getDate() != null ? newProject.getDate() : "").trim().isEmpty())
project.setDate(newProject.getDate());
if (classId > 0) {
if (classId == (project.get_class() != null ? project.get_class().getId() : 0))
throw new GradingFactorDaoException("Project's class with id : " + classId + " already exist");
project.set_class(_class);
}
if (termId > 0) {
if (termId != (project.getTerm() != null ? project.getTerm().getId() : 0))
project.setTerm(term);
}
session.getTransaction().commit();
session.close();
return project;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
Aggregations