1 5 package com.dotmarketing.portlets.eventsapproval.action; 6 7 import java.net.URLDecoder ; 8 import java.util.Iterator ; 9 import java.util.List ; 10 11 import javax.portlet.ActionRequest; 12 import javax.portlet.ActionResponse; 13 import javax.portlet.PortletConfig; 14 import javax.servlet.http.HttpServletRequest ; 15 16 import org.apache.struts.action.ActionForm; 17 import org.apache.struts.action.ActionMapping; 18 import org.apache.struts.action.ActionMessage; 19 import org.apache.struts.action.ActionMessages; 20 21 import com.dotmarketing.db.DotHibernate; 22 import com.dotmarketing.factories.InodeFactory; 23 import com.dotmarketing.portal.struts.DotPortletAction; 24 import com.dotmarketing.portlets.events.factories.EventFactory; 25 import com.dotmarketing.portlets.events.model.Event; 26 import com.dotmarketing.portlets.events.model.Recurance; 27 import com.dotmarketing.portlets.facilities.model.Facility; 28 import com.dotmarketing.util.WebKeys; 29 import com.liferay.portal.model.User; 30 import com.liferay.portal.struts.ActionException; 31 import com.liferay.portal.util.Constants; 32 import com.liferay.portlet.ActionRequestImpl; 33 34 35 39 public class EditEventAction extends DotPortletAction { 40 41 public static boolean debug = false; 42 43 public void processAction( 44 ActionMapping mapping, ActionForm form, PortletConfig config, 45 ActionRequest req, ActionResponse res) 46 throws Exception { 47 48 String cmd = (req.getParameter(Constants.CMD)!=null)? req.getParameter(Constants.CMD) : Constants.EDIT; 49 String referer = req.getParameter("referer"); 50 51 if ((referer!=null) && (referer.length()!=0)) { 52 referer = URLDecoder.decode(referer,"UTF-8"); 53 } 54 55 DotHibernate dh = new DotHibernate(); 56 dh.startTransaction(); 57 User user = _getUser(req); 58 59 try { 60 _retrieveEvent(req, res, config, form, user); 61 62 } catch (ActionException ae) { 63 _handleException(ae, req); 64 } 65 66 Event e = (Event) req.getAttribute(WebKeys.EVENT_EDIT); 67 68 69 if (!EventFactory.isAnEventAdministrator(user)) 70 { 71 ActionRequestImpl reqImpl = (ActionRequestImpl) req; 72 HttpServletRequest httpReq = reqImpl.getHttpServletRequest(); 73 ActionMessages am = new ActionMessages(); 74 am.add("messages",new ActionMessage("message.permissions.error")); 75 saveMessages(httpReq,am); 76 List events = EventFactory.getEventsWaitingForApproval(); 77 req.setAttribute("events", events); 78 79 setForward(req,"portlet.ext.eventsapproval.view_events"); 80 dh.commitTransaction(); 81 return; 82 } 83 84 87 else if ((cmd != null) && cmd.equals(com.dotmarketing.util.Constants.APPROVE)) { 88 try { 89 90 _approveEvent(req, res, config, form, user); 91 setForward(req,"portlet.ext.eventsapproval.view_events"); 92 93 } catch (ActionException ae) { 94 _handleException(ae, req); 95 return; 96 } 97 } 98 101 else if ((cmd != null) && cmd.equals(com.dotmarketing.util.Constants.DISAPPROVE)) { 102 try { 103 104 _disapproveEvent(req, res, config, form, user); 105 setForward(req,"portlet.ext.eventsapproval.view_events"); 106 107 } catch (ActionException ae) { 108 _handleException(ae, req); 109 return; 110 } 111 } 112 dh.commitTransaction(); 113 114 List events = EventFactory.getEventsWaitingForApproval(); 115 req.setAttribute("events", events); 116 117 118 } 119 120 121 123 private void _retrieveEvent(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user) 124 throws Exception { 125 126 String inode = (req.getParameter("eventInode")!=null) ? req.getParameter("eventInode") : "0"; 127 Event e = null; 128 if(inode.equals("0")){ 129 e = EventFactory.newInstance(); 130 } else { 131 e = EventFactory.getEvent(inode); 132 } 133 req.setAttribute(WebKeys.EVENT_EDIT, e); 134 Recurance r = (Recurance) InodeFactory.getChildOfClass(e, Recurance.class); 135 req.setAttribute(WebKeys.RECURANCE_EDIT, r); 136 } 137 138 private void _approveEvent(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user) 139 throws Exception { 140 141 Event e = ( Event ) req.getAttribute(WebKeys.EVENT_EDIT); 142 Recurance r = (Recurance) req.getAttribute(WebKeys.RECURANCE_EDIT); 143 144 if (e.getInode() > 0) { 145 if (r.getInode() > 0) { 146 List events = InodeFactory.getParentsOfClass(r, Event.class); 147 Iterator it = events.iterator(); 148 while (it.hasNext()) { 149 Event ev = (Event) it.next(); 150 Facility facility = (Facility) InodeFactory.getParentOfClass(e,Facility.class); 151 List conflicts = EventFactory.findConflicts(ev,facility); 152 if(conflicts.size() == 0) 153 { 154 ev.setApprovalStatus(com.dotmarketing.util.Constants.EVENT_APPROVED_STATUS); 155 InodeFactory.saveInode(ev); 156 } 157 } 158 } 159 else 160 { 161 e.setApprovalStatus(com.dotmarketing.util.Constants.EVENT_APPROVED_STATUS); 162 InodeFactory.saveInode(e); 163 } 164 Facility fac = (Facility) InodeFactory.getParentOfClass(e, Facility.class); 165 EventFactory.sendEmailNotification(e, fac, user, true); 166 } 167 } 168 169 private void _disapproveEvent(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user) 170 throws Exception { 171 172 Event e = ( Event ) req.getAttribute(WebKeys.EVENT_EDIT); 173 Recurance r = (Recurance) req.getAttribute(WebKeys.RECURANCE_EDIT); 174 175 if (e.getInode() > 0) { 176 if (r.getInode() > 0) { 177 List events = InodeFactory.getParentsOfClass(r, Event.class); 178 Iterator it = events.iterator(); 179 while (it.hasNext()) { 180 Event ev = (Event) it.next(); 181 if(ev.getApprovalStatus() == com.dotmarketing.util.Constants.EVENT_WAITING_APPROVAL_STATUS) 182 { 183 ev.setApprovalStatus(com.dotmarketing.util.Constants.EVENT_DISAPPROVED_STATUS); 184 InodeFactory.saveInode(ev); 185 } 186 } 187 } else { 188 e.setApprovalStatus(com.dotmarketing.util.Constants.EVENT_DISAPPROVED_STATUS); 189 InodeFactory.saveInode(e); 190 } 191 192 Facility fac = (Facility) InodeFactory.getParentOfClass(e, Facility.class); 193 EventFactory.sendEmailNotification(e, fac, user, true); 194 } 195 } 196 197 } 198 199 | Popular Tags |