1 package com.dotmarketing.portlets.jobs.action; 2 3 import java.util.Calendar ; 4 import java.util.GregorianCalendar ; 5 import javax.portlet.ActionRequest; 6 import javax.portlet.ActionResponse; 7 import javax.portlet.PortletConfig; 8 import javax.servlet.http.HttpServletRequest ; 9 import org.apache.commons.beanutils.BeanUtils; 10 import org.apache.struts.action.ActionForm; 11 import org.apache.struts.action.ActionMapping; 12 import com.dotmarketing.factories.InodeFactory; 13 import com.dotmarketing.portal.struts.DotPortletAction; 14 import com.dotmarketing.portlets.jobs.factories.SearchfirmFactory; 15 import com.dotmarketing.portlets.jobs.model.Searchfirm; 16 import com.dotmarketing.util.Constants; 17 import com.dotmarketing.util.Logger; 18 import com.dotmarketing.util.Validator; 19 import com.dotmarketing.util.WebKeys; 20 import com.liferay.portlet.ActionRequestImpl; 21 import com.liferay.util.servlet.SessionMessages; 22 23 24 public class EditSearchFirmAction extends DotPortletAction { 25 public void processAction(ActionMapping mapping, ActionForm form, PortletConfig config, ActionRequest req, 26 ActionResponse res) throws Exception { 27 String cmd = req.getParameter(com.liferay.portal.util.Constants.CMD); 28 29 ActionRequestImpl reqImpl = (ActionRequestImpl) req; 31 HttpServletRequest httpReq = reqImpl.getHttpServletRequest(); 32 33 String referer = req.getParameter("referer"); 34 35 _editSearchfirm(form, req, res); 37 38 if (com.liferay.portal.util.Constants.ADD.equals(cmd)) { 40 Logger.debug(this, "Searchfirm: Saving Searchfirm"); 41 42 if (!Validator.validate(req, form, mapping)) { 44 Logger.debug(this, "Searchfirm: Validation Searchfirm Failed"); 45 setForward(req, mapping.getInput()); 46 47 return; 48 } else { 49 try { 50 _saveSearchfirm(form, req, res); 51 } catch (Exception e) { 52 _handleException(e, req); 53 } 54 55 _sendToReferral(req, res, referer); 56 57 return; 58 } 59 } 60 else if (com.liferay.portal.util.Constants.DELETE.equals(cmd)) { 62 Logger.debug(this, "Searchfirm: Deleting Searchfirm"); 63 64 try { 65 _deleteSearchfirm(form, req, res); 66 } catch (Exception e) { 67 _handleException(e, req); 68 } 69 70 _sendToReferral(req, res, referer); 71 72 return; 73 } 74 75 else if (Constants.ACTIVATE.equals(cmd)) { 77 Logger.debug(this, "Searchfirm: Activating Searchfirm"); 78 79 try { 80 _activateSearchfirm(form, req, res); 81 } catch (Exception e) { 82 _handleException(e, req); 83 } 84 85 _sendToReferral(req, res, referer); 86 87 return; 88 } 89 90 BeanUtils.copyProperties(form, req.getAttribute(WebKeys.SEARCHFIRM_EDIT)); 91 setForward(req, "portlet.ext.jobs.edit_searchfirm"); 92 } 93 94 95 private void _saveSearchfirm(ActionForm form, ActionRequest req, ActionResponse res) 97 throws Exception { 98 99 BeanUtils.copyProperties(req.getAttribute(WebKeys.SEARCHFIRM_EDIT), form); 100 Searchfirm s = (Searchfirm) req.getAttribute(WebKeys.SEARCHFIRM_EDIT); 101 102 if(s.getExpirationdate() == null) { 103 if(s.isActive()) { 104 Calendar calendar = new GregorianCalendar (); 105 calendar.setTime(s.getCreationdate()); 106 calendar.add(Calendar.MONTH,12); 107 s.setExpirationdate(calendar.getTime()); 108 } 109 } 110 SearchfirmFactory.save(s); 111 SessionMessages.add(req, "message.searchfirm.save"); 112 } 113 114 private void _deleteSearchfirm(ActionForm form, ActionRequest req, ActionResponse res) 116 throws Exception { 117 Searchfirm Searchfirm = (Searchfirm) req.getAttribute(WebKeys.SEARCHFIRM_EDIT); 118 InodeFactory.deleteInode(Searchfirm); 119 SessionMessages.add(req, "message", "message.searchfirm.delete"); 120 } 121 122 private void _activateSearchfirm(ActionForm form, ActionRequest req, ActionResponse res) 124 throws Exception { 125 Searchfirm s = (Searchfirm)req.getAttribute(WebKeys.SEARCHFIRM_EDIT); 127 String activeStr = req.getParameter("active"); 128 boolean active = Boolean.parseBoolean(activeStr); 129 s.setActive(active); 130 if(s.isActive()) { 131 Calendar cal = new GregorianCalendar (); 132 cal.setTime(s.getCreationdate()); 133 cal.add(Calendar.MONTH,12); 134 s.setExpirationdate(cal.getTime()); 135 } 136 InodeFactory.saveInode(s); 137 } 138 139 private void _editSearchfirm(ActionForm form, ActionRequest req, ActionResponse res) 141 throws Exception { 142 Searchfirm searchfirm = SearchfirmFactory.getSearchfirm(req.getParameter("inode")); 143 req.setAttribute(WebKeys.SEARCHFIRM_EDIT, searchfirm); 144 } 145 } 146 | Popular Tags |