Search in sources :

Example 6 with ClassException

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

the class ClassScheduleListResource method getScheduleById.

@GET
@Path("{scheduleId}")
public Response getScheduleById(@PathParam("classId") long classId, @PathParam("scheduleId") long id) {
    try {
        ClassScheduleListResourceLinks resourceLinks = new ClassScheduleListResourceLinks(uriInfo);
        Schedule schedule = classService.getScheduleById(classId, id);
        schedule.addLink(resourceLinks.self(classId, id));
        return Response.status(Response.Status.OK).entity(schedule).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();
    }
}
Also used : ClassScheduleListResourceLinks(com.remswork.project.alice.resource.links.ClassScheduleListResourceLinks) Message(com.remswork.project.alice.model.support.Message) Schedule(com.remswork.project.alice.model.Schedule) ClassException(com.remswork.project.alice.exception.ClassException)

Example 7 with ClassException

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

the class ClassScheduleListResource method addScheduleById.

@POST
public Response addScheduleById(@PathParam("classId") long classId) {
    try {
        ClassScheduleListResourceLinks resourceLinks = new ClassScheduleListResourceLinks(uriInfo);
        if (scheduleId == 0)
            throw new ClassDaoException("Query param : scheduleId is required");
        Schedule schedule = classService.addScheduleById(classId, scheduleId);
        schedule.addLink(resourceLinks.self(classId, scheduleId));
        return Response.status(Response.Status.OK).entity(schedule).build();
    } catch (ClassException | ClassDaoException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : ClassScheduleListResourceLinks(com.remswork.project.alice.resource.links.ClassScheduleListResourceLinks) ClassDaoException(com.remswork.project.alice.dao.exception.ClassDaoException) Message(com.remswork.project.alice.model.support.Message) Schedule(com.remswork.project.alice.model.Schedule) ClassException(com.remswork.project.alice.exception.ClassException)

Example 8 with ClassException

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

the class ClassScheduleListResource method deleteScheduleById.

@DELETE
@Path("{scheduleId}")
public Response deleteScheduleById(@PathParam("classId") long classId, @PathParam("scheduleId") long id) {
    try {
        ClassScheduleListResourceLinks resourceLinks = new ClassScheduleListResourceLinks(uriInfo);
        Schedule schedule = classService.deleteScheduleById(classId, id);
        schedule.addLink(resourceLinks.self(classId, id));
        return Response.status(Response.Status.OK).entity(schedule).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();
    }
}
Also used : ClassScheduleListResourceLinks(com.remswork.project.alice.resource.links.ClassScheduleListResourceLinks) Message(com.remswork.project.alice.model.support.Message) Schedule(com.remswork.project.alice.model.Schedule) ClassException(com.remswork.project.alice.exception.ClassException)

Example 9 with ClassException

use of com.remswork.project.alice.exception.ClassException 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();
    }
}
Also used : ClassStudentListResourceLinks(com.remswork.project.alice.resource.links.ClassStudentListResourceLinks) Message(com.remswork.project.alice.model.support.Message) ClassException(com.remswork.project.alice.exception.ClassException) Student(com.remswork.project.alice.model.Student)

Example 10 with ClassException

use of com.remswork.project.alice.exception.ClassException 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();
    }
}
Also used : ClassStudentListResourceLinks(com.remswork.project.alice.resource.links.ClassStudentListResourceLinks) Set(java.util.Set) Message(com.remswork.project.alice.model.support.Message) GenericEntity(javax.ws.rs.core.GenericEntity) ClassException(com.remswork.project.alice.exception.ClassException) Student(com.remswork.project.alice.model.Student)

Aggregations

ClassException (com.remswork.project.alice.exception.ClassException)55 Message (com.remswork.project.alice.model.support.Message)46 Class (com.remswork.project.alice.model.Class)18 AsyncTask (android.os.AsyncTask)17 Gson (com.google.gson.Gson)17 IOException (java.io.IOException)17 InputStream (java.io.InputStream)17 HttpURLConnection (java.net.HttpURLConnection)17 URL (java.net.URL)17 ExecutionException (java.util.concurrent.ExecutionException)17 ClassServiceException (com.remswork.project.alice.web.service.exception.ClassServiceException)16 Client (javax.ws.rs.client.Client)16 WebTarget (javax.ws.rs.client.WebTarget)16 Response (javax.ws.rs.core.Response)16 Student (com.remswork.project.alice.model.Student)14 Schedule (com.remswork.project.alice.model.Schedule)13 ArrayList (java.util.ArrayList)9 ClientBuilder (javax.ws.rs.client.ClientBuilder)7 Builder (javax.ws.rs.client.Invocation.Builder)7 JSONArray (org.json.JSONArray)7