use of com.remswork.project.alice.exception.StudentException 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.exception.StudentException in project classify-system by anverliedoit.
the class StudentDaoImpl method addStudent.
@Override
public Student addStudent(Student student, long sectionId) throws StudentException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
if (student == null)
throw new StudentDaoException("You tried to add student with a null value");
if (student.getStudentNumber() == 0)
throw new StudentDaoException("Student's studentnumber is required");
if (student.getFirstName() == null)
throw new StudentDaoException("Student's first name is required");
if (student.getFirstName().trim().equals(""))
throw new StudentDaoException("Student can't have an empty first name");
if (student.getLastName() == null)
throw new StudentDaoException("Student's last name is required");
if (student.getLastName().trim().equals(""))
throw new StudentDaoException("Student can't have an empty last name");
if (student.getMiddleName() == null)
throw new StudentDaoException("Student's middle name is required");
if (student.getMiddleName().trim().equals(""))
throw new StudentDaoException("Student can't have an empty middle name");
if (student.getGender() == null)
throw new StudentDaoException("Student's gender is required");
if (student.getGender().trim().equals(""))
throw new StudentDaoException("Student can't have an empty gender");
if (!(student.getGender().trim().equalsIgnoreCase("Male") || student.getGender().trim().equalsIgnoreCase("Female")))
throw new StudentDaoException("Student's gender is invalid");
if (student.getAge() == 0)
throw new StudentDaoException("Student's age is required");
if (student.getAge() <= 14 || student.getAge() > 60)
throw new StudentDaoException("Student's age is invalid. " + "The minimum age is 14 and the maximum age is 60");
if (sectionId > 0) {
Section section = sectionDao.getSectionById(sectionId);
student.setSection(section);
} else
student.setSection(null);
student = (Student) session.merge(student);
session.getTransaction().commit();
session.close();
return student;
} catch (StudentDaoException | SectionException e) {
session.close();
throw new StudentException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.StudentException in project classify-system by anverliedoit.
the class StudentDaoImpl method deleteStudentById.
@Override
public Student deleteStudentById(long id) throws StudentException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Student student = session.get(Student.class, id);
String[] table = new String[8];
table[0] = ActivityResult.class.getSimpleName();
table[1] = AssignmentResult.class.getSimpleName();
table[2] = AttendanceResult.class.getSimpleName();
table[3] = ExamResult.class.getSimpleName();
table[4] = ProjectResult.class.getSimpleName();
table[5] = QuizResult.class.getSimpleName();
table[6] = RecitationResult.class.getSimpleName();
table[7] = Grade.class.getSimpleName();
if (student == null)
throw new StudentDaoException("Student with id : " + id + " does not exist.");
for (String cell : table) {
String hql = "delete from ".concat(cell).concat(" where student.id = :studentId");
Query query = session.createQuery(hql);
query.setParameter("studentId", id);
query.executeUpdate();
}
Query classQuery = session.createQuery("from Class");
for (Object classObj : classQuery.list()) {
Class _class = (Class) classObj;
_class = session.get(Class.class, _class.getId());
for (Student s : _class.getStudentList()) {
if (s == null)
continue;
if (s.getId() == id) {
_class.getStudentList().remove(s);
break;
}
}
}
String hql = "";
student.setSection(null);
session.delete(student);
session.getTransaction().commit();
session.close();
return student;
} catch (StudentDaoException e) {
session.close();
throw new StudentException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.StudentException in project classify-system by anverliedoit.
the class StudentDaoImpl method getStudentBySN.
public Student getStudentBySN(long sn) throws StudentException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Query query = session.createQuery("from Student as s where s.studentNumber=:sn");
query.setParameter("sn", sn);
Student student = null;
if (query.list().size() > 0) {
student = (Student) query.list().get(0);
}
if (student == null)
throw new StudentDaoException("Student with sn : " + sn + " does not exist");
session.getTransaction().commit();
session.close();
return student;
} catch (StudentDaoException e) {
session.close();
throw new StudentException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.StudentException in project classify-system by anverliedoit.
the class StudentDaoImpl method getStudentById.
@Override
public Student getStudentById(long id) throws StudentException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Student student = session.get(Student.class, id);
if (student == null)
throw new StudentDaoException("Student with id : " + id + " does not exist");
session.getTransaction().commit();
session.close();
return student;
} catch (StudentDaoException e) {
session.close();
throw new StudentException(e.getMessage());
}
}
Aggregations