@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
traceRequest(req);
String pathInfo = req.getPathInfo();
IPath path = pathInfo == null ? Path.EMPTY : new Path(pathInfo);
ITaskService taskService = taskTracker.getService();
if (path.segmentCount() == 0) {
taskService.removeCompletedTasks(TaskJobHandler.getUserId(req));
List<TaskInfo> tasks = taskService.getTasks(TaskJobHandler.getUserId(req));
List<String> locations = new ArrayList<String>();
try {
for (TaskInfo task : tasks) {
locations.add(getJsonWithLocation(req, task).optString(ProtocolConstants.KEY_LOCATION));
}
} catch (Exception e) {
handleException(resp, e.getMessage(), e);
}
writeJSONResponse(req, resp, new JSONArray(locations));
return;
}
if (path.segmentCount() != 2 || (!"id".equals(path.segment(0)) && !"temp".equals(path.segment(0)))) {//$NON-NLS-1$
handleException(resp, "Invalid request path: " + EncodingUtils.encodeForHTML(path.toString()), null, HttpServletResponse.SC_BAD_REQUEST);
return;
}
boolean isKeep = "id".equals(path.segment(0));
String taskId = path.segment(1);
try {
taskService.removeTask(TaskJobHandler.getUserId(req), taskId, isKeep);
} catch (TaskDoesNotExistException e) {
handleException(resp, "Could not remove task that does not exist: " + e.getTaskId(), e, HttpServletResponse.SC_NOT_FOUND);
return;
} catch (TaskOperationException e) {
handleException(resp, e.getMessage(), e);