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