use of com.remswork.project.alice.model.Class 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.model.Class in project classify-system by anverliedoit.
the class AssignmentDaoImpl method addAssignment.
@Override
public Assignment addAssignment(Assignment assignment, long classId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Class _class = session.get(Class.class, classId);
if (assignment == 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("Assignment's class with id : " + classId + " does not exist");
if (assignment.getTitle() == null)
throw new GradingFactorDaoException("Assignment's title is required");
if (assignment.getTitle().trim().equals(""))
throw new GradingFactorDaoException("Assignment can't have an empty title");
if (assignment.getDate() == null)
throw new GradingFactorDaoException("Assignment's date is required");
if (assignment.getDate().trim().equals(""))
throw new GradingFactorDaoException("Assignment can't have an empty date");
if (assignment.getItemTotal() < 0)
throw new GradingFactorDaoException("Assignment's itemTotal is invalid");
assignment.set_class(_class);
session.persist(assignment);
session.getTransaction().commit();
session.close();
return assignment;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.
the class AssignmentDaoImpl method updateAssignmentById.
@Override
public Assignment updateAssignmentById(long id, Assignment newAssignment, long classId, long termId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Assignment assignment = session.get(Assignment.class, id);
Class _class = session.get(Class.class, classId);
Term term = session.get(Term.class, termId);
if (newAssignment == null)
newAssignment = new Assignment();
if (assignment == null)
throw new GradingFactorDaoException("Assignment with id : " + id + " does not exist");
if (_class == null && classId != 0)
throw new GradingFactorDaoException("Assignment's class with id : " + classId + " does not exist");
if (term == null && termId > 0)
throw new GradingFactorDaoException("Assignment's term with id : " + termId + " does not exist");
if (!(newAssignment.getTitle() != null ? newAssignment.getTitle() : "").trim().isEmpty())
assignment.setTitle(newAssignment.getTitle());
if (!(newAssignment.getDate() != null ? newAssignment.getDate() : "").trim().isEmpty())
assignment.setDate(newAssignment.getDate());
if (classId > 0) {
if (classId == (assignment.get_class() != null ? assignment.get_class().getId() : 0))
throw new GradingFactorDaoException("Assignment's class with id : " + classId + " already exist");
assignment.set_class(_class);
}
if (termId > 0) {
if (termId != (assignment.getTerm() != null ? assignment.getTerm().getId() : 0))
assignment.setTerm(term);
}
session.getTransaction().commit();
session.close();
return assignment;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.
the class QuizDaoImpl method addQuiz.
@Override
public Quiz addQuiz(Quiz quiz, long classId, long termId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Class _class = session.get(Class.class, classId);
Term term = session.get(Term.class, termId);
if (quiz == null)
throw new GradingFactorDaoException("You tried to add class with a null value");
if (termId < 1)
throw new GradingFactorDaoException("Query param : termId has an invalid input");
if (_class == null)
throw new GradingFactorDaoException("Quiz's class with id : " + classId + " does not exist");
if (term == null)
throw new GradingFactorDaoException("Quiz's term with id : " + termId + " does not exist");
if (quiz.getTitle() == null)
throw new GradingFactorDaoException("Quiz's title is required");
if (quiz.getTitle().trim().equals(""))
throw new GradingFactorDaoException("Quiz can't have an empty title");
if (quiz.getDate() == null)
throw new GradingFactorDaoException("Quiz's date is required");
if (quiz.getDate().trim().equals(""))
throw new GradingFactorDaoException("Quiz can't have an empty date");
if (quiz.getItemTotal() < 0)
throw new GradingFactorDaoException("Quiz's itemTotal is invalid");
quiz.set_class(_class);
quiz.setTerm(term);
session.persist(quiz);
session.getTransaction().commit();
session.close();
return quiz;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.
the class QuizDaoImpl method updateQuizById.
@Override
public Quiz updateQuizById(long id, Quiz newQuiz, long classId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Quiz quiz = session.get(Quiz.class, id);
Class _class = session.get(Class.class, classId);
if (newQuiz == null)
newQuiz = new Quiz();
if (quiz == null)
throw new GradingFactorDaoException("Quiz with id : " + id + " does not exist");
if (_class == null && classId != 0)
throw new GradingFactorDaoException("Quiz's class with id : " + classId + " does not exist");
if (!(newQuiz.getTitle() != null ? newQuiz.getTitle() : "").trim().isEmpty())
quiz.setTitle(newQuiz.getTitle());
if (!(newQuiz.getDate() != null ? newQuiz.getDate() : "").trim().isEmpty())
quiz.setDate(newQuiz.getDate());
if (classId > 0) {
if (classId == (quiz.get_class() != null ? quiz.get_class().getId() : 0))
throw new GradingFactorDaoException("Quiz's class with id : " + classId + " already exist");
quiz.set_class(_class);
}
session.getTransaction().commit();
session.close();
return quiz;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
Aggregations