Search in sources :

Example 61 with Message

use of com.remswork.project.alice.model.support.Message 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();
    }
}
Also used : StudentException(com.remswork.project.alice.exception.StudentException) Message(com.remswork.project.alice.model.support.Message) StudentResourceLinks(com.remswork.project.alice.resource.links.StudentResourceLinks) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) List(java.util.List) Student(com.remswork.project.alice.model.Student) Section(com.remswork.project.alice.model.Section) SectionResourceLinks(com.remswork.project.alice.resource.links.SectionResourceLinks)

Example 62 with Message

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

the class SubjectResource method deleteSubjectById.

@DELETE
@Path("{subjectId}")
public Response deleteSubjectById(@PathParam("subjectId") long id) {
    try {
        SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
        Subject subject = subjectService.deleteSubjectById(id);
        subject.addLink(resourceLinks.self(id));
        return Response.status(Response.Status.OK).entity(subject).build();
    } catch (SubjectException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : SubjectResourceLinks(com.remswork.project.alice.resource.links.SubjectResourceLinks) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException) Subject(com.remswork.project.alice.model.Subject)

Example 63 with Message

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

the class SubjectResource method getSubject.

@GET
@Path("0")
public Response getSubject(@QueryParam("classId") long classId, @QueryParam("scheduleId") long scheduleId, @QueryParam("teacherId") long teacherId) {
    try {
        if (classId != 0 && teacherId != 0) {
            SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
            Subject subject = subjectService.getSubjectByClassAndTeacherId(classId, teacherId);
            subject.addLink(resourceLinks.self(subject.getId()));
            return Response.status(Response.Status.OK).entity(subject).build();
        } else if (scheduleId != 0) {
            SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
            Subject subject = subjectService.getSubjectByScheduleId(scheduleId);
            subject.addLink(resourceLinks.self(subject.getId()));
            return Response.status(Response.Status.OK).entity(subject).build();
        } else
            throw new SubjectException("No subject found");
    } catch (SubjectException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : SubjectResourceLinks(com.remswork.project.alice.resource.links.SubjectResourceLinks) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException) Subject(com.remswork.project.alice.model.Subject)

Example 64 with Message

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

the class SubjectResource method getSubjectListByTeacherIdUnique.

@GET
@Path("1/unique")
@Deprecated
public Response getSubjectListByTeacherIdUnique(@QueryParam("teacherId") long teacherId) {
    try {
        SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
        List<Subject> subjectList = subjectService.getSubjectListByTeacherIdUnique(teacherId);
        for (Subject subject : subjectList) subject.addLink(resourceLinks.self(subject.getId()));
        GenericEntity<List<Subject>> entity = new GenericEntity<List<Subject>>(subjectList) {
        };
        return Response.status(Response.Status.OK).entity(entity).build();
    } catch (SubjectException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : SubjectResourceLinks(com.remswork.project.alice.resource.links.SubjectResourceLinks) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException) List(java.util.List) Subject(com.remswork.project.alice.model.Subject)

Example 65 with Message

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

the class SubjectResource method addSubject.

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

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