001    /**
002     * Copyright 2005-2012 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     */
016    package org.kuali.rice.kns.util;
017    
018    import java.util.HashMap;
019    import java.util.Map;
020    
021    import javax.servlet.http.HttpServletRequest;
022    
023    import org.apache.struts.Globals;
024    import org.kuali.rice.kim.api.identity.Person;
025    import org.kuali.rice.krad.UserSession;
026    import org.kuali.rice.krad.exception.KualiExceptionIncident;
027    import org.kuali.rice.krad.util.KRADConstants;
028    
029    /**
030     * This is a description of what this class does - ewestfal don't forget to fill
031     * this in.
032     * 
033     * @author Kuali Rice Team (rice.collab@kuali.org)
034     * 
035     */
036    public final class IncidentReportUtils {
037    
038            /**
039         * Key to define the attribute stores exception properties such as
040         * user email, user name, component name, etc.
041         * <p>Value is exceptionProperties
042         */
043        public static final String EXCEPTION_PROPERTIES="exceptionProperties";
044        
045            private IncidentReportUtils() {
046                    throw new UnsupportedOperationException("do not call");
047            }
048    
049            public static Map<String, String> populateRequestForIncidentReport(Exception exception,
050                            String documentId, String componentName, HttpServletRequest request) {
051    
052                    // Create properties of form and user for additional information
053                    // to be displayed or passing through JSP
054                    Map<String, String> properties = new HashMap<String, String>();
055                    properties.put(KualiExceptionIncident.DOCUMENT_ID, documentId);
056                    String userEmail = "";
057                    String userName = "";
058                    String uuid = "";
059                    // No specific forward for the caught exception, use default logic
060                    // Get user information
061                    UserSession userSession = (UserSession) request.getSession()
062                                    .getAttribute(KRADConstants.USER_SESSION_KEY);
063                    Person sessionUser = null;
064                    if (userSession != null) {
065                            sessionUser = userSession.getPerson();
066                    }
067                    if (sessionUser != null) {
068                            userEmail = sessionUser.getEmailAddressUnmasked();
069                            userName = sessionUser.getName();
070                            uuid = sessionUser.getPrincipalName();
071                    }
072                    properties.put(KualiExceptionIncident.USER_EMAIL, userEmail);
073                    properties.put(KualiExceptionIncident.USER_NAME, userName);
074                    properties.put(KualiExceptionIncident.UUID, uuid);
075                    properties.put(KualiExceptionIncident.COMPONENT_NAME, componentName);
076    
077                    // Reset the exception so the forward action can read it
078                    request.setAttribute(Globals.EXCEPTION_KEY, exception);
079                    // Set exception current information
080                    request.setAttribute(EXCEPTION_PROPERTIES, properties);
081    
082                    return properties;
083    
084            }
085    }