Coverage Report - org.kuali.rice.kew.preferences.web.PreferencesForm
 
Classes in this File Line Coverage Branch Coverage Complexity
PreferencesForm
0%
0/40
0%
0/6
1.615
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.kew.preferences.web;
 17  
 
 18  
 import javax.servlet.http.HttpServletRequest;
 19  
 
 20  
 import org.kuali.rice.kew.api.preferences.Preferences;
 21  
 import org.kuali.rice.kns.web.struts.form.KualiForm;
 22  
 import org.kuali.rice.krad.exception.ValidationException;
 23  
 import org.kuali.rice.krad.util.GlobalVariables;
 24  
 import org.kuali.rice.krad.util.KRADConstants;
 25  
 
 26  
 
 27  
 /**
 28  
  * Struts ActionForm for {@link PreferencesAction}.
 29  
  *
 30  
  * @see PreferencesAction
 31  
  *
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  */
 34  
 public class PreferencesForm extends KualiForm {
 35  
 
 36  
     private static final long serialVersionUID = 4536869031291955777L;
 37  
     private static final String ERR_KEY_REFRESH_RATE_WHOLE_NUM = "preferences.refreshRate";
 38  
     private static final String ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM = "preferences.pageSize";
 39  
         private Preferences.Builder preferences;
 40  0
     private String methodToCall = "";
 41  
     private String returnMapping;
 42  0
     private boolean showOutbox = true;
 43  
 
 44  
     // KULRICE-3137: Added a backLocation parameter similar to the one from lookups.
 45  
     private String backLocation;
 46  
     
 47  
         public String getReturnMapping() {
 48  0
         return returnMapping;
 49  
     }
 50  
     public void setReturnMapping(String returnMapping) {
 51  0
         this.returnMapping = returnMapping;
 52  0
     }
 53  0
     public PreferencesForm() {
 54  0
         preferences = Preferences.Builder.create();
 55  0
     }
 56  
     public String getMethodToCall() {
 57  0
         return methodToCall;
 58  
     }
 59  
     public void setMethodToCall(String methodToCall) {
 60  0
         this.methodToCall = methodToCall;
 61  0
     }
 62  
     public Preferences.Builder getPreferences() {
 63  0
         return preferences;
 64  
     }
 65  
     public void setPreferences(Preferences.Builder preferences) {
 66  0
         this.preferences = preferences;
 67  0
     }
 68  
     public boolean isShowOutbox() {
 69  0
         return this.showOutbox;
 70  
     }
 71  
     public void setShowOutbox(boolean showOutbox) {
 72  0
         this.showOutbox = showOutbox;
 73  0
     }
 74  
     
 75  
         public String getBackLocation() {
 76  0
                 return this.backLocation;
 77  
         }
 78  
         public void setBackLocation(String backLocation) {
 79  0
                 this.backLocation = backLocation;
 80  0
         }
 81  
         
 82  
         /**
 83  
          * Retrieves the "returnLocation" parameter after calling "populate" on the superclass.
 84  
          * 
 85  
          * @see org.kuali.rice.krad.web.struts.form.KualiForm#populate(javax.servlet.http.HttpServletRequest)
 86  
          */
 87  
         @Override
 88  
         public void populate(HttpServletRequest request) {
 89  0
                 super.populate(request);
 90  
                 
 91  0
         if (getParameter(request, KRADConstants.RETURN_LOCATION_PARAMETER) != null) {
 92  0
             setBackLocation(getParameter(request, KRADConstants.RETURN_LOCATION_PARAMETER));
 93  
         }
 94  0
         }
 95  
 
 96  
     public void validatePreferences() {
 97  
      
 98  
         try {
 99  0
             new Integer(preferences.getRefreshRate().trim());
 100  0
         } catch (NumberFormatException e) {
 101  0
             GlobalVariables.getMessageMap().putError(ERR_KEY_REFRESH_RATE_WHOLE_NUM, "general.message", "ActionList Refresh Rate must be in whole minutes");
 102  0
         } catch (NullPointerException e1) {
 103  0
             GlobalVariables.getMessageMap().putError(ERR_KEY_REFRESH_RATE_WHOLE_NUM, "general.message", "ActionList Refresh Rate must be in whole minutes");
 104  0
         }
 105  
 
 106  
         try {
 107  0
             if(new Integer(preferences.getPageSize().trim()) == 0){
 108  0
                      GlobalVariables.getMessageMap().putError(ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM, "general.message", "ActionList Page Size must be non-zero ");
 109  
             }    
 110  0
         } catch (NumberFormatException e) {
 111  0
             GlobalVariables.getMessageMap().putError(ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM, "general.message", "ActionList Page Size must be in whole minutes");
 112  0
         } catch (NullPointerException e1) {
 113  0
             GlobalVariables.getMessageMap().putError(ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM, "general.message", "ActionList Page Size must be in whole minutes");
 114  0
         }
 115  
       
 116  0
         if (GlobalVariables.getMessageMap().hasErrors()) {
 117  0
             throw new ValidationException("errors in preferences");
 118  
         }
 119  0
     }
 120  
 }