Search in sources :

Example 1 with AssignmentResourceLinks

use of com.remswork.project.alice.resource.links.AssignmentResourceLinks in project classify-system by anverliedoit.

the class AssignmentResource method addAssignment.

@POST
public Response addAssignment(Assignment assignment) {
    try {
        AssignmentResourceLinks resourceLinks = new AssignmentResourceLinks(uriInfo);
        ClassResourceLinks classResourceLinks = new ClassResourceLinks(uriInfo);
        if (termId > 0)
            assignment = assignmentService.addAssignment(assignment, classId, termId);
        else
            assignment = assignmentService.addAssignment(assignment, classId);
        assignment.addLink(resourceLinks.self(assignment.getId()));
        if (assignment.get_class() != null)
            assignment.get_class().addLink(classResourceLinks.self(assignment.get_class().getId()));
        return Response.status(Response.Status.CREATED).entity(assignment).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 : ClassResourceLinks(com.remswork.project.alice.resource.links.ClassResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) AssignmentResourceLinks(com.remswork.project.alice.resource.links.AssignmentResourceLinks)

Example 2 with AssignmentResourceLinks

use of com.remswork.project.alice.resource.links.AssignmentResourceLinks in project classify-system by anverliedoit.

the class AssignmentResource method getAssignmentById.

@GET
@Path("{assignmentId}")
public Response getAssignmentById(@PathParam("assignmentId") long id) {
    try {
        AssignmentResourceLinks resourceLinks = new AssignmentResourceLinks(uriInfo);
        ClassResourceLinks classResourceLinks = new ClassResourceLinks(uriInfo);
        Assignment assignment = assignmentService.getAssignmentById(id);
        assignment.addLink(resourceLinks.self(id));
        if (assignment.get_class() != null)
            assignment.get_class().addLink(classResourceLinks.self(assignment.get_class().getId()));
        return Response.status(Response.Status.OK).entity(assignment).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 : Assignment(com.remswork.project.alice.model.Assignment) ClassResourceLinks(com.remswork.project.alice.resource.links.ClassResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) AssignmentResourceLinks(com.remswork.project.alice.resource.links.AssignmentResourceLinks)

Example 3 with AssignmentResourceLinks

use of com.remswork.project.alice.resource.links.AssignmentResourceLinks in project classify-system by anverliedoit.

the class AssignmentResource method getAssignmentList.

@GET
public Response getAssignmentList() {
    try {
        List<Assignment> assignmentList;
        AssignmentResourceLinks resourceLinks = new AssignmentResourceLinks(uriInfo);
        ClassResourceLinks classResourceLinks = new ClassResourceLinks(uriInfo);
        if (classId != 0 && termId != 0)
            assignmentList = assignmentService.getAssignmentListByClassId(classId, termId);
        else if (classId != 0)
            assignmentList = assignmentService.getAssignmentListByClassId(classId);
        else if (studentId != 0 && termId != 0)
            assignmentList = assignmentService.getAssignmentListByStudentId(studentId, termId);
        else if (studentId != 0)
            assignmentList = assignmentService.getAssignmentListByStudentId(studentId);
        else
            assignmentList = assignmentService.getAssignmentList();
        for (Assignment assignment : assignmentList) {
            assignment.addLink(resourceLinks.self(assignment.getId()));
            if (assignment.get_class() != null)
                assignment.get_class().addLink(classResourceLinks.self(assignment.get_class().getId()));
        }
        GenericEntity<List<Assignment>> entity = new GenericEntity<List<Assignment>>(assignmentList) {
        };
        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 : Assignment(com.remswork.project.alice.model.Assignment) ClassResourceLinks(com.remswork.project.alice.resource.links.ClassResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) AssignmentResourceLinks(com.remswork.project.alice.resource.links.AssignmentResourceLinks) List(java.util.List)

Example 4 with AssignmentResourceLinks

use of com.remswork.project.alice.resource.links.AssignmentResourceLinks in project classify-system by anverliedoit.

the class AssignmentResource method deleteAssignmentById.

@DELETE
@Path("{assignmentId}")
public Response deleteAssignmentById(@PathParam("assignmentId") long id) {
    try {
        AssignmentResourceLinks resourceLinks = new AssignmentResourceLinks(uriInfo);
        ClassResourceLinks classResourceLinks = new ClassResourceLinks(uriInfo);
        Assignment assignment = assignmentService.deleteAssignmentById(id);
        assignment.addLink(resourceLinks.self(assignment.getId()));
        if (assignment.get_class() != null)
            assignment.get_class().addLink(classResourceLinks.self(assignment.get_class().getId()));
        return Response.status(Response.Status.OK).entity(assignment).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 : Assignment(com.remswork.project.alice.model.Assignment) ClassResourceLinks(com.remswork.project.alice.resource.links.ClassResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) AssignmentResourceLinks(com.remswork.project.alice.resource.links.AssignmentResourceLinks)

Example 5 with AssignmentResourceLinks

use of com.remswork.project.alice.resource.links.AssignmentResourceLinks in project classify-system by anverliedoit.

the class AssignmentResource method updateAssignmentById.

@PUT
@Path("{assignmentId}")
public Response updateAssignmentById(@PathParam("assignmentId") long id, Assignment newAssignment) {
    try {
        AssignmentResourceLinks resourceLinks = new AssignmentResourceLinks(uriInfo);
        ClassResourceLinks classResourceLinks = new ClassResourceLinks(uriInfo);
        Assignment assignment;
        if (termId > 0)
            assignment = assignmentService.updateAssignmentById(id, newAssignment, classId, termId);
        else
            assignment = assignmentService.updateAssignmentById(id, newAssignment, classId);
        assignment.addLink(resourceLinks.self(assignment.getId()));
        if (assignment.get_class() != null)
            assignment.get_class().addLink(classResourceLinks.self(assignment.get_class().getId()));
        return Response.status(Response.Status.OK).entity(assignment).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 : Assignment(com.remswork.project.alice.model.Assignment) ClassResourceLinks(com.remswork.project.alice.resource.links.ClassResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) AssignmentResourceLinks(com.remswork.project.alice.resource.links.AssignmentResourceLinks)

Aggregations

GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)5 Message (com.remswork.project.alice.model.support.Message)5 AssignmentResourceLinks (com.remswork.project.alice.resource.links.AssignmentResourceLinks)5 ClassResourceLinks (com.remswork.project.alice.resource.links.ClassResourceLinks)5 Assignment (com.remswork.project.alice.model.Assignment)4 List (java.util.List)1