KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > portlets > user > action > EditUserCommentAction


1 package com.dotmarketing.portlets.user.action;
2
3 import java.util.Date JavaDoc;
4
5 import javax.portlet.ActionRequest;
6 import javax.portlet.ActionResponse;
7 import javax.portlet.PortletConfig;
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9
10 import org.apache.commons.beanutils.BeanUtils;
11 import org.apache.struts.action.ActionForm;
12 import org.apache.struts.action.ActionMapping;
13
14 import com.dotmarketing.beans.UserProxy;
15 import com.dotmarketing.db.DotHibernate;
16 import com.dotmarketing.factories.UserProxyFactory;
17 import com.dotmarketing.portal.struts.DotPortletAction;
18 import com.dotmarketing.portlets.user.factories.UserCommentsFactory;
19 import com.dotmarketing.portlets.user.model.UserComment;
20 import com.dotmarketing.portlets.user.struts.UserCommentsForm;
21 import com.dotmarketing.util.Logger;
22 import com.liferay.portal.model.User;
23 import com.liferay.portal.util.Constants;
24 import com.liferay.portlet.ActionRequestImpl;
25 import com.liferay.util.servlet.SessionMessages;
26
27 /**
28  * @author Maria Ahues
29  */

30
31 public class EditUserCommentAction extends DotPortletAction {
32     
33     public static boolean debug = false;
34     
35     /*public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig config, RenderRequest req,
36             RenderResponse res) throws Exception {
37         
38         ActionForward myfoward = mapping.findForward("portlet.admin.list_users");
39         return myfoward;
40     }*/

41     
42     public void processAction(
43             ActionMapping mapping, ActionForm form, PortletConfig config,
44             ActionRequest req, ActionResponse res)
45     throws Exception JavaDoc
46     {
47         ActionRequestImpl reqImpl = (ActionRequestImpl)req;
48         HttpServletRequest JavaDoc httpReq = reqImpl.getHttpServletRequest();
49         UserCommentsForm userCommentForm = (UserCommentsForm) form;
50         
51         String JavaDoc referer = req.getParameter("referer");
52         
53         String JavaDoc cmd = req.getParameter(Constants.CMD);
54         User user = _getUser(req);
55         
56         
57         new DotHibernate().startTransaction();
58         try
59         {
60             if(cmd.equals(Constants.DELETE))
61             {
62                 _deleteWebAsset(req,res,config,userCommentForm,user);
63             }
64             else if (cmd.equals(Constants.SAVE))
65             {
66                 _saveWebAsset(req,res,config,userCommentForm,user);
67             }
68             new DotHibernate().commitTransaction();
69         }
70         catch(Exception JavaDoc ex)
71         {
72             Logger.warn(this,ex.toString());
73             new DotHibernate().rollbackTransaction();
74         }
75         referer += "&layer=comments";
76         _sendToReferral(req,res,referer);
77         SessionMessages.add(req,"comments");
78     }
79     
80     public void _deleteWebAsset(ActionRequest req, ActionResponse res, PortletConfig config, ActionForm form, User user) throws Exception JavaDoc
81     {
82         try
83         {
84             UserCommentsForm userCommentForm = (UserCommentsForm) form;
85             String JavaDoc userCommentInodeString = req.getParameter("commentId");
86             long userCommentInode = Long.parseLong(userCommentInodeString);
87             UserComment userComment = UserCommentsFactory.getComment(userCommentInode);
88             long userProxyInode = userCommentForm.getUserProxy();
89             UserCommentsFactory.deleteUserComment(userProxyInode,userComment);
90         }
91         catch(Exception JavaDoc ex)
92         {
93             Logger.debug(this,ex.toString());
94         }
95     }
96     
97     public void _saveWebAsset(ActionRequest req, ActionResponse res, PortletConfig config, ActionForm form, User user) throws Exception JavaDoc
98     {
99         UserCommentsForm userCommentForm = (UserCommentsForm) form;
100         UserComment userComment = new UserComment();
101         BeanUtils.copyProperties(userComment,userCommentForm);
102         
103         //Copy additional fields
104
userComment.setCommentUserId(user.getUserId());
105         
106         Date JavaDoc now = new Date JavaDoc();
107         userComment.setDate(now);
108         
109         UserProxy userProxy = UserProxyFactory.getUserProxy(userCommentForm.getUserProxy());
110         userComment.setUserId(userProxy.getUserId());
111         
112         userComment.setMethod(userCommentForm.getMethod());
113         userComment.setTypeComment(userCommentForm.getTypeComment());
114         userComment.setSubject(userCommentForm.getSubject());
115         userComment.setComment(userCommentForm.getComment());
116
117         UserCommentsFactory.saveUserComment(userProxy.getInode(),userComment);
118     }
119 }
120
Popular Tags