View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kns.web.struts.form;
17  
18  import org.apache.log4j.Logger;
19  import org.apache.struts.action.ActionMapping;
20  import org.kuali.rice.krad.exception.ExceptionIncident;
21  import org.kuali.rice.krad.util.KRADConstants;
22  
23  import javax.servlet.http.HttpServletRequest;
24  import java.util.HashMap;
25  import java.util.HashSet;
26  import java.util.Map;
27  import java.util.Set;
28  
29  /**
30   * This class is the action form for all Question Prompts.
31   * 
32   * 
33   */
34  public class KualiExceptionIncidentForm extends KualiForm {
35      private static final long serialVersionUID = 831951332440283401L;
36      private static Logger LOG=Logger.getLogger(KualiExceptionIncidentForm.class); 
37      
38      /**
39       * The form properties that should be populated in order for the toMap() method to function properly.
40       */
41      private static final Set<String> PROPS_NEEDED_FOR_MAP = new HashSet<String>();
42      static {
43      	PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.DOCUMENT_ID);
44      	PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.USER_EMAIL);
45      	PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.USER_NAME);
46      	PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.UUID);
47      	PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.COMPONENT_NAME);
48      	PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.DESCRIPTION);
49      	PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.EXCEPTION_REPORT_SUBJECT);
50      	PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.EXCEPTION_MESSAGE);
51      	PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.DISPLAY_MESSAGE);
52      	PROPS_NEEDED_FOR_MAP.add(ExceptionIncident.STACK_TRACE);
53      }
54      
55      /**
56       * Flag to determine whether it's cancel action
57       */
58      private boolean cancel=false;
59      /**
60       * Object containing exception information
61       */
62  //    private KualiExceptionIncident exceptionIncident;
63      /**
64       * The error subject created from current settings and thrown exception
65       */
66       private String exceptionReportSubject;
67      /**
68       * The error message
69       */
70       private String exceptionMessage;
71       /**
72        * The error message to be displayed
73        */
74        private String displayMessage;
75       /**
76       * Additional message from user
77       */
78       private String description;
79       /**
80        * Document id. it's blank if not a document process
81        */
82       private String documentId=""; 
83       /**
84        * Session user email address
85        */
86       private String userEmail="";
87       /**
88        * Session user name
89        */
90       private String principalName="";
91       /**
92        * Session user name
93        */
94       private String userName="";
95       /**
96        * Detail message not for displaying
97        */
98       private String stackTrace;
99       /**
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