use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class GradeDaoImpl method updateGradeById.
@Override
public Grade updateGradeById(long id, Grade newGrade) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Grade grade = session.get(Grade.class, id);
if (newGrade == null)
newGrade = new Grade();
if (grade == null)
throw new GradingFactorDaoException("Grade with id : " + id + " doesn't exist.");
if (newGrade.getTotalScore() >= 0 && grade.getTotalScore() > 0)
grade.setTotalScore(newGrade.getTotalScore());
if (newGrade.getActivityScore() > 0 && grade.getActivityScore() > 0)
grade.setActivityScore(newGrade.getActivityScore());
if (newGrade.getAssignmentScore() > 0 && grade.getAssignmentScore() > 0)
grade.setAssignmentScore(newGrade.getAssignmentScore());
if (newGrade.getAttendanceScore() > 0 && grade.getAttendanceScore() > 0)
grade.setAttendanceScore(newGrade.getAttendanceScore());
if (newGrade.getExamScore() > 0 && grade.getExamScore() > 0)
grade.setExamScore(newGrade.getExamScore());
if (newGrade.getProjectScore() > 0 && grade.getProjectScore() > 0)
grade.setProjectScore(newGrade.getProjectScore());
if (newGrade.getQuizScore() > 0 && grade.getQuizScore() > 0)
grade.setQuizScore(newGrade.getQuizScore());
session.getTransaction().commit();
session.close();
return grade;
} 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 GradeDaoImpl method deleteGradeById.
@Override
public Grade deleteGradeById(long id) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Grade grade = session.get(Grade.class, id);
if (grade == null)
throw new GradingFactorDaoException("Grade with id : " + id + " doesn't exist.");
session.delete(grade);
session.getTransaction().commit();
session.close();
return grade;
} 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 addProjectResult.
@Override
public ProjectResult addProjectResult(int score, long projectId, long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Project project = session.get(Project.class, projectId);
Student student = session.get(Student.class, studentId);
ProjectResult result = new ProjectResult();
String hql = "from ProjectResult as R where R.project.id = :projectId and R.student.id = :studentId";
Query query = session.createQuery(hql);
query.setParameter("projectId", projectId);
query.setParameter("studentId", studentId);
if (project == null)
throw new GradingFactorDaoException("Project's project with id : " + projectId + " does not exist");
if (student == null)
throw new GradingFactorDaoException("Project's student with id : " + studentId + " does not exist");
if (projectId < 1)
throw new GradingFactorDaoException("Query param : projectId is required");
if (studentId < 1)
throw new GradingFactorDaoException("Query param : studentId is required");
if (score < 0 && score > project.getItemTotal())
throw new GradingFactorDaoException("ProjectResult's score is invalid");
if (query.list().size() > 0)
throw new GradingFactorDaoException("ProjectResult's student with id : " + studentId + " already exist");
result.setScore(score);
result.setProject(project);
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 ProjectDaoImpl method getProjectResultByProjectAndStudentId.
@Override
public ProjectResult getProjectResultByProjectAndStudentId(long projectId, long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Project project = session.get(Project.class, projectId);
Student student = session.get(Student.class, studentId);
String hql = "from ProjectResult as R where R.project.id = :projectId and R.student.id = :studentId";
Query query = session.createQuery(hql);
query.setParameter("projectId", projectId);
query.setParameter("studentId", studentId);
if (project == null)
throw new GradingFactorDaoException("Project with id : " + projectId + " does not exist");
if (student == null)
throw new GradingFactorDaoException("Project's student with id : " + studentId + " does not exist");
if (query.list().size() < 1)
throw new GradingFactorDaoException("No ProjectResult found. Try use query param " + "(ex. studentId=[id])");
ProjectResult result = (ProjectResult) 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 QuizDaoImpl method getQuizListByStudentId.
@Override
public List<Quiz> getQuizListByStudentId(long studentId, long termId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Student student = session.get(Student.class, studentId);
Term term = session.get(Term.class, termId);
List<Quiz> quizList = new ArrayList<>();
String hql = "from QuizResult as R join R.quiz as A where R.student.id = :studentId and " + "A.term.id = :termId";
if (term == null)
throw new GradingFactorDaoException("Quiz's term with id : " + termId + " does not exist");
if (student == null)
throw new GradingFactorDaoException("Quiz's student with id : " + studentId + " does not exist");
Query query = session.createQuery(hql);
query.setParameter("studentId", studentId);
query.setParameter("termId", termId);
for (Object object : query.list()) quizList.add((Quiz) ((Object[]) object)[1]);
session.getTransaction().commit();
session.close();
return quizList;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
Aggregations