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 import org.apache.struts.validator.*; 35 36 import cowsultants.itracker.ejb.client.exceptions.*; 37 import cowsultants.itracker.ejb.client.interfaces.*; 38 import cowsultants.itracker.ejb.client.models.*; 39 import cowsultants.itracker.ejb.client.resources.*; 40 import cowsultants.itracker.ejb.client.util.*; 41 import cowsultants.itracker.web.forms.*; 42 import cowsultants.itracker.web.util.*; 43 44 45 public class CreateIssueFormAction extends ITrackerAction { 46 47 public CreateIssueFormAction() { 48 } 49 50 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 51 ActionErrors errors = new ActionErrors(); 52 53 if(! isLoggedIn(request, response)) { 54 return mapping.findForward("login"); 55 } 56 57 try { 58 InitialContext ic = new InitialContext(); 59 60 Object phRef = ic.lookup("java:comp/env/" + ProjectHandler.JNDI_NAME); 61 ProjectHandlerHome phHome = (ProjectHandlerHome) PortableRemoteObject.narrow(phRef, ProjectHandlerHome.class); 62 ProjectHandler ph = phHome.create(); 63 64 Object uhRef = ic.lookup("java:comp/env/" + UserHandler.JNDI_NAME); 65 UserHandlerHome uhHome = (UserHandlerHome) PortableRemoteObject.narrow(uhRef, UserHandlerHome.class); 66 UserHandler uh = uhHome.create(); 67 68 Integer projectId = new Integer ((request.getParameter("pid") == null ? "-1" : (request.getParameter("pid")))); 69 70 HttpSession session = request.getSession(true); 71 UserModel currUser = (UserModel) session.getAttribute(Constants.USER_KEY); 72 HashMap currPermissions = (HashMap) session.getAttribute(Constants.PERMISSIONS_KEY); 73 74 if(! UserUtilities.hasPermission(currPermissions, projectId, UserUtilities.PERMISSION_CREATE)) { 75 Logger.logDebug("Unauthorized user requested access to create issue for project " + projectId); 76 return mapping.findForward("unauthorized"); 77 } 78 79 ProjectModel project = ph.getProject(projectId); 80 Logger.logDebug("Received request for project " + projectId + "(" + project.getName() + ")"); 81 82 if(project == null) { 83 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidproject")); 84 } else if(project.getStatus() != ProjectUtilities.STATUS_ACTIVE) { 85 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.projectlocked")); 86 } 87 88 if(errors.isEmpty()) { 89 DynaValidatorForm issueForm = (DynaValidatorForm) form; 90 if(issueForm == null) { 91 issueForm = new IssueForm(); 92 } 93 issueForm.set("creatorId", currUser.getId()); 94 NameValuePairModel[] severities = IssueUtilities.getSeverities(ITrackerResources.getLocale()); 95 if(severities.length > 0) { 96 try { 97 int midPoint = (severities.length / 2); 98 issueForm.set("severity", new Integer (severities[midPoint].getValue())); 99 } catch(NumberFormatException nfe) { 100 Logger.logDebug("Invalid status number found while preparing create issue form."); 101 } 102 } 103 104 VersionModel[] versions = project.getVersions(); 105 if(versions.length > 0) { 106 Arrays.sort(versions, new VersionModel()); 107 issueForm.set("versions", new Integer [] {versions[0].getId()}); 108 } 109 110 Logger.logDebug("Forwarding to create issue form for project " + project.getId()); 111 request.setAttribute("issueForm", issueForm); 112 session.setAttribute(Constants.PROJECT_KEY, project); 113 saveToken(request); 114 return mapping.getInputForward(); 115 } 116 } catch(Exception e) { 117 Logger.logError("Exception while creating create issue form.", e); 118 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.system")); 119 } 120 121 if(! errors.isEmpty()) { 122 saveErrors(request, errors); 123 } 124 return mapping.findForward("error"); 125 } 126 127 } 128 | Popular Tags |