View Javadoc

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      private String methodToCall = "";
41      private String returnMapping;
42      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          return returnMapping;
49      }
50      public void setReturnMapping(String returnMapping) {
51          this.returnMapping = returnMapping;
52      }
53      public PreferencesForm() {
54          preferences = Preferences.Builder.create();
55      }
56      public String getMethodToCall() {
57          return methodToCall;
58      }
59      public void setMethodToCall(String methodToCall) {
60          this.methodToCall = methodToCall;
61      }
62      public Preferences.Builder getPreferences() {
63          return preferences;
64      }
65      public void setPreferences(Preferences.Builder preferences) {
66          this.preferences = preferences;
67      }
68      public boolean isShowOutbox() {
69          return this.showOutbox;
70      }
71      public void setShowOutbox(boolean showOutbox) {
72          this.showOutbox = showOutbox;
73      }
74      
75  	public String getBackLocation() {
76  		return this.backLocation;
77  	}
78  	public void setBackLocation(String backLocation) {
79  		this.backLocation = backLocation;
80  	}
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  		super.populate(request);
90  		
91          if (getParameter(request, KRADConstants.RETURN_LOCATION_PARAMETER) != null) {
92              setBackLocation(getParameter(request, KRADConstants.RETURN_LOCATION_PARAMETER));
93          }
94  	}
95  
96      public void validatePreferences() {
97       
98          try {
99              new Integer(preferences.getRefreshRate().trim());
100         } catch (NumberFormatException e) {
101             GlobalVariables.getMessageMap().putError(ERR_KEY_REFRESH_RATE_WHOLE_NUM, "general.message", "ActionList Refresh Rate must be in whole minutes");
102         } catch (NullPointerException e1) {
103             GlobalVariables.getMessageMap().putError(ERR_KEY_REFRESH_RATE_WHOLE_NUM, "general.message", "ActionList Refresh Rate must be in whole minutes");
104         }
105 
106         try {
107             if(new Integer(preferences.getPageSize().trim()) == 0){
108             	 GlobalVariables.getMessageMap().putError(ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM, "general.message", "ActionList Page Size must be non-zero ");
109             }    
110         } catch (NumberFormatException e) {
111             GlobalVariables.getMessageMap().putError(ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM, "general.message", "ActionList Page Size must be in whole minutes");
112         } catch (NullPointerException e1) {
113             GlobalVariables.getMessageMap().putError(ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM, "general.message", "ActionList Page Size must be in whole minutes");
114         }
115       
116         if (GlobalVariables.getMessageMap().hasErrors()) {
117             throw new ValidationException("errors in preferences");
118         }
119     }
120 }