use of com.remswork.project.alice.model.Student in project classify-system by anverliedoit.
the class ClassStudentListResource method getStudentById.
@GET
@Path("{studentId}")
public Response getStudentById(@PathParam("classId") long classId, @PathParam("studentId") long id) {
try {
ClassStudentListResourceLinks resourceLinks = new ClassStudentListResourceLinks(uriInfo);
Student student = classService.getStudentById(classId, id);
student.addLink(resourceLinks.self(classId, id));
return Response.status(Response.Status.OK).entity(student).build();
} catch (ClassException e) {
e.printStackTrace();
Message message = new Message(404, "Not Found", e.getMessage());
return Response.status(Response.Status.NOT_FOUND).entity(message).build();
}
}
use of com.remswork.project.alice.model.Student in project classify-system by anverliedoit.
the class ClassStudentListResource method getStudentList.
@GET
public Response getStudentList(@PathParam("classId") long classId) {
try {
ClassStudentListResourceLinks resourceLinks = new ClassStudentListResourceLinks(uriInfo);
Set<Student> studentSet = classService.getStudentList(classId);
for (Student student : studentSet) student.addLink(resourceLinks.self(classId, student.getId()));
GenericEntity<Set<Student>> entity = new GenericEntity<Set<Student>>(studentSet) {
};
return Response.status(Response.Status.OK).entity(entity).build();
} catch (ClassException e) {
e.printStackTrace();
Message message = new Message(404, "Not Found", e.getMessage());
return Response.status(Response.Status.NOT_FOUND).entity(message).build();
}
}
use of com.remswork.project.alice.model.Student in project classify-system by anverliedoit.
the class ClassStudentListResource method deleteStudentById.
@DELETE
@Path("{studentId}")
public Response deleteStudentById(@PathParam("classId") long classId, @PathParam("studentId") long id) {
try {
ClassStudentListResourceLinks resourceLinks = new ClassStudentListResourceLinks(uriInfo);
Student student = classService.deleteStudentById(classId, id);
student.addLink(resourceLinks.self(classId, id));
return Response.status(Response.Status.OK).entity(student).build();
} catch (ClassException 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.model.Student in project classify-system by anverliedoit.
the class StudentResource method getStudentList.
@GET
public Response getStudentList() {
try {
StudentResourceLinks resourceLinks = new StudentResourceLinks(uriInfo);
SectionResourceLinks sectionResourceLinks = new SectionResourceLinks(uriInfo);
DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
List<Student> studentList = studentService.getStudentList();
if (sn == null) {
for (Student student : studentList) {
student.addLink(resourceLinks.self(student.getId()));
if (student.getSection() != null) {
Section section = student.getSection();
section.addLink(sectionResourceLinks.self(section.getId()));
if (section.getDepartment() != null)
section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
}
}
GenericEntity<List<Student>> entity = new GenericEntity<List<Student>>(studentList) {
};
return Response.status(Response.Status.OK).entity(entity).build();
} else {
Student student = studentService.getStudentBySN(sn);
if (student.getSection() != null) {
Section section = student.getSection();
section.addLink(sectionResourceLinks.self(section.getId()));
if (section.getDepartment() != null) {
section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
}
}
return Response.status(Response.Status.OK).entity(student).build();
}
} catch (StudentException e) {
e.printStackTrace();
Message message = new Message(404, "Not Found", e.getMessage());
return Response.status(Response.Status.NOT_FOUND).entity(message).build();
}
}
use of com.remswork.project.alice.model.Student 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());
}
}
Aggregations