use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.
the class ClassDaoImpl method getStudentList.
@Override
public Set<Student> getStudentList(long classId) throws ClassException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Class _class = session.get(Class.class, classId);
if (_class == null)
throw new ClassDaoException("Class with id : " + classId + " does not exist");
Set<Student> studentSet = _class.getStudentList();
session.getTransaction().commit();
session.close();
return studentSet;
} catch (ClassDaoException e) {
session.close();
throw new ClassException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.
the class ClassDaoImpl method deleteStudentById.
@Override
public Student deleteStudentById(long classId, long id) throws ClassException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Class _class = session.get(Class.class, classId);
Student student = null;
if (_class == null)
throw new ClassDaoException("Class with id : " + classId + " does not exist");
for (Student s : _class.getStudentList()) {
if (s.getId() == id) {
_class.getStudentList().remove(s);
student = s;
break;
}
}
if (student == null)
throw new ClassDaoException("Class's student with id : " + id + " does not exist");
session.getTransaction().commit();
session.close();
return student;
} catch (ClassDaoException e) {
session.close();
throw new ClassException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.
the class ClassDaoImpl method getClassListByStudentId.
@Override
public List<Class> getClassListByStudentId(long studentId) throws ClassException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Class> classList = new ArrayList<>();
Query query = session.createQuery("from Class as c join c.studentList as st where st.id = :studentId");
query.setParameter("studentId", studentId);
for (Object classObject : query.list()) classList.add((Class) ((Object[]) classObject)[0]);
session.getTransaction().commit();
session.close();
return classList;
} catch (ClassDaoException e) {
session.close();
throw new ClassException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.
the class DepartmentDaoImpl method deleteDepartmentById.
@Override
public Department deleteDepartmentById(long id) throws DepartmentException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Department department = session.get(Department.class, id);
if (department == null)
throw new DepartmentDaoException("Department with id : " + id + " does not exist.");
// to avoid the constraints restriction we meed to remove department from the teacher
// that having the department
Query teacherQuery = session.createQuery("from Teacher");
for (Object teacherObj : teacherQuery.list()) {
Teacher teacher = (Teacher) teacherObj;
if (teacher.getDepartment() == null)
continue;
if (teacher.getDepartment().equals(department) || (teacher.getDepartment() != null ? teacher.getDepartment().getId() : 0) == department.getId()) {
teacher.setDepartment(null);
}
}
// to avoid the constraints restriction we meed to delete the section that having the department
Query sectionQuery = session.createQuery("from Section");
for (Object sectionObj : sectionQuery.list()) {
Section section = (Section) sectionObj;
if (section.getDepartment() == null)
continue;
if (section.getDepartment().equals(department) || (section.getDepartment() != null ? section.getDepartment().getId() : 0) == department.getId()) {
session.delete(section);
}
}
// to avoid the constraints restriction we meed to remove department from the class's teacher and section
// that having the department
Query classQuery = session.createQuery("from Class");
for (Object classObj : classQuery.list()) {
Class _class = (Class) classObj;
Teacher teacher = _class.getTeacher();
Section section = _class.getSection();
if (teacher != null) {
if (teacher.getDepartment() != null) {
if (teacher.getDepartment().equals(department) || (teacher.getDepartment() != null ? teacher.getDepartment().getId() : 0) == department.getId()) {
teacher.setDepartment(null);
}
}
}
if (section != null) {
if (section.getDepartment() != null) {
if (section.getDepartment().equals(department) || (section.getDepartment() != null ? section.getDepartment().getId() : 0) == department.getId()) {
_class.setSection(null);
}
}
}
}
session.delete(department);
session.getTransaction().commit();
session.close();
return department;
} catch (DepartmentDaoException e) {
session.close();
throw new DepartmentException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.
the class ExamDaoImpl method addExam.
@Override
public Exam addExam(Exam exam, long classId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Class _class = session.get(Class.class, classId);
if (exam == 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("Exam's class with id : " + classId + " does not exist");
if (exam.getTitle() == null)
throw new GradingFactorDaoException("Exam's title is required");
if (exam.getTitle().trim().equals(""))
throw new GradingFactorDaoException("Exam can't have an empty title");
if (exam.getDate() == null)
throw new GradingFactorDaoException("Exam's date is required");
if (exam.getDate().trim().equals(""))
throw new GradingFactorDaoException("Exam can't have an empty date");
if (exam.getItemTotal() < 0)
throw new GradingFactorDaoException("Exam's itemTotal is invalid");
exam.set_class(_class);
session.persist(exam);
session.getTransaction().commit();
session.close();
return exam;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
Aggregations