use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.
the class SectionDaoImpl method deleteSectionById.
@Override
public Section deleteSectionById(long id) throws SectionException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Section section = session.get(Section.class, id);
if (section == null)
throw new SectionDaoException("Section with id : " + id + " does not exist");
// to avoid the constraints restriction we meed to remove section from the student that having the section
Query studentQuery = session.createQuery("from Student");
for (Object studentObj : studentQuery.list()) {
Student student = (Student) studentObj;
if (student.getSection() == null)
continue;
if (student.getSection().equals(section) || (student.getSection() != null ? student.getSection().getId() : 0) == section.getId()) {
student.setSection(null);
}
}
// to avoid the constraints restriction we meed to remove section from the class that having the section
Query classQuery = session.createQuery("from Class");
for (Object classObj : classQuery.list()) {
Class _class = (Class) classObj;
if (_class.getSection() == null)
continue;
if (_class.getSection().equals(section) || (_class.getSection() != null ? _class.getSection().getId() : 0) == section.getId()) {
_class.setSection(null);
}
}
section.setDepartment(null);
session.delete(section);
session.getTransaction().commit();
session.close();
return section;
} catch (SectionDaoException e) {
session.close();
throw new SectionException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.
the class StudentDaoImpl method deleteStudentById.
@Override
public Student deleteStudentById(long id) throws StudentException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Student student = session.get(Student.class, id);
String[] table = new String[8];
table[0] = ActivityResult.class.getSimpleName();
table[1] = AssignmentResult.class.getSimpleName();
table[2] = AttendanceResult.class.getSimpleName();
table[3] = ExamResult.class.getSimpleName();
table[4] = ProjectResult.class.getSimpleName();
table[5] = QuizResult.class.getSimpleName();
table[6] = RecitationResult.class.getSimpleName();
table[7] = Grade.class.getSimpleName();
if (student == null)
throw new StudentDaoException("Student with id : " + id + " does not exist.");
for (String cell : table) {
String hql = "delete from ".concat(cell).concat(" where student.id = :studentId");
Query query = session.createQuery(hql);
query.setParameter("studentId", id);
query.executeUpdate();
}
Query classQuery = session.createQuery("from Class");
for (Object classObj : classQuery.list()) {
Class _class = (Class) classObj;
_class = session.get(Class.class, _class.getId());
for (Student s : _class.getStudentList()) {
if (s == null)
continue;
if (s.getId() == id) {
_class.getStudentList().remove(s);
break;
}
}
}
String hql = "";
student.setSection(null);
session.delete(student);
session.getTransaction().commit();
session.close();
return student;
} catch (StudentDaoException e) {
session.close();
throw new StudentException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.
the class ExamDaoImpl method updateExamById.
@Override
public Exam updateExamById(long id, Exam newExam, long classId, long termId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Exam exam = session.get(Exam.class, id);
Class _class = session.get(Class.class, classId);
Term term = session.get(Term.class, termId);
if (newExam == null)
newExam = new Exam();
if (exam == null)
throw new GradingFactorDaoException("Exam with id : " + id + " does not exist");
if (_class == null && classId != 0)
throw new GradingFactorDaoException("Exam's class with id : " + classId + " does not exist");
if (term == null && termId > 0)
throw new GradingFactorDaoException("Exam's term with id : " + termId + " does not exist");
if (!(newExam.getTitle() != null ? newExam.getTitle() : "").trim().isEmpty())
exam.setTitle(newExam.getTitle());
if (!(newExam.getDate() != null ? newExam.getDate() : "").trim().isEmpty())
exam.setDate(newExam.getDate());
if (classId > 0) {
if (classId == (exam.get_class() != null ? exam.get_class().getId() : 0))
throw new GradingFactorDaoException("Exam's class with id : " + classId + " already exist");
exam.set_class(_class);
}
if (termId > 0) {
if (termId != (exam.getTerm() != null ? exam.getTerm().getId() : 0))
exam.setTerm(term);
}
session.getTransaction().commit();
session.close();
return exam;
} 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 GradeDaoImpl method addGrade.
@Override
public Grade addGrade(Grade grade, long classId, long studentId, long termId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Class _class = session.get(Class.class, classId);
Student student = session.get(Student.class, studentId);
Term term = session.get(Term.class, termId);
if (grade == null)
throw new GradingFactorDaoException("You tried to add grade with a null value");
if (grade.getTotalScore() < 0)
throw new GradingFactorDaoException("Grade's total score is not valid");
if (grade.getActivityScore() < 0)
throw new GradingFactorDaoException("Grade's activity score is not valid");
if (grade.getAssignmentScore() < 0)
throw new GradingFactorDaoException("Grade's assignment score is not valid");
if (grade.getAttendanceScore() < 0)
throw new GradingFactorDaoException("Grade's attendance score is not valid");
if (grade.getExamScore() < 0)
throw new GradingFactorDaoException("Grade's exam score is not valid");
if (grade.getProjectScore() < 0)
throw new GradingFactorDaoException("Grade's project score is not valid");
if (grade.getQuizScore() < 0)
throw new GradingFactorDaoException("Grade's quiz score is not valid");
if (classId < 1)
throw new GradingFactorDaoException("Query param : classId is required.");
if (studentId < 1)
throw new GradingFactorDaoException("Query param : studentId is required.");
if (termId < 1)
throw new GradingFactorDaoException("Query param : termId is required.");
if (_class == null)
throw new GradingFactorDaoException("Class with id : " + classId + " doesn't exist.");
if (student == null)
throw new GradingFactorDaoException("Student with id : " + studentId + " doesn't exist.");
if (term == null)
throw new GradingFactorDaoException("Term with id : " + termId + " doesn't exist.");
grade.set_class(_class);
grade.setStudent(student);
grade.setTerm(term);
session.persist(grade);
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 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());
}
}
Aggregations