use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.
the class GradeDaoImpl method getGradeList.
@Override
public List<Grade> getGradeList() throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Grade> gradeList = new ArrayList<>();
Query query = session.createQuery("from Grade");
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.exception.GradingFactorException 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.exception.GradingFactorException 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.exception.GradingFactorException 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.exception.GradingFactorException 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());
}
}
Aggregations