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.kew.preferences.web; 017 018 import javax.servlet.http.HttpServletRequest; 019 020 import org.kuali.rice.kew.api.preferences.Preferences; 021 import org.kuali.rice.kns.web.struts.form.KualiForm; 022 import org.kuali.rice.krad.exception.ValidationException; 023 import org.kuali.rice.krad.util.GlobalVariables; 024 import org.kuali.rice.krad.util.KRADConstants; 025 026 027 /** 028 * Struts ActionForm for {@link PreferencesAction}. 029 * 030 * @see PreferencesAction 031 * 032 * @author Kuali Rice Team (rice.collab@kuali.org) 033 */ 034 public class PreferencesForm extends KualiForm { 035 036 private static final long serialVersionUID = 4536869031291955777L; 037 private static final String ERR_KEY_REFRESH_RATE_WHOLE_NUM = "preferences.refreshRate"; 038 private static final String ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM = "preferences.pageSize"; 039 private Preferences.Builder preferences; 040 private String methodToCall = ""; 041 private String returnMapping; 042 private boolean showOutbox = true; 043 private String documentTypePreferenceName; 044 private String documentTypePreferenceValue; 045 046 // KULRICE-3137: Added a backLocation parameter similar to the one from lookups. 047 private String backLocation; 048 049 public String getReturnMapping() { 050 return returnMapping; 051 } 052 public void setReturnMapping(String returnMapping) { 053 this.returnMapping = returnMapping; 054 } 055 public PreferencesForm() { 056 preferences = Preferences.Builder.create(); 057 } 058 public String getMethodToCall() { 059 return methodToCall; 060 } 061 public void setMethodToCall(String methodToCall) { 062 this.methodToCall = methodToCall; 063 } 064 public Preferences.Builder getPreferences() { 065 return preferences; 066 } 067 public void setPreferences(Preferences.Builder preferences) { 068 this.preferences = preferences; 069 } 070 public boolean isShowOutbox() { 071 return this.showOutbox; 072 } 073 public void setShowOutbox(boolean showOutbox) { 074 this.showOutbox = showOutbox; 075 } 076 077 public String getBackLocation() { 078 return this.backLocation; 079 } 080 public void setBackLocation(String backLocation) { 081 this.backLocation = backLocation; 082 } 083 084 public String getDocumentTypePreferenceName() { 085 return documentTypePreferenceName; 086 } 087 088 public void setDocumentTypePreferenceName(String documentTypePreferenceName) { 089 this.documentTypePreferenceName = documentTypePreferenceName; 090 } 091 092 public String getDocumentTypePreferenceValue() { 093 return documentTypePreferenceValue; 094 } 095 096 public void setDocumentTypePreferenceValue(String documentTypePreferenceValue) { 097 this.documentTypePreferenceValue = documentTypePreferenceValue; 098 } 099 100 public Object getDocumentTypeNotificationPreference(String documentType) { 101 return preferences.getDocumentTypeNotificationPreference(documentType); 102 } 103 104 public void setDocumentTypeNotificationPreference(String documentType, String preferenceValue) { 105 preferences.addDocumentTypeNotificationPreference(documentType, preferenceValue); 106 } 107 108 /** 109 * Retrieves the "returnLocation" parameter after calling "populate" on the superclass. 110 * 111 * @see org.kuali.rice.krad.web.struts.form.KualiForm#populate(javax.servlet.http.HttpServletRequest) 112 */ 113 @Override 114 public void populate(HttpServletRequest request) { 115 super.populate(request); 116 117 if (getParameter(request, KRADConstants.RETURN_LOCATION_PARAMETER) != null) { 118 setBackLocation(getParameter(request, KRADConstants.RETURN_LOCATION_PARAMETER)); 119 } 120 } 121 122 public void validatePreferences() { 123 124 try { 125 new Integer(preferences.getRefreshRate().trim()); 126 } catch (NumberFormatException e) { 127 GlobalVariables.getMessageMap().putError(ERR_KEY_REFRESH_RATE_WHOLE_NUM, "general.message", "ActionList Refresh Rate must be in whole minutes"); 128 } catch (NullPointerException e1) { 129 GlobalVariables.getMessageMap().putError(ERR_KEY_REFRESH_RATE_WHOLE_NUM, "general.message", "ActionList Refresh Rate must be in whole minutes"); 130 } 131 132 try { 133 if(new Integer(preferences.getPageSize().trim()) == 0){ 134 GlobalVariables.getMessageMap().putError(ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM, "general.message", "ActionList Page Size must be non-zero "); 135 } 136 } catch (NumberFormatException e) { 137 GlobalVariables.getMessageMap().putError(ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM, "general.message", "ActionList Page Size must be in whole minutes"); 138 } catch (NullPointerException e1) { 139 GlobalVariables.getMessageMap().putError(ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM, "general.message", "ActionList Page Size must be in whole minutes"); 140 } 141 142 if (GlobalVariables.getMessageMap().hasErrors()) { 143 throw new ValidationException("errors in preferences"); 144 } 145 } 146 }