Search in sources :

Example 1 with DepartmentException

use of com.remswork.project.alice.exception.DepartmentException in project classify-system by anverliedoit.

the class DepartmentResource method deleteDepartmentById.

@DELETE
@Path("{departmentId}")
public Response deleteDepartmentById(@PathParam("departmentId") long id) {
    try {
        DepartmentResourceLinks resourceLinks = new DepartmentResourceLinks(uriInfo);
        Department department = departmentService.deleteDepartmentById(id);
        department.addLink(resourceLinks.self(id));
        return Response.status(Response.Status.OK).entity(department).build();
    } catch (DepartmentException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : Department(com.remswork.project.alice.model.Department) DepartmentException(com.remswork.project.alice.exception.DepartmentException) Message(com.remswork.project.alice.model.support.Message) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks)

Example 2 with DepartmentException

use of com.remswork.project.alice.exception.DepartmentException in project classify-system by anverliedoit.

the class DepartmentResource method getDepartmentById.

@GET
@Path("{departmentId}")
public Response getDepartmentById(@PathParam("departmentId") long id) {
    try {
        DepartmentResourceLinks resourceLinks = new DepartmentResourceLinks(uriInfo);
        Department department = departmentService.getDepartmentById(id);
        department.addLink(resourceLinks.self(id));
        return Response.status(Response.Status.OK).entity(department).build();
    } catch (DepartmentException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : Department(com.remswork.project.alice.model.Department) DepartmentException(com.remswork.project.alice.exception.DepartmentException) Message(com.remswork.project.alice.model.support.Message) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks)

Example 3 with DepartmentException

use of com.remswork.project.alice.exception.DepartmentException in project classify-system by anverliedoit.

the class DepartmentResource method updateDepartmentById.

@PUT
@Path("{departmentId}")
public Response updateDepartmentById(@PathParam("departmentId") long id, Department newDepartment) {
    try {
        DepartmentResourceLinks resourceLinks = new DepartmentResourceLinks(uriInfo);
        Department department = departmentService.updateDepartmentById(id, newDepartment);
        department.addLink(resourceLinks.self(id));
        return Response.status(Response.Status.OK).entity(department).build();
    } catch (DepartmentException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : Department(com.remswork.project.alice.model.Department) DepartmentException(com.remswork.project.alice.exception.DepartmentException) Message(com.remswork.project.alice.model.support.Message) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks)

Example 4 with DepartmentException

use of com.remswork.project.alice.exception.DepartmentException in project classify-system by anverliedoit.

the class TeacherDaoImpl method addTeacher.

@Override
public Teacher addTeacher(Teacher teacher, long departmentId) throws TeacherException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        if (teacher == null)
            throw new TeacherDaoException("You tried to add teacher with a null value");
        if (teacher.getFirstName() == null)
            throw new TeacherDaoException("Teacher's first name is required");
        if (teacher.getFirstName().trim().equals(""))
            throw new TeacherDaoException("Teacher can't have an empty first name");
        if (teacher.getLastName() == null)
            throw new TeacherDaoException("Teacher's last name is required");
        if (teacher.getLastName().trim().equals(""))
            throw new TeacherDaoException("Teacher can't have an empty last name");
        if (teacher.getMiddleName() == null)
            throw new TeacherDaoException("Teacher's middle name is required");
        if (teacher.getMiddleName().trim().equals(""))
            throw new TeacherDaoException("Teacher can't have an empty middle name");
        if (teacher.getEmail() == null)
            throw new TeacherDaoException("Teacher's email is required");
        if (teacher.getEmail().trim().equals(""))
            throw new TeacherDaoException("Teacher can't have an empty email");
        if (departmentId > 0) {
            Department department = departmentDao.getDepartmentById(departmentId);
            teacher.setDepartment(department);
        }
        UserDetail userDetail = new UserDetail();
        userDetail.setIsEnabled(true);
        userDetail.setRegistrationDate(new Date().now().toString());
        userDetail.setUsername(teacher.getEmail());
        userDetail.setPassword((teacher.getFirstName() + teacher.getLastName() + "123").toLowerCase());
        userDetail.setUserType(UserDetail.USER_TEACHER);
        teacher.setUserDetail(userDetail);
        teacher = (Teacher) session.merge(teacher);
        session.getTransaction().commit();
        session.close();
        return teacher;
    } catch (TeacherDaoException | DepartmentException e) {
        session.close();
        throw new TeacherException(e.getMessage());
    }
}
Also used : TeacherException(com.remswork.project.alice.exception.TeacherException) DepartmentException(com.remswork.project.alice.exception.DepartmentException) TeacherDaoException(com.remswork.project.alice.dao.exception.TeacherDaoException) Date(com.remswork.project.alice.model.support.Date) Session(org.hibernate.Session)

Example 5 with DepartmentException

use of com.remswork.project.alice.exception.DepartmentException in project classify-system by anverliedoit.

the class TeacherDaoImpl method updateTeacherById.

@Override
public Teacher updateTeacherById(long id, Teacher newTeacher, long departmentId) throws TeacherException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        if (newTeacher == null)
            newTeacher = new Teacher();
        Teacher teacher = session.get(Teacher.class, id);
        if (teacher == null)
            throw new TeacherDaoException("Teacher with id : " + id + " does not exist.");
        if (!(newTeacher.getFirstName() != null ? newTeacher.getFirstName() : "").trim().isEmpty())
            teacher.setFirstName(newTeacher.getFirstName());
        if (!(newTeacher.getLastName() != null ? newTeacher.getLastName() : "").trim().isEmpty())
            teacher.setLastName(newTeacher.getLastName());
        if (!(newTeacher.getEmail() != null ? newTeacher.getEmail() : "").trim().isEmpty())
            teacher.setEmail(newTeacher.getEmail());
        if (!(newTeacher.getMiddleName() != null ? newTeacher.getMiddleName() : "").trim().isEmpty())
            teacher.setMiddleName(newTeacher.getMiddleName());
        if (departmentId > 0) {
            Department department = departmentDao.getDepartmentById(departmentId);
            if (department.getId() == (teacher.getDepartment() != null ? teacher.getDepartment().getId() : 0))
                throw new TeacherDaoException("Can't update teacher's department with same department");
            teacher.setDepartment(department);
            teacher = (Teacher) session.merge(teacher);
        }
        session.getTransaction().commit();
        session.close();
        return teacher;
    } catch (TeacherDaoException | DepartmentException e) {
        session.close();
        throw new TeacherException(e.getMessage());
    }
}
Also used : TeacherException(com.remswork.project.alice.exception.TeacherException) DepartmentException(com.remswork.project.alice.exception.DepartmentException) TeacherDaoException(com.remswork.project.alice.dao.exception.TeacherDaoException) Session(org.hibernate.Session)

Aggregations

DepartmentException (com.remswork.project.alice.exception.DepartmentException)30 Department (com.remswork.project.alice.model.Department)22 Message (com.remswork.project.alice.model.support.Message)15 Session (org.hibernate.Session)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 AsyncTask (android.os.AsyncTask)5 Gson (com.google.gson.Gson)5 DepartmentDaoException (com.remswork.project.alice.dao.exception.DepartmentDaoException)5 SectionException (com.remswork.project.alice.exception.SectionException)5 Section (com.remswork.project.alice.model.Section)5 DepartmentResourceLinks (com.remswork.project.alice.resource.links.DepartmentResourceLinks)5 DepartmentServiceException (com.remswork.project.alice.web.service.exception.DepartmentServiceException)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 HttpURLConnection (java.net.HttpURLConnection)5 URL (java.net.URL)5 ExecutionException (java.util.concurrent.ExecutionException)5 Client (javax.ws.rs.client.Client)5 WebTarget (javax.ws.rs.client.WebTarget)5 Response (javax.ws.rs.core.Response)5