01: package org.claros.intouch.notes.services;
02:
03: import java.io.IOException;
04: import java.io.PrintWriter;
05: import java.sql.Timestamp;
06: import java.util.Date;
07: import java.util.List;
08:
09: import javax.servlet.ServletException;
10: import javax.servlet.http.HttpServletRequest;
11: import javax.servlet.http.HttpServletResponse;
12:
13: import org.apache.commons.logging.Log;
14: import org.apache.commons.logging.LogFactory;
15: import org.claros.intouch.common.services.BaseService;
16: import org.claros.intouch.notes.controllers.NotesController;
17: import org.claros.intouch.notes.models.Note;
18:
19: /**
20: *
21: * @author umut
22: *
23: */
24: public class CreateNewNoteService extends BaseService {
25:
26: /**
27: *
28: */
29: private static final long serialVersionUID = -1520417818456610709L;
30: private static Log log = LogFactory
31: .getLog(CreateNewNoteService.class);
32:
33: /**
34: * The doPost method of the servlet. <br>
35: *
36: * This method is called when a form has its tag value method equals to post.
37: *
38: * @param request the request send by the client to the server
39: * @param response the response send by the server to the client
40: * @throws ServletException if an error occurred
41: * @throws IOException if an error occurred
42: */
43: public void doPost(HttpServletRequest request,
44: HttpServletResponse response) throws ServletException,
45: IOException {
46:
47: response.setHeader("Expires", "-1");
48: response.setHeader("Pragma", "no-cache");
49: response.setHeader("Cache-control", "no-cache");
50: response.setHeader("Content-Type", "text/html; charset=utf-8");
51: PrintWriter out = response.getWriter();
52:
53: String sId = request.getParameter("folderId");
54: if (sId != null) {
55: try {
56: Note note = new Note();
57: note.setNoteContent("");
58: note.setUsername(getAuthProfile(request).getUsername());
59: note.setPosTop(new Integer(100));
60: note.setPosLeft(new Integer(237));
61: note.setPosWidth(new Integer(225));
62: note.setPosHeight(new Integer(225));
63: note.setFolderId(new Long(sId));
64: note.setNoteBorderColor("#e6e643");
65: note.setNoteColor("#fdf7ad");
66: note.setNoteBarColor("#ffff7f");
67: note.setNoteDate(new Timestamp(new Date().getTime()));
68: NotesController.saveNote(getAuthProfile(request), note);
69:
70: List notes = NotesController.getNotesByFolderId(
71: getAuthProfile(request), new Long(sId));
72: Long lastId = null;
73: if (notes != null) {
74: Note tmp = (Note) notes.get(0);
75: lastId = tmp.getId();
76: }
77: if (lastId != null) {
78: out.print("ok" + lastId.intValue());
79: } else {
80: out.print("fail");
81: }
82: } catch (Exception e) {
83: log.warn("error while creating note", e);
84: out.print("fail");
85: }
86: } else {
87: out.print("fail");
88: }
89: }
90: }
|