use of com.remswork.project.alice.dao.exception.ClassDaoException in project classify-system by anverliedoit.
the class ClassScheduleListResource method addScheduleById.
@POST
public Response addScheduleById(@PathParam("classId") long classId) {
try {
ClassScheduleListResourceLinks resourceLinks = new ClassScheduleListResourceLinks(uriInfo);
if (scheduleId == 0)
throw new ClassDaoException("Query param : scheduleId is required");
Schedule schedule = classService.addScheduleById(classId, scheduleId);
schedule.addLink(resourceLinks.self(classId, scheduleId));
return Response.status(Response.Status.OK).entity(schedule).build();
} catch (ClassException | ClassDaoException e) {
e.printStackTrace();
Message message = new Message(400, "Bad Request", e.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
}
}
use of com.remswork.project.alice.dao.exception.ClassDaoException in project classify-system by anverliedoit.
the class ScheduleDaoImpl method getScheduleListByTeacherId.
@Override
public Set<Schedule> getScheduleListByTeacherId(long teacherId) throws ScheduleException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Set<Schedule> scheduleSet = new HashSet<>();
String hql = "from Class as c join c.scheduleList as s join c.teacher as t where t.id = :teacherId";
Query query = session.createQuery(hql);
query.setParameter("teacherId", teacherId);
for (Object list : query.list()) {
Object[] row = (Object[]) list;
scheduleSet.add((Schedule) row[1]);
}
session.getTransaction().commit();
session.close();
return scheduleSet;
} catch (ClassDaoException e) {
session.close();
throw new ScheduleException(e.getMessage());
}
}
use of com.remswork.project.alice.dao.exception.ClassDaoException 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.dao.exception.ClassDaoException 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.dao.exception.ClassDaoException 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