Search in sources :

Example 66 with Message

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

the class TeacherResource method getAll.

@GET
public Response getAll() {
    try {
        TeacherResourceLinks resourceLink = new TeacherResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        List<Teacher> teacherList = teacherService.getTeacherList();
        for (Teacher teacher : teacherList) {
            teacher.addLink(resourceLink.self(teacher.getId()));
            if (teacher.getDepartment() != null)
                teacher.getDepartment().addLink(departmentResourceLinks.self(teacher.getDepartment().getId()));
        }
        GenericEntity<List<Teacher>> entity = new GenericEntity<List<Teacher>>(teacherList) {
        };
        return Response.status(Response.Status.OK).entity(entity).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) List(java.util.List)

Example 67 with Message

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

the class TeacherResource method deleteTeacherById.

@DELETE
@Path("{teacherId}")
public Response deleteTeacherById(@PathParam("teacherId") long id) {
    try {
        TeacherResourceLinks resourceLink = new TeacherResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        Teacher teacher = teacherService.deleteTeacherById(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(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)

Example 68 with Message

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

the class TermResource method addTerm.

@POST
public Response addTerm(Term term) {
    try {
        TermResourceLinks resourceLinks = new TermResourceLinks(uriInfo);
        term = termService.addTerm(term);
        term.addLink(resourceLinks.self(term.getId()));
        return Response.status(Response.Status.CREATED).entity(term).build();
    } catch (GradingFactorException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : TermResourceLinks(com.remswork.project.alice.resource.links.TermResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException)

Example 69 with Message

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

the class TermResource method getTermList.

@GET
public Response getTermList() {
    try {
        TermResourceLinks resourceLinks = new TermResourceLinks(uriInfo);
        List<Term> termList = termService.getTermList();
        for (Term term : termList) term.addLink(resourceLinks.self(term.getId()));
        GenericEntity<List<Term>> entity = new GenericEntity<List<Term>>(termList) {
        };
        return Response.status(Response.Status.OK).entity(entity).build();
    } catch (GradingFactorException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : TermResourceLinks(com.remswork.project.alice.resource.links.TermResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) List(java.util.List) Term(com.remswork.project.alice.model.Term)

Example 70 with Message

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

the class TermResource method updateTermById.

@PUT
@Path("{termId}")
public Response updateTermById(@PathParam("termId") long id, Term newTerm) {
    try {
        TermResourceLinks resourceLinks = new TermResourceLinks(uriInfo);
        Term term = termService.updateTermById(id, newTerm);
        term.addLink(resourceLinks.self(id));
        return Response.status(Response.Status.OK).entity(term).build();
    } catch (GradingFactorException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : TermResourceLinks(com.remswork.project.alice.resource.links.TermResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Term(com.remswork.project.alice.model.Term)

Aggregations

Message (com.remswork.project.alice.model.support.Message)336 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)178 Gson (com.google.gson.Gson)155 IOException (java.io.IOException)155 InputStream (java.io.InputStream)155 HttpURLConnection (java.net.HttpURLConnection)155 URL (java.net.URL)155 ExecutionException (java.util.concurrent.ExecutionException)155 AsyncTask (android.os.AsyncTask)153 Client (javax.ws.rs.client.Client)58 WebTarget (javax.ws.rs.client.WebTarget)58 Response (javax.ws.rs.core.Response)58 JSONArray (org.json.JSONArray)49 JSONException (org.json.JSONException)49 ClassException (com.remswork.project.alice.exception.ClassException)46 ArrayList (java.util.ArrayList)46 ClassResourceLinks (com.remswork.project.alice.resource.links.ClassResourceLinks)40 OutputStreamWriter (java.io.OutputStreamWriter)36 BufferedWriter (java.io.BufferedWriter)34 OutputStream (java.io.OutputStream)34