View Javadoc

1   /**
2    * Copyright 2005-2013 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.util;
17  
18  import org.apache.struts.Globals;
19  import org.kuali.rice.kim.api.identity.Person;
20  import org.kuali.rice.krad.UserSession;
21  import org.kuali.rice.krad.exception.KualiExceptionIncident;
22  import org.kuali.rice.krad.util.KRADConstants;
23  
24  import javax.servlet.http.HttpServletRequest;
25  import java.util.HashMap;
26  import java.util.Map;
27  
28  /**
29   * Utility methods for use with the incident report functionality.
30   *
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   * 
33   */
34  public final class IncidentReportUtils {
35  
36  	/**
37       * Key to define the attribute stores exception properties such as
38       * user email, user name, component name, etc.
39       * <p>Value is exceptionProperties
40       */
41      public static final String EXCEPTION_PROPERTIES="exceptionProperties";
42      
43  	private IncidentReportUtils() {
44  		throw new UnsupportedOperationException("do not call");
45  	}
46  
47  	public static Map<String, String> populateRequestForIncidentReport(Exception exception,
48  			String documentId, String componentName, HttpServletRequest request) {
49  
50  		// Create properties of form and user for additional information
51  		// to be displayed or passing through JSP
52  		Map<String, String> properties = new HashMap<String, String>();
53  		properties.put(KualiExceptionIncident.DOCUMENT_ID, documentId);
54  		String userEmail = "";
55  		String userName = "";
56  		String uuid = "";
57  		// No specific forward for the caught exception, use default logic
58  		// Get user information
59  		UserSession userSession = (UserSession) request.getSession()
60  				.getAttribute(KRADConstants.USER_SESSION_KEY);
61  		Person sessionUser = null;
62  		if (userSession != null) {
63  			sessionUser = userSession.getPerson();
64  		}
65  		if (sessionUser != null) {
66  			userEmail = sessionUser.getEmailAddressUnmasked();
67  			userName = sessionUser.getName();
68  			uuid = sessionUser.getPrincipalName();
69  		}
70  		properties.put(KualiExceptionIncident.USER_EMAIL, userEmail);
71  		properties.put(KualiExceptionIncident.USER_NAME, userName);
72  		properties.put(KualiExceptionIncident.UUID, uuid);
73  		properties.put(KualiExceptionIncident.COMPONENT_NAME, componentName);
74  
75  		// Reset the exception so the forward action can read it
76  		request.setAttribute(Globals.EXCEPTION_KEY, exception);
77  		// Set exception current information
78  		request.setAttribute(EXCEPTION_PROPERTIES, properties);
79  
80  		return properties;
81  
82  	}
83  }