Search in sources :

Example 16 with Teacher

use of com.remswork.project.alice.model.Teacher in project classify-system by anverliedoit.

the class TeacherServiceImpl method addTeacher.

@Override
public Teacher addTeacher(Teacher teacher, long departmentId) throws TeacherException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(uri.toString());
        Builder builder = target.queryParam("departmentId", departmentId).request();
        builder.accept("application/json");
        Response response = builder.post(Entity.json(teacher));
        if (response.getStatus() == 201) {
            return (Teacher) response.readEntity(Teacher.class);
        } else if (response.getStatus() == 400) {
            Message message = (Message) response.readEntity(Message.class);
            throw new TeacherServiceException(message.getMessage());
        } else
            throw new TeacherServiceException("The request might invalid or server is down");
    } catch (TeacherServiceException e) {
        throw new TeacherException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) TeacherServiceException(com.remswork.project.alice.web.service.exception.TeacherServiceException) TeacherException(com.remswork.project.alice.exception.TeacherException) Message(com.remswork.project.alice.model.support.Message) ClientBuilder(javax.ws.rs.client.ClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) Teacher(com.remswork.project.alice.model.Teacher) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Example 17 with Teacher

use of com.remswork.project.alice.model.Teacher in project classify-system by anverliedoit.

the class TeacherServiceImpl method deleteTeacherById.

@Override
public Teacher deleteTeacherById(long id) throws TeacherException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        uri.append("/");
        uri.append(id);
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(uri.toString());
        Builder builder = target.request();
        builder.accept("application/json");
        Response response = builder.delete();
        if (response.getStatus() == 200) {
            return (Teacher) response.readEntity(Teacher.class);
        } else if (response.getStatus() == 400) {
            Message message = (Message) response.readEntity(Message.class);
            throw new TeacherServiceException(message.getMessage());
        } else
            throw new TeacherServiceException("The request might invalid or server is down");
    } catch (TeacherServiceException e) {
        throw new TeacherException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) TeacherServiceException(com.remswork.project.alice.web.service.exception.TeacherServiceException) TeacherException(com.remswork.project.alice.exception.TeacherException) Message(com.remswork.project.alice.model.support.Message) ClientBuilder(javax.ws.rs.client.ClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) Teacher(com.remswork.project.alice.model.Teacher) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Example 18 with Teacher

use of com.remswork.project.alice.model.Teacher in project classify-system by anverliedoit.

the class ClassController method deleteClassById.

@RequestMapping(value = "delete", method = RequestMethod.POST)
public String deleteClassById(@RequestParam("teacherId") long teacherId, @RequestParam("classId") long classId, ModelMap modelMap) {
    List<com.remswork.project.alice.model.Class> classList = new ArrayList<>();
    Teacher teacher;
    try {
        classService.deleteClassById(classId);
        classList = classService.getClassListByTeacherId(teacherId);
        teacher = teacherService.getTeacherById(teacherId);
    } catch (Exception e) {
        e.printStackTrace();
        teacher = null;
    }
    modelMap.put("teacher", teacher);
    modelMap.put("classes", classList);
    return "teacher-detail";
}
Also used : ArrayList(java.util.ArrayList) Teacher(com.remswork.project.alice.model.Teacher) ClassException(com.remswork.project.alice.exception.ClassException)

Example 19 with Teacher

use of com.remswork.project.alice.model.Teacher in project classify-system by anverliedoit.

the class TeacherResource method getTeacherById.

@GET
@Path("{teacherId}")
public Response getTeacherById(@PathParam("teacherId") long id) {
    try {
        TeacherResourceLinks resourceLink = new TeacherResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        Teacher teacher = teacherService.getTeacherById(id);
        teacher.addLink(resourceLink.self(id));
        if (teacher.getDepartment() != null)
            teacher.getDepartment().addLink(departmentResourceLinks.self(teacher.getDepartment().getId()));
        return Response.status(Response.Status.OK).entity(teacher).build();
    } catch (TeacherException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : TeacherException(com.remswork.project.alice.exception.TeacherException) Message(com.remswork.project.alice.model.support.Message) Teacher(com.remswork.project.alice.model.Teacher) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) TeacherResourceLinks(com.remswork.project.alice.resource.links.TeacherResourceLinks)

Example 20 with Teacher

use of com.remswork.project.alice.model.Teacher in project classify-system by anverliedoit.

the class TeacherResource method updateTeacherById.

@PUT
@Path("{teacherId}")
public Response updateTeacherById(@PathParam("teacherId") long id, Teacher newTeacher) {
    try {
        TeacherResourceLinks resourceLink = new TeacherResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        Teacher teacher;
        if (departmentId > 0)
            teacher = teacherService.updateTeacherById(id, newTeacher, departmentId);
        else
            teacher = teacherService.updateTeacherById(id, newTeacher);
        teacher.addLink(resourceLink.self(id));
        if (teacher.getDepartment() != null)
            teacher.getDepartment().addLink(departmentResourceLinks.self(teacher.getDepartment().getId()));
        return Response.status(Response.Status.OK).entity(teacher).build();
    } catch (TeacherException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : TeacherException(com.remswork.project.alice.exception.TeacherException) Message(com.remswork.project.alice.model.support.Message) Teacher(com.remswork.project.alice.model.Teacher) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) TeacherResourceLinks(com.remswork.project.alice.resource.links.TeacherResourceLinks)

Aggregations

Teacher (com.remswork.project.alice.model.Teacher)29 TeacherException (com.remswork.project.alice.exception.TeacherException)14 Message (com.remswork.project.alice.model.support.Message)14 TeacherServiceException (com.remswork.project.alice.web.service.exception.TeacherServiceException)6 Client (javax.ws.rs.client.Client)6 WebTarget (javax.ws.rs.client.WebTarget)6 Response (javax.ws.rs.core.Response)6 Subject (com.remswork.project.alice.model.Subject)5 Gson (com.google.gson.Gson)4 TeacherHelper (com.lieverandiver.thesisproject.helper.TeacherHelper)4 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)4 Department (com.remswork.project.alice.model.Department)4 DepartmentResourceLinks (com.remswork.project.alice.resource.links.DepartmentResourceLinks)4 TeacherResourceLinks (com.remswork.project.alice.resource.links.TeacherResourceLinks)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 HttpURLConnection (java.net.HttpURLConnection)4 URL (java.net.URL)4 ExecutionException (java.util.concurrent.ExecutionException)4 ClientBuilder (javax.ws.rs.client.ClientBuilder)4