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