001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kns.web.struts.form; 017 018import org.apache.log4j.Logger; 019import org.apache.struts.action.ActionMapping; 020import org.kuali.rice.krad.exception.ExceptionIncident; 021import org.kuali.rice.krad.util.KRADConstants; 022 023import javax.servlet.http.HttpServletRequest; 024import java.util.HashMap; 025import java.util.HashSet; 026import java.util.Map; 027import java.util.Set; 028 029/** 030 * This class is the action form for all Question Prompts. 031 * 032 * 033 */ 034public class KualiExceptionIncidentForm extends KualiForm { 035 private static final long serialVersionUID = 831951332440283401L; 036 private static Logger LOG=Logger.getLogger(KualiExceptionIncidentForm.class); 037 038 /** 039 * The form properties that should be populated in order for the toMap() method to function properly. 040 */ 041 private static final Set<String> PROPS_NEEDED_FOR_MAP = new HashSet<String>(); 042 static { 043 PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.DOCUMENT_ID); 044 PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.USER_EMAIL); 045 PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.USER_NAME); 046 PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.UUID); 047 PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.COMPONENT_NAME); 048 PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.DESCRIPTION); 049 PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.EXCEPTION_REPORT_SUBJECT); 050 PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.EXCEPTION_MESSAGE); 051 PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.DISPLAY_MESSAGE); 052 PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.STACK_TRACE); 053 } 054 055 /** 056 * Flag to determine whether it's cancel action 057 */ 058 private boolean cancel=false; 059 /** 060 * Object containing exception information 061 */ 062// private KualiExceptionIncident exceptionIncident; 063 /** 064 * The error subject created from current settings and thrown exception 065 */ 066 private String exceptionReportSubject; 067 /** 068 * The error message 069 */ 070 private String exceptionMessage; 071 /** 072 * The error message to be displayed 073 */ 074 private String displayMessage; 075 /** 076 * Additional message from user 077 */ 078 private String description; 079 /** 080 * Document id. it's blank if not a document process 081 */ 082 private String documentId=""; 083 /** 084 * Session user email address 085 */ 086 private String userEmail=""; 087 /** 088 * Session user name 089 */ 090 private String principalName=""; 091 /** 092 * Session user name 093 */ 094 private String userName=""; 095 /** 096 * Detail message not for displaying 097 */ 098 private String stackTrace; 099 /** 100 * Form that threw the exception 101 */ 102 private String componentName; 103 104 /** 105 * @see org.kuali.rice.krad.web.struts.pojo.PojoForm#populate(javax.servlet.http.HttpServletRequest) 106 */ 107 public void populate(HttpServletRequest request) { 108 109 super.populate(request); 110 111 // KULRICE-4402: ie explorer needs this. 112 if(notNull(request.getParameter(KRADConstants.CANCEL_METHOD + ".x")) && notNull(request.getParameter( 113 KRADConstants.CANCEL_METHOD + ".y"))){ 114 this.setCancel(true); 115 } 116 } 117 118 private boolean notNull(String s){ 119 if(s != null && !"".equals(s)){ 120 return true; 121 }else 122 return false; 123 } 124 125 /* 126 * Reset method - reset attributes of form retrieved from session otherwise 127 * we will always call docHandler action 128 * @param mapping 129 * @param request 130 */ 131 public void reset(ActionMapping mapping, HttpServletRequest request) { 132 133 this.setMethodToCall(null); 134 this.setRefreshCaller(null); 135 this.setAnchor(null); 136 this.setCurrentTabIndex(0); 137 138 this.cancel=false; 139 this.documentId=null; 140 this.componentName=null; 141 this.description=null; 142 this.displayMessage=null; 143 this.exceptionMessage=null; 144 this.stackTrace=null; 145 this.userEmail=null; 146 this.userName=null; 147 this.principalName=null; 148 149 } 150 151 /** 152 * This method return list of required information contained by the jsp in both 153 * display and hidden properties. 154 * 155 * @return 156 * <p>Example: 157 * <code> 158 * documentId, 2942084 159 * userEmail, someone@somewhere 160 * userName, some name 161 * componentFormName, Form that threw exception name 162 * exceptionMessage, Error message from exception 163 * displayMessage, Either exception error message or generic exception error message 164 * stackTrace, Exception stack trace here 165 * </code> 166 * 167 */ 168 public Map<String, String> toMap() { 169 if (LOG.isTraceEnabled()) { 170 String message=String.format("ENTRY"); 171 LOG.trace(message); 172 } 173 174 Map<String, String> map=new HashMap<String, String>(); 175 map.put(ExceptionIncident.DOCUMENT_ID, this.documentId); 176 map.put(ExceptionIncident.USER_EMAIL, this.userEmail); 177 map.put(ExceptionIncident.USER_NAME, this.userName); 178 map.put(ExceptionIncident.UUID, this.principalName); 179 map.put(ExceptionIncident.COMPONENT_NAME, this.componentName); 180 map.put(ExceptionIncident.DESCRIPTION, this.description); 181 map.put(ExceptionIncident.EXCEPTION_REPORT_SUBJECT, this.exceptionReportSubject); 182 map.put(ExceptionIncident.EXCEPTION_MESSAGE, this.exceptionMessage); 183 map.put(ExceptionIncident.DISPLAY_MESSAGE, this.displayMessage); 184 map.put(ExceptionIncident.STACK_TRACE, this.stackTrace); 185 186 if (LOG.isTraceEnabled()) { 187 String message=String.format("ENTRY %s", map.toString()); 188 LOG.trace(message); 189 } 190 191 return map; 192 } 193 194 /** 195 * @return the cancel 196 */ 197 public final boolean isCancel() { 198 return this.cancel; 199 } 200 201 /** 202 * @param cancel the cancel to set 203 */ 204 public final void setCancel(boolean cancel) { 205 this.cancel = cancel; 206 } 207 208 /** 209 * @return the exceptionIncident 210 */ 211// public final KualiExceptionIncident getExceptionIncident() { 212// return this.exceptionIncident; 213// } 214 215 /** 216 * @return the description 217 */ 218 public final String getDescription() { 219 return this.description; 220 } 221 222 /** 223 * @param description the description to set 224 */ 225 public final void setDescription(String description) { 226 this.description = description; 227 } 228 229 /** 230 * @return the exceptionMessage 231 */ 232 public final String getExceptionMessage() { 233 return this.exceptionMessage; 234 } 235 236 /** 237 * @param exceptionMessage the exceptionMessage to set 238 */ 239 public final void setExceptionMessage(String exceptionMessage) { 240 this.exceptionMessage = exceptionMessage; 241 } 242 243 /** 244 * @return the displayMessage 245 */ 246 public final String getDisplayMessage() { 247 return this.displayMessage; 248 } 249 250 /** 251 * @param displayMessage the displayMessage to set 252 */ 253 public final void setDisplayMessage(String displayMessage) { 254 this.displayMessage = displayMessage; 255 } 256 257 /** 258 * @return the documentId 259 */ 260 public final String getDocumentId() { 261 return this.documentId; 262 } 263 264 /** 265 * @param documentId the documentId to set 266 */ 267 public final void setDocumentId(String documentId) { 268 this.documentId = documentId; 269 } 270 271 /** 272 * @return the userEmail 273 */ 274 public final String getUserEmail() { 275 return this.userEmail; 276 } 277 278 /** 279 * @param userEmail the userEmail to set 280 */ 281 public final void setUserEmail(String userEmail) { 282 this.userEmail = userEmail; 283 } 284 285 /** 286 * @return the principalName 287 */ 288 public String getPrincipalName() { 289 return this.principalName; 290 } 291 292 /** 293 * @param principalName the principalName to set 294 */ 295 public void setPrincipalName(String principalName) { 296 this.principalName = principalName; 297 } 298 299 /** 300 * @return the userName 301 */ 302 public final String getUserName() { 303 return this.userName; 304 } 305 306 /** 307 * @param userName the userName to set 308 */ 309 public final void setUserName(String userName) { 310 this.userName = userName; 311 } 312 313 /** 314 * @param stackTrace the stackTrace to set 315 */ 316 public final void setStackTrace(String stackTrace) { 317 this.stackTrace = stackTrace; 318 } 319 320 /** 321 * @return the stackTrace 322 */ 323 public final String getStackTrace() { 324 return this.stackTrace; 325 } 326 327 /** 328 * @return the exceptionReportSubject 329 */ 330 public final String getExceptionReportSubject() { 331 return this.exceptionReportSubject; 332 } 333 334 /** 335 * @param exceptionReportSubject the exceptionReportSubject to set 336 */ 337 public final void setExceptionReportSubject(String exceptionReportSubject) { 338 this.exceptionReportSubject = exceptionReportSubject; 339 } 340 341 /** 342 * @return the componentName 343 */ 344 public final String getComponentName() { 345 return this.componentName; 346 } 347 348 /** 349 * @param componentName the componentName to set 350 */ 351 public final void setComponentName(String componentName) { 352 this.componentName = componentName; 353 } 354 355 /** 356 * This overridden method ... 357 * 358 * @see org.kuali.rice.krad.web.struts.form.KualiForm#shouldMethodToCallParameterBeUsed(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest) 359 */ 360 @Override 361 public boolean shouldMethodToCallParameterBeUsed( 362 String methodToCallParameterName, 363 String methodToCallParameterValue, HttpServletRequest request) { 364 // we will allow all method to calls since the KualiExceptionHandlerAction will ignore the methodToCall 365 return true; 366 } 367 368 /** 369 * @see org.kuali.rice.krad.web.struts.form.KualiForm#shouldPropertyBePopulatedInForm(java.lang.String, javax.servlet.http.HttpServletRequest) 370 */ 371 @Override 372 public boolean shouldPropertyBePopulatedInForm( 373 String requestParameterName, HttpServletRequest request) { 374 if (PROPS_NEEDED_FOR_MAP.contains(requestParameterName)) { 375 return true; 376 } 377 else if (KRADConstants.CANCEL_METHOD.equals(requestParameterName)) { 378 return true; 379 } 380 return super.shouldPropertyBePopulatedInForm(requestParameterName, request); 381 } 382} 383