use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.
the class RecitationDaoImpl method getRecitationResultById.
@Override
public RecitationResult getRecitationResultById(long id) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
RecitationResult result = session.get(RecitationResult.class, id);
if (result == null)
throw new GradingFactorDaoException("RecitationResult 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.exception.GradingFactorException in project classify-system by anverliedoit.
the class ProjectDaoImpl method addProject.
@Override
public Project addProject(Project project, long classId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Class _class = session.get(Class.class, classId);
if (project == null)
throw new GradingFactorDaoException("You tried to add class with a null value");
if (classId == 0)
throw new GradingFactorDaoException("Query param : classId is required");
if (_class == null)
throw new GradingFactorDaoException("Project's class with id : " + classId + " does not exist");
if (project.getTitle() == null)
throw new GradingFactorDaoException("Project's title is required");
if (project.getTitle().trim().equals(""))
throw new GradingFactorDaoException("Project can't have an empty title");
if (project.getDate() == null)
throw new GradingFactorDaoException("Project's date is required");
if (project.getDate().trim().equals(""))
throw new GradingFactorDaoException("Project can't have an empty date");
if (project.getItemTotal() < 0)
throw new GradingFactorDaoException("Project's itemTotal is invalid");
project.set_class(_class);
session.persist(project);
session.getTransaction().commit();
session.close();
return project;
} 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 ProjectDaoImpl method getProjectListByClassId.
@Override
public List<Project> getProjectListByClassId(long classId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Project> projectList = new ArrayList<>();
Query query = session.createQuery("from Project where _class.id = :classId");
query.setParameter("classId", classId);
for (Object objProject : query.list()) projectList.add((Project) objProject);
session.getTransaction().commit();
session.close();
return projectList;
} 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 QuizDaoImpl method getQuizResultById.
@Override
public QuizResult getQuizResultById(long id) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
QuizResult result = session.get(QuizResult.class, id);
if (result == null)
throw new GradingFactorDaoException("QuizResult 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.exception.GradingFactorException in project classify-system by anverliedoit.
the class QuizDaoImpl method getQuizResultByQuizAndStudentId.
@Override
public QuizResult getQuizResultByQuizAndStudentId(long quizId, long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Quiz quiz = session.get(Quiz.class, quizId);
Student student = session.get(Student.class, studentId);
String hql = "from QuizResult as R where R.quiz.id = :quizId and R.student.id = :studentId";
Query query = session.createQuery(hql);
query.setParameter("quizId", quizId);
query.setParameter("studentId", studentId);
if (quiz == null)
throw new GradingFactorDaoException("Quiz with id : " + quizId + " does not exist");
if (student == null)
throw new GradingFactorDaoException("Quiz's student with id : " + studentId + " does not exist");
if (query.list().size() < 1)
throw new GradingFactorDaoException("No QuizResult found. Try use query param " + "(ex. studentId=[id])");
QuizResult result = (QuizResult) query.list().get(0);
session.getTransaction().commit();
session.close();
return result;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
Aggregations