Search in sources :

Example 1 with ActivityResourceLinks

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

the class ActivityResource method addActivity.

@POST
public Response addActivity(Activity activity) {
    try {
        ActivityResourceLinks resourceLinks = new ActivityResourceLinks(uriInfo);
        ClassResourceLinks classResourceLinks = new ClassResourceLinks(uriInfo);
        if (termId > 0)
            activity = activityService.addActivity(activity, classId, termId);
        else
            activity = activityService.addActivity(activity, classId);
        activity.addLink(resourceLinks.self(activity.getId()));
        if (activity.get_class() != null)
            activity.get_class().addLink(classResourceLinks.self(activity.get_class().getId()));
        return Response.status(Response.Status.CREATED).entity(activity).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) ActivityResourceLinks(com.remswork.project.alice.resource.links.ActivityResourceLinks) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException)

Example 2 with ActivityResourceLinks

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

the class ActivityResource method getActivityById.

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

Example 3 with ActivityResourceLinks

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

the class ActivityResource method updateActivityById.

@PUT
@Path("{activityId}")
public Response updateActivityById(@PathParam("activityId") long id, Activity newActivity) {
    try {
        ActivityResourceLinks resourceLinks = new ActivityResourceLinks(uriInfo);
        ClassResourceLinks classResourceLinks = new ClassResourceLinks(uriInfo);
        Activity activity;
        if (termId > 0)
            activity = activityService.updateActivityById(id, newActivity, classId, termId);
        else
            activity = activityService.updateActivityById(id, newActivity, classId);
        activity.addLink(resourceLinks.self(activity.getId()));
        if (activity.get_class() != null)
            activity.get_class().addLink(classResourceLinks.self(activity.get_class().getId()));
        return Response.status(Response.Status.OK).entity(activity).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) ActivityResourceLinks(com.remswork.project.alice.resource.links.ActivityResourceLinks) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Activity(com.remswork.project.alice.model.Activity)

Example 4 with ActivityResourceLinks

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

the class ActivityResource method getActivityList.

@GET
public Response getActivityList() {
    try {
        List<Activity> activityList;
        ActivityResourceLinks resourceLinks = new ActivityResourceLinks(uriInfo);
        ClassResourceLinks classResourceLinks = new ClassResourceLinks(uriInfo);
        if (classId != 0 && termId != 0)
            activityList = activityService.getActivityListByClassId(classId, termId);
        else if (classId != 0)
            activityList = activityService.getActivityListByClassId(classId);
        else if (studentId != 0 && termId != 0)
            activityList = activityService.getActivityListByStudentId(studentId, termId);
        else if (studentId != 0)
            activityList = activityService.getActivityListByStudentId(studentId);
        else
            activityList = activityService.getActivityList();
        for (Activity activity : activityList) {
            activity.addLink(resourceLinks.self(activity.getId()));
            if (activity.get_class() != null)
                activity.get_class().addLink(classResourceLinks.self(activity.get_class().getId()));
        }
        GenericEntity<List<Activity>> entity = new GenericEntity<List<Activity>>(activityList) {
        };
        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 : ClassResourceLinks(com.remswork.project.alice.resource.links.ClassResourceLinks) Message(com.remswork.project.alice.model.support.Message) ActivityResourceLinks(com.remswork.project.alice.resource.links.ActivityResourceLinks) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Activity(com.remswork.project.alice.model.Activity) List(java.util.List)

Example 5 with ActivityResourceLinks

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

the class ActivityResource method deleteActivityById.

@DELETE
@Path("{activityId}")
public Response deleteActivityById(@PathParam("activityId") long id) {
    try {
        ActivityResourceLinks resourceLinks = new ActivityResourceLinks(uriInfo);
        ClassResourceLinks classResourceLinks = new ClassResourceLinks(uriInfo);
        Activity activity = activityService.deleteActivityById(id);
        activity.addLink(resourceLinks.self(activity.getId()));
        if (activity.get_class() != null)
            activity.get_class().addLink(classResourceLinks.self(activity.get_class().getId()));
        return Response.status(Response.Status.OK).entity(activity).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) ActivityResourceLinks(com.remswork.project.alice.resource.links.ActivityResourceLinks) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Activity(com.remswork.project.alice.model.Activity)

Aggregations

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