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.util.*; 40 import cowsultants.itracker.web.forms.*; 41 import cowsultants.itracker.web.util.*; 42 43 46 public class EditIssueFormAction extends ITrackerAction { 47 48 public EditIssueFormAction() { 49 } 50 51 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 52 ActionErrors errors = new ActionErrors(); 53 54 if(! isLoggedIn(request, response)) { 55 return mapping.findForward("login"); 56 } 57 58 try { 59 InitialContext ic = new InitialContext(); 60 61 Object ihRef = ic.lookup("java:comp/env/" + IssueHandler.JNDI_NAME); 62 IssueHandlerHome ihHome = (IssueHandlerHome) PortableRemoteObject.narrow(ihRef, IssueHandlerHome.class); 63 IssueHandler ih = ihHome.create(); 64 65 Integer issueId = new Integer ((request.getParameter("id") == null ? "-1" : (request.getParameter("id")))); 66 67 IssueModel issue = ih.getIssue(issueId); 68 ProjectModel project = ih.getIssueProject(issueId); 69 70 if(issue == null) { 71 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidissue")); 72 } else if(project == null) { 73 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidproject")); 74 } else if(project.getStatus() != ProjectUtilities.STATUS_ACTIVE) { 75 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.projectlocked")); 76 } else { 77 HttpSession session = request.getSession(true); 78 UserModel currUser = (UserModel) session.getAttribute(Constants.USER_KEY); 79 HashMap currPermissions = (HashMap) session.getAttribute(Constants.PERMISSIONS_KEY); 80 Locale currLocale = (Locale) session.getAttribute(Constants.LOCALE_KEY); 81 82 if(! IssueUtilities.canEditIssue(issue, currUser.getId(), currPermissions)) { 83 Logger.logDebug("Unauthorized user requested access to edit issue for project " + project.getId()); 84 return mapping.findForward("unauthorized"); 85 } 86 87 if(errors.isEmpty()) { 88 Logger.logDebug("Forwarding to edit issue form for issue " + issue.getId()); 89 DynaValidatorForm issueForm = (DynaValidatorForm) form; 90 if(issueForm == null) { 91 issueForm = new IssueForm(); 92 } 93 issueForm.set("id", issue.getId()); 94 issueForm.set("projectId", issue.getProjectId()); 95 issueForm.set("prevStatus", new Integer (issue.getStatus())); 96 issueForm.set("caller", request.getParameter("caller")); 97 98 issueForm.set("description", HTMLUtilities.handleQuotes(issue.getDescription())); 99 issueForm.set("status", new Integer (issue.getStatus())); 100 101 if(! ProjectUtilities.hasOption(ProjectUtilities.OPTION_PREDEFINED_RESOLUTIONS, project.getOptions())) { 102 try { 103 int resolutionNumber = Integer.parseInt(issue.getResolution()); 106 issue.setResolution(IssueUtilities.checkResolutionName(issue.getResolution(), currLocale)); 107 } catch(MissingResourceException mre) { 108 } catch(NumberFormatException nfe) { 109 } 110 } 111 issueForm.set("resolution", HTMLUtilities.handleQuotes(issue.getResolution())); 112 issueForm.set("severity", new Integer (issue.getSeverity())); 113 issueForm.set("targetVersion", (issue.getTargetVersionId() == null ? new Integer (-1) : issue.getTargetVersionId())); 114 issueForm.set("ownerId", (issue.getOwnerId() == null ? new Integer (-1) : issue.getOwnerId())); 115 116 IssueFieldModel[] fields = issue.getFields(); 117 HashMap customFields = new HashMap(); 118 for(int i = 0; i < fields.length; i++) { 119 customFields.put(fields[i].getCustomFieldId(), fields[i].getValue(currLocale)); 120 } 121 issueForm.set("customFields", customFields); 122 123 HashSet selectedComponents = ih.getIssueComponentIds(issueId); 124 if(selectedComponents != null) { 125 Integer [] components = new Integer [selectedComponents.size()]; 126 int i = 0; 127 for(Iterator iter = selectedComponents.iterator(); iter.hasNext(); i++) { 128 components[i] = (Integer ) iter.next(); 129 } 130 issueForm.set("components", components); 131 } 132 133 HashSet selectedVersions = ih.getIssueVersionIds(issueId); 134 if(selectedVersions != null) { 135 Integer [] versions = new Integer [selectedVersions.size()]; 136 int i = 0; 137 for(Iterator iter = selectedVersions.iterator(); iter.hasNext(); i++) { 138 versions[i] = (Integer ) iter.next(); 139 } 140 issueForm.set("versions", versions); 141 } 142 143 request.setAttribute("issueForm", issueForm); 144 session.setAttribute(Constants.ISSUE_KEY, issue); 145 saveToken(request); 146 return mapping.getInputForward(); 147 } 148 } 149 } catch(Exception e) { 150 Logger.logError("Exception while creating edit issue form.", e); 151 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.system")); 152 } 153 154 if(! errors.isEmpty()) { 155 saveErrors(request, errors); 156 } 157 158 return mapping.findForward("error"); 159 } 160 161 } 162 | Popular Tags |