use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class GradeDaoImpl method getGradeListByClass.
@Override
public List<Grade> getGradeListByClass(long classId, long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Grade> gradeList = new ArrayList<>();
String hql = "from Grade as G where G._class.id = :classId and G.student.id = :studentId";
Query query = session.createQuery(hql);
query.setParameter("classId", classId);
query.setParameter("studentId", studentId);
for (Object object : query.list()) gradeList.add((Grade) object);
session.getTransaction().commit();
session.close();
return gradeList;
} 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 updateGrade.
@Override
public Grade updateGrade(long id, Grade newGrade, long classId, long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Grade grade = session.get(Grade.class, id);
Class _class = session.get(Class.class, classId);
Student student = session.get(Student.class, studentId);
if (newGrade == null)
newGrade = new Grade();
if (grade == null)
throw new GradingFactorDaoException("Grade with id : " + id + " doesn't exist.");
if (_class == null && classId != 0)
throw new GradingFactorDaoException("Class with id : " + classId + " doesn't exist.");
if (student == null && studentId != 0)
throw new GradingFactorDaoException("Student with id : " + studentId + " doesn't exist.");
if (classId < 0)
throw new GradingFactorDaoException("The class id is invalid");
if (studentId < 0)
throw new GradingFactorDaoException("The student id is invalid");
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());
if (classId > 0) {
if ((grade.get_class() != null ? grade.get_class().getId() : 0) == classId)
throw new GradingFactorDaoException("The class id is already exist");
grade.set_class(_class);
}
if (studentId > 0) {
if ((grade.getStudent() != null ? grade.getStudent().getId() : 0) == studentId)
throw new GradingFactorDaoException("The student id is already exist");
grade.setStudent(student);
}
grade.set_class(_class);
grade.setStudent(student);
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 getGradeListByStudentId.
@Override
public List<Grade> getGradeListByStudentId(long studentId, long termId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Grade> gradeList = new ArrayList<>();
String hql = "from Grade as G where G.student.id = :studentId and G.term.id = :termId";
Query query = session.createQuery(hql);
query.setParameter("studentId", studentId);
query.setParameter("termId", termId);
for (Object object : query.list()) gradeList.add((Grade) object);
session.getTransaction().commit();
session.close();
return gradeList;
} 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 getGradeById.
@Override
public Grade getGradeById(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.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 updateProjectResultByProjectAndStudentId.
@Override
public ProjectResult updateProjectResultByProjectAndStudentId(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);
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 (query.list().size() < 1)
throw new GradingFactorDaoException("No result to delete");
ProjectResult result = (ProjectResult) query.list().get(0);
result.setScore(score);
session.getTransaction().commit();
session.close();
return result;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
Aggregations