01: package org.claros.intouch.tasks.services;
02:
03: import java.io.IOException;
04: import java.io.PrintWriter;
05:
06: import javax.servlet.ServletException;
07: import javax.servlet.http.HttpServletRequest;
08: import javax.servlet.http.HttpServletResponse;
09:
10: import org.claros.intouch.common.services.BaseService;
11: import org.claros.intouch.tasks.controllers.TaskController;
12: import org.claros.intouch.tasks.models.Task;
13:
14: public class ClickTaskService extends BaseService {
15:
16: /**
17: *
18: */
19: private static final long serialVersionUID = -3277216365813696293L;
20:
21: /**
22: * @param request
23: * the request send by the client to the server
24: * @param response
25: * the response send by the server to the client
26: * @throws ServletException
27: * if an error occurred
28: * @throws IOException
29: * if an error occurred
30: */
31: public void doPost(HttpServletRequest request,
32: HttpServletResponse response) throws ServletException,
33: IOException {
34: response.setHeader("Expires", "-1");
35: response.setHeader("Pragma", "no-cache");
36: response.setHeader("Cache-control", "no-cache");
37: response.setHeader("Content-Type", "text/html; charset=utf-8");
38: PrintWriter out = response.getWriter();
39:
40: String sId = request.getParameter("id");
41:
42: if (sId != null) {
43: try {
44: Task task = TaskController.getTaskById(getAuthProfile(
45: request).getUsername(), new Long(sId));
46: if (task != null) {
47: String checked = task.getChecked();
48: if (checked != null && checked.equals("true")) {
49: task.setChecked("false");
50: } else {
51: task.setChecked("true");
52: }
53: TaskController.saveTask(getAuthProfile(request)
54: .getUsername(), task);
55: } else {
56: throw new Exception();
57: }
58: out.print("ok");
59: } catch (Exception e) {
60: out.print("fail");
61: }
62: } else {
63: out.print("fail");
64: }
65: }
66: }
|