Search in sources :

Example 56 with Message

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

the class SectionResource method getSectionById.

@GET
@Path("{sectionId}")
public Response getSectionById(@PathParam("sectionId") long id) {
    try {
        SectionResourceLinks resourceLinks = new SectionResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        Section section = sectionService.getSectionById(id);
        section.addLink(resourceLinks.self(id));
        if (section.getDepartment() != null)
            section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
        return Response.status(Response.Status.OK).entity(section).build();
    } catch (SectionException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : Message(com.remswork.project.alice.model.support.Message) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) SectionResourceLinks(com.remswork.project.alice.resource.links.SectionResourceLinks)

Example 57 with Message

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

the class SectionResource method deleteSectionById.

@DELETE
@Path("{sectionId}")
public Response deleteSectionById(@PathParam("sectionId") long id) {
    try {
        SectionResourceLinks resourceLinks = new SectionResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        Section section = sectionService.deleteSectionById(id);
        section.addLink(resourceLinks.self(id));
        if (section.getDepartment() != null)
            section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
        return Response.status(Response.Status.OK).entity(section).build();
    } catch (SectionException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : Message(com.remswork.project.alice.model.support.Message) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) SectionResourceLinks(com.remswork.project.alice.resource.links.SectionResourceLinks)

Example 58 with Message

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

the class SectionResource method addSection.

@POST
public Response addSection(Section section) {
    try {
        SectionResourceLinks resourceLinks = new SectionResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        section = sectionService.addSection(section, departmentId);
        section.addLink(resourceLinks.self(section.getId()));
        if (section.getDepartment() != null)
            section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
        return Response.status(Response.Status.CREATED).entity(section).build();
    } catch (SectionException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : Message(com.remswork.project.alice.model.support.Message) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) SectionException(com.remswork.project.alice.exception.SectionException) SectionResourceLinks(com.remswork.project.alice.resource.links.SectionResourceLinks)

Example 59 with Message

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

the class SectionResource method updateSectionById.

@PUT
@Path("{sectionId}")
public Response updateSectionById(@PathParam("sectionId") long id, Section newSection) {
    try {
        SectionResourceLinks resourceLinks = new SectionResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        Section section = sectionService.updateSectionById(id, newSection, departmentId);
        section.addLink(resourceLinks.self(id));
        if (section.getDepartment() != null)
            section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
        return Response.status(Response.Status.OK).entity(section).build();
    } catch (SectionException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : Message(com.remswork.project.alice.model.support.Message) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) SectionResourceLinks(com.remswork.project.alice.resource.links.SectionResourceLinks)

Example 60 with Message

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

the class SectionResource method getSectionList.

@GET
public Response getSectionList() {
    try {
        SectionResourceLinks resourceLinks = new SectionResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        List<Section> sectionList = sectionService.getSectionList();
        for (Section section : sectionList) {
            section.addLink(resourceLinks.self(section.getId()));
            if (section.getDepartment() != null)
                section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
        }
        GenericEntity<List<Section>> entity = new GenericEntity<List<Section>>(sectionList) {
        };
        return Response.status(Response.Status.OK).entity(entity).build();
    } catch (SectionException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : Message(com.remswork.project.alice.model.support.Message) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) List(java.util.List) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) SectionResourceLinks(com.remswork.project.alice.resource.links.SectionResourceLinks)

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