String subject = req.getParameter("subject");
String note = req.getParameter("note");
String keyString = req.getParameter("key");
Key listKey = KeyFactory.stringToKey(keyString);
Note n = new Note();
n.setDate(new Date());
n.setSubject(subject);
n.setNote(note);
n.setUserId(user.getUserId());
String action = req.getParameter("action");
try {
DAOFactory df = DAOFactory.getInstance();
NotesDAO notesDAO = df.getDAO(Note.class, NotesDAO.class);
// update Note
if(action != null && action.equals("edit")){
n.setKey(listKey);
notesDAO.updateNote(n);
keyString = KeyFactory.keyToString(listKey.getParent());
}
else // create new note and persist it
notesDAO.addNote(listKey, n);