1 18 19 package cowsultants.itracker.web.actions; 20 21 import java.io.*; 22 import java.rmi.*; 23 import java.util.*; 24 import javax.ejb.*; 25 import javax.rmi.*; 26 import javax.naming.*; 27 import javax.servlet.*; 28 import javax.servlet.http.*; 29 30 import org.apache.commons.beanutils.*; 31 import org.apache.struts.action.*; 32 import org.apache.struts.upload.*; 33 import org.apache.struts.util.*; 34 35 import cowsultants.itracker.ejb.client.exceptions.*; 36 import cowsultants.itracker.ejb.client.interfaces.*; 37 import cowsultants.itracker.ejb.client.models.*; 38 import cowsultants.itracker.ejb.client.resources.*; 39 import cowsultants.itracker.ejb.client.util.*; 40 import cowsultants.itracker.web.util.*; 41 42 43 public class MoveIssueAction extends ITrackerAction { 44 45 public MoveIssueAction() { 46 } 47 48 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 49 ActionErrors errors = new ActionErrors(); 50 51 if(! isLoggedIn(request, response)) { 52 return mapping.findForward("login"); 53 } 54 if(! isTokenValid(request)) { 55 Logger.logDebug("Invalid request token while creating issue."); 56 return mapping.findForward("index"); 57 } 58 resetToken(request); 59 60 try { 61 InitialContext ic = new InitialContext(); 62 Object ihRef = ic.lookup("java:comp/env/" + IssueHandler.JNDI_NAME); 63 IssueHandlerHome ihHome = (IssueHandlerHome) PortableRemoteObject.narrow(ihRef, IssueHandlerHome.class); 64 IssueHandler ih = ihHome.create(); 65 66 Integer issueId = (Integer ) PropertyUtils.getSimpleProperty(form, "issueId"); 67 Integer projectId = (Integer ) PropertyUtils.getSimpleProperty(form, "projectId"); 68 String caller = (String ) PropertyUtils.getSimpleProperty(form, "caller"); 69 if(caller == null) { 70 caller = "index"; 71 } 72 73 IssueModel issue = ih.getIssue(issueId); 74 if(issue == null) { 75 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidissue")); 76 } 77 78 if(errors.isEmpty()) { 79 HttpSession session = request.getSession(true); 80 UserModel user = (UserModel) session.getAttribute(Constants.USER_KEY); 81 HashMap userPermissions = (HashMap) session.getAttribute(Constants.PERMISSIONS_KEY); 82 83 if(! UserUtilities.hasPermission(userPermissions, issue.getProjectId(), UserUtilities.PERMISSION_EDIT)) { 84 Logger.logDebug("User not authorized to move issue " + issueId); 85 return mapping.findForward("unauthorized"); 86 } 87 if(! UserUtilities.hasPermission(userPermissions, projectId, new int[] {UserUtilities.PERMISSION_EDIT, UserUtilities.PERMISSION_CREATE})) { 88 Logger.logDebug("User attempted to move issue " + issueId + " to unauthorized project."); 89 return mapping.findForward("unauthorized"); 90 } 91 92 ih.moveIssue(issue, projectId, user.getId()); 93 94 session.removeAttribute(Constants.PROJECTS_KEY); 95 session.removeAttribute(Constants.ISSUE_KEY); 96 97 if("editissue".equals((String ) PropertyUtils.getSimpleProperty(form, "caller"))) { 98 return new ActionForward(mapping.findForward("editissue").getPath() + "?id=" + issue.getId()); 99 } else if("viewissue".equals((String ) PropertyUtils.getSimpleProperty(form, "caller"))) { 100 return new ActionForward(mapping.findForward("viewissue").getPath() + "?id=" + issue.getId()); 101 } else { 102 return mapping.findForward("index"); 103 } 104 } 105 } catch(Exception e) { 106 Logger.logError("Exception processing form data", e); 107 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.system")); 108 } 109 110 if(! errors.isEmpty()) { 111 saveErrors(request, errors); 112 } 113 return mapping.findForward("error"); 114 } 115 116 } 117 | Popular Tags |