1 18 19 package cowsultants.itracker.web.forms; 20 21 import java.rmi.*; 22 import java.util.*; 23 import javax.ejb.*; 24 import javax.rmi.*; 25 import javax.naming.*; 26 import javax.servlet.http.*; 27 28 import org.apache.commons.beanutils.*; 29 import org.apache.struts.action.*; 30 import org.apache.struts.validator.*; 31 import org.apache.struts.util.*; 32 33 import cowsultants.itracker.ejb.client.exceptions.*; 34 import cowsultants.itracker.ejb.client.interfaces.*; 35 import cowsultants.itracker.ejb.client.models.*; 36 import cowsultants.itracker.ejb.client.resources.*; 37 import cowsultants.itracker.ejb.client.util.*; 38 import cowsultants.itracker.web.util.*; 39 40 41 44 public class IssueForm extends DynaValidatorForm { 45 46 53 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { 54 ActionErrors errors = super.validate(mapping, request); 55 56 Logger.logDebug("Errors contains " + errors.size() + " errors."); 57 try { 58 ProjectModel project = null; 59 Integer projectId = (Integer ) PropertyUtils.getSimpleProperty(this, "projectId"); 60 if(projectId == null) { 61 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidproject")); 62 } else { 63 InitialContext ic = new InitialContext(); 64 Object phRef = ic.lookup("java:comp/env/" + ProjectHandler.JNDI_NAME); 65 ProjectHandlerHome phHome = (ProjectHandlerHome) PortableRemoteObject.narrow(phRef, ProjectHandlerHome.class); 66 ProjectHandler ph = phHome.create(); 67 68 project = ph.getProject(projectId); 69 } 70 71 if(errors.isEmpty() && project == null) { 72 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidproject")); 73 } else if(errors.isEmpty() && project.getStatus() != ProjectUtilities.STATUS_ACTIVE) { 74 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.projectlocked")); 75 } else if(errors.isEmpty()) { 76 Locale currLocale = ITrackerResources.getLocale(); 77 78 request.setAttribute(Constants.PROJECT_KEY, project); 79 80 CustomFieldModel[] projectFields = project.getCustomFields(); 81 if(projectFields.length > 0) { 82 HttpSession session = request.getSession(); 83 if(session != null) { 84 currLocale = (Locale) session.getAttribute(Constants.LOCALE_KEY); 85 } 86 87 for(int i = 0; i < projectFields.length; i++) { 88 String fieldValue = request.getParameter("customFields(" + projectFields[i].getId() +")"); 89 if(fieldValue != null && ! fieldValue.equals("")) { 90 IssueFieldModel issueField = new IssueFieldModel(projectFields[i]); 91 try { 92 issueField.setValue(fieldValue, currLocale); 93 } catch(IssueException ie) { 94 String label = CustomFieldUtilities.getCustomFieldName(projectFields[i].getId(), currLocale); 95 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(ie.getType(), label)); 96 } 97 } else if(projectFields[i].isRequired()) { 98 String label = CustomFieldUtilities.getCustomFieldName(projectFields[i].getId(), currLocale); 99 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(IssueException.TYPE_CF_REQ_FIELD, label)); 100 } 101 } 102 } 103 } 104 } catch(Exception e) { 105 e.printStackTrace(); 106 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.system")); 107 } 108 109 return errors; 110 } 111 112 } 113 | Popular Tags |