17 |
@Path("/tasks") |
@Path("/tasks") |
18 |
public class TaskRestService { |
public class TaskRestService { |
19 |
|
|
20 |
|
@Context ServletContext context; |
21 |
|
|
22 |
|
|
23 |
@Path("/list") |
@Path("/list") |
24 |
@GET |
@GET |
25 |
@Produces(MediaType.APPLICATION_JSON) |
@Produces(MediaType.APPLICATION_JSON) |
26 |
public String listTasks(@Context ServletContext context ) { |
public String listTasks( ) { |
27 |
TaskManager taskManager = (TaskManager) context.getAttribute(TaskManager.TASKMANAGER); |
TaskManager taskManager = (TaskManager) context.getAttribute(TaskManager.TASKMANAGER); |
28 |
List<TaskBean> beans = taskManager.getTasks(); |
List<TaskBean> beans = taskManager.getTasks(); |
29 |
|
|
36 |
@Path("/log/{id}") |
@Path("/log/{id}") |
37 |
@GET |
@GET |
38 |
@Produces(MediaType.TEXT_PLAIN) |
@Produces(MediaType.TEXT_PLAIN) |
39 |
public String getLog(@Context ServletContext context, @PathParam("id") int taskId ) { |
public String getLog( @PathParam("id") int taskId ) { |
40 |
TaskManager taskManager = (TaskManager) context.getAttribute(TaskManager.TASKMANAGER); |
TaskManager taskManager = (TaskManager) context.getAttribute(TaskManager.TASKMANAGER); |
41 |
Task t = taskManager.getTaskById(taskId); |
Task t = taskManager.getTaskById(taskId); |
42 |
|
|
47 |
return t.getLog(); |
return t.getLog(); |
48 |
} |
} |
49 |
|
|
50 |
|
@Path("/remove/{id}") |
51 |
|
@GET |
52 |
|
@Produces(MediaType.TEXT_PLAIN) |
53 |
|
public String removeTask( @PathParam("id") int taskId ) { |
54 |
|
TaskManager taskManager = (TaskManager) context.getAttribute(TaskManager.TASKMANAGER); |
55 |
|
Task removeTask = taskManager.getTaskById(taskId); |
56 |
|
|
57 |
|
if (removeTask == null ){ |
58 |
|
return "No task with id: " + taskId; |
59 |
|
} |
60 |
|
|
61 |
|
taskManager.removeTask(removeTask); |
62 |
|
|
63 |
|
return "OK"; |
64 |
|
} |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
} |
} |