use of com.remswork.project.alice.dao.exception.ClassDaoException 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.dao.exception.ClassDaoException 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.dao.exception.ClassDaoException 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.dao.exception.ClassDaoException in project classify-system by anverliedoit.
the class ClassStudentListResource method addStudentById.
@POST
public Response addStudentById(@PathParam("classId") long classId) {
try {
ClassStudentListResourceLinks resourceLinks = new ClassStudentListResourceLinks(uriInfo);
if (studentId == 0)
throw new ClassDaoException("Query param : studentId is required");
Student student = classService.addStudentById(classId, studentId);
student.addLink(resourceLinks.self(classId, studentId));
return Response.status(Response.Status.OK).entity(student).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();
}
}
Aggregations