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