use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.
the class ProjectDaoImpl method updateProjectById.
@Override
public Project updateProjectById(long id, Project newProject, long classId, long termId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Project project = session.get(Project.class, id);
Class _class = session.get(Class.class, classId);
Term term = session.get(Term.class, termId);
if (newProject == null)
newProject = new Project();
if (project == null)
throw new GradingFactorDaoException("Project with id : " + id + " does not exist");
if (_class == null && classId != 0)
throw new GradingFactorDaoException("Project's class with id : " + classId + " does not exist");
if (term == null && termId > 0)
throw new GradingFactorDaoException("Project's term with id : " + termId + " does not exist");
if (!(newProject.getTitle() != null ? newProject.getTitle() : "").trim().isEmpty())
project.setTitle(newProject.getTitle());
if (!(newProject.getDate() != null ? newProject.getDate() : "").trim().isEmpty())
project.setDate(newProject.getDate());
if (classId > 0) {
if (classId == (project.get_class() != null ? project.get_class().getId() : 0))
throw new GradingFactorDaoException("Project's class with id : " + classId + " already exist");
project.set_class(_class);
}
if (termId > 0) {
if (termId != (project.getTerm() != null ? project.getTerm().getId() : 0))
project.setTerm(term);
}
session.getTransaction().commit();
session.close();
return project;
} 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 AttendanceDaoImpl method updateAttendanceById.
@Override
public Attendance updateAttendanceById(long id, Attendance newAttendance, long classId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Attendance attendance = session.get(Attendance.class, id);
Class _class = session.get(Class.class, classId);
if (newAttendance == null)
newAttendance = new Attendance();
if (attendance == null)
throw new GradingFactorDaoException("Attendance with id : " + id + " does not exist");
if (_class == null && classId != 0)
throw new GradingFactorDaoException("Attendance's class with id : " + classId + " does not exist");
if (!(newAttendance.getTitle() != null ? newAttendance.getTitle() : "").trim().isEmpty())
attendance.setTitle(newAttendance.getTitle());
if (!(newAttendance.getDate() != null ? newAttendance.getDate() : "").trim().isEmpty())
attendance.setDate(newAttendance.getDate());
if (classId > 0) {
if (classId == (attendance.get_class() != null ? attendance.get_class().getId() : 0))
throw new GradingFactorDaoException("Attendance's class with id : " + classId + " already exist");
attendance.set_class(_class);
}
session.getTransaction().commit();
session.close();
return attendance;
} 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 ClassDaoImpl method getClassById.
@Override
public Class getClassById(long id) throws ClassException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Class _class = session.get(Class.class, id);
if (_class == null)
throw new ClassDaoException("Class with id : " + id + " does not exist");
session.getTransaction().commit();
session.close();
return _class;
} 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 updateClassById.
@Override
public Class updateClassById(long id, Class newClass, long teacherId, long subjectId, long sectionId) throws ClassException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Class _class = session.get(Class.class, id);
if (_class == null)
throw new ClassDaoException("Class with id : " + id + " does not exist");
if (teacherId != 0) {
Teacher teacher = teacherDao.getTeacherById(teacherId);
if ((_class.getTeacher() != null ? _class.getTeacher().getId() : 0) == teacher.getId())
throw new ClassDaoException("Can't update class's teacher with same teacher");
_class.setTeacher(teacher);
}
if (subjectId != 0) {
Subject subject = subjectDao.getSubjectById(subjectId);
if ((_class.getSubject() != null ? _class.getSubject().getId() : 0) == subject.getId())
throw new ClassDaoException("Can't update class's subject with same subject");
_class.setSubject(subject);
}
if (sectionId != 0) {
Section section = sectionDao.getSectionById(sectionId);
if ((_class.getSection() != null ? _class.getSection().getId() : 0) == section.getId())
throw new ClassDaoException("Can't update class's section with same section");
_class.setSection(section);
}
_class = (Class) session.merge(_class);
session.getTransaction().commit();
session.close();
return _class;
} catch (ClassDaoException | TeacherException | SubjectException | SectionException 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 deleteScheduleById.
@Override
public Schedule deleteScheduleById(long classId, long id) throws ClassException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Class _class = session.get(Class.class, classId);
Schedule schedule = null;
if (_class == null)
throw new ClassDaoException("Class with id : " + classId + " does not exist");
for (Schedule s : _class.getScheduleList()) {
if (s.getId() == id) {
_class.getScheduleList().remove(s);
schedule = s;
break;
}
}
if (schedule == null)
throw new ClassDaoException("Class's schedule with id : " + id + " does not exist");
session.getTransaction().commit();
session.close();
return schedule;
} catch (ClassDaoException e) {
session.close();
throw new ClassException(e.getMessage());
}
}
Aggregations