001 /* 002 * Copyright 2005-2007 The Kuali Foundation 003 * 004 * 005 * Licensed under the Educational Community License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.opensource.org/licenses/ecl2.php 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.kuali.rice.ksb.messaging.web; 018 019 import org.apache.commons.beanutils.ConversionException; 020 import org.apache.commons.beanutils.ConvertUtils; 021 import org.apache.commons.beanutils.Converter; 022 import org.apache.struts.action.ActionForm; 023 import org.kuali.rice.core.api.util.KeyValue; 024 import org.kuali.rice.ksb.messaging.PersistedMessageBO; 025 import org.kuali.rice.ksb.util.CodeTranslator; 026 027 import java.sql.Timestamp; 028 import java.util.ArrayList; 029 import java.util.Collection; 030 import java.util.List; 031 032 033 /** 034 * Struts ActionForm for the {@link MessageQueueAction}. 035 * 036 * @author Kuali Rice Team (rice.collab@kuali.org) 037 */ 038 public class MessageQueueForm extends ActionForm { 039 040 private static final long serialVersionUID = -247925603792980036L; 041 public static final int DEFAULT_MAX_ROWS = 1000; 042 public static final int DEFAULT_PAGE_SIZE = 100; 043 044 private int maxRows = DEFAULT_MAX_ROWS; 045 private int pageSize = DEFAULT_PAGE_SIZE; 046 private Long messageId; 047 private String methodToCall = ""; 048 private Collection<PersistedMessageBO> messageQueueRows; 049 private String showEdit; 050 private String command; 051 private PersistedMessageBO messageQueueFromDatabase; 052 private PersistedMessageBO messageQueueFromForm; 053 private String newQueueDate; 054 private String existingQueueDate; 055 private String ipAddress; 056 057 // filter stuff 058 private String routeQueueIdFilter; 059 private String serviceNameFilter; 060 private String applicationIdFilter; 061 private String queueStatusFilter; 062 private String ipNumberFilter; 063 private String value1Filter; 064 private String value2Filter; 065 private String filterApplied; 066 067 private Integer maxMessageFetcherMessages = Integer.valueOf(50); 068 069 private String myIpAddress; 070 private String myApplicationId; 071 private String messagePersistence; 072 private String messageDelivery; 073 private String messageOff; 074 private List<KeyValue> ipAddresses = new ArrayList<KeyValue>(); 075 076 static { 077 ConvertUtils.register(new SqlTimestampConverter(), Timestamp.class); 078 } 079 080 public MessageQueueForm() { 081 messageQueueFromForm = new PersistedMessageBO(); 082 maxRows = DEFAULT_MAX_ROWS; 083 pageSize = DEFAULT_PAGE_SIZE; 084 } 085 086 public String getRouteQueueStatusLabel(String statusCode) { 087 return CodeTranslator.getRouteQueueStatusLabel(statusCode); 088 } 089 090 public String getMethodToCall() { 091 return methodToCall; 092 } 093 094 public void setMethodToCall(String methodToCall) { 095 this.methodToCall = methodToCall; 096 } 097 098 public Long getMessageId() { 099 return messageId; 100 } 101 102 public void setMessageId(Long routeQueueId) { 103 this.messageId = routeQueueId; 104 } 105 106 public Collection<PersistedMessageBO> getMessageQueueRows() { 107 return messageQueueRows; 108 } 109 110 public void setMessageQueueRows(Collection<PersistedMessageBO> routeQueueRows) { 111 this.messageQueueRows = routeQueueRows; 112 } 113 114 public int getMessageQueueRowsSize() { 115 if (messageQueueRows == null) { 116 return 0; 117 } 118 return messageQueueRows.size(); 119 } 120 121 public String getCommand() { 122 return command; 123 } 124 125 public void setCommand(String command) { 126 this.command = command; 127 } 128 129 public PersistedMessageBO getMessageQueueFromDatabase() { 130 return messageQueueFromDatabase; 131 } 132 133 public void setMessageQueueFromDatabase(PersistedMessageBO existingRouteQueue) { 134 this.messageQueueFromDatabase = existingRouteQueue; 135 } 136 137 public PersistedMessageBO getMessageQueueFromForm() { 138 return messageQueueFromForm; 139 } 140 141 public void setMessageQueueFromForm(PersistedMessageBO routeQueue) { 142 this.messageQueueFromForm = routeQueue; 143 } 144 145 public String getShowEdit() { 146 return showEdit; 147 } 148 149 public void setShowEdit(String showEdit) { 150 this.showEdit = showEdit; 151 } 152 153 public String getExistingQueueDate() { 154 return existingQueueDate; 155 } 156 157 public void setExistingQueueDate(String existingQueueDate) { 158 this.existingQueueDate = existingQueueDate; 159 } 160 161 public String getNewQueueDate() { 162 return newQueueDate; 163 } 164 165 public void setNewQueueDate(String newQueueDate) { 166 this.newQueueDate = newQueueDate; 167 } 168 169 public int getMaxRows() { 170 return maxRows; 171 } 172 173 public void setMaxRows(int maxRows) { 174 this.maxRows = maxRows; 175 } 176 177 public int getPageSize() { 178 return this.pageSize; 179 } 180 181 public void setPageSize(int pageSize) { 182 this.pageSize = pageSize; 183 } 184 185 /** 186 * @return the ipNumberFilter 187 */ 188 public String getIpNumberFilter() { 189 return ipNumberFilter; 190 } 191 192 /** 193 * @param ipNumberFilter the ipNumberFilter to set 194 */ 195 public void setIpNumberFilter(String ipNumberFilter) { 196 this.ipNumberFilter = ipNumberFilter; 197 } 198 199 /** 200 * @return the applicationIdFilter 201 */ 202 public String getApplicationIdFilter() { 203 return applicationIdFilter; 204 } 205 206 /** 207 * @param applicationIdFilter the applicationIdFilter to set 208 */ 209 public void setApplicationIdFilter(String applicationIdFilter) { 210 this.applicationIdFilter = applicationIdFilter; 211 } 212 213 /** 214 * @return the queueStatusFilter 215 */ 216 public String getQueueStatusFilter() { 217 return queueStatusFilter; 218 } 219 220 /** 221 * @param queueStatusFilter the queueStatusFilter to set 222 */ 223 public void setQueueStatusFilter(String queueStatusFilter) { 224 this.queueStatusFilter = queueStatusFilter; 225 } 226 227 /** 228 * @return the serviceNameFilter 229 */ 230 public String getServiceNameFilter() { 231 return serviceNameFilter; 232 } 233 234 /** 235 * @param serviceNameFilter the serviceNameFilter to set 236 */ 237 public void setServiceNameFilter(String serviceNameFilter) { 238 this.serviceNameFilter = serviceNameFilter; 239 } 240 241 /** 242 * @return the filterApplied 243 */ 244 public String getFilterApplied() { 245 return filterApplied; 246 } 247 248 /** 249 * @param filterApplied the filterApplied to set 250 */ 251 public void setFilterApplied(String filterApplied) { 252 this.filterApplied = filterApplied; 253 } 254 255 public String getRouteQueueIdFilter() { 256 return this.routeQueueIdFilter; 257 } 258 259 public void setRouteQueueIdFilter(String messageIdFilter) { 260 this.routeQueueIdFilter = messageIdFilter; 261 } 262 263 public String getValue1Filter() { 264 return this.value1Filter; 265 } 266 267 public void setValue1Filter(String value1Filter) { 268 this.value1Filter = value1Filter; 269 } 270 271 public String getValue2Filter() { 272 return this.value2Filter; 273 } 274 275 public void setValue2Filter(String value2Filter) { 276 this.value2Filter = value2Filter; 277 } 278 279 public List<KeyValue> getIpAddresses() { 280 return this.ipAddresses; 281 } 282 283 public void setIpAddresses(List<KeyValue> ipAddresses) { 284 this.ipAddresses = ipAddresses; 285 } 286 287 public String getIpAddress() { 288 return this.ipAddress; 289 } 290 291 public void setIpAddress(String ipAddress) { 292 this.ipAddress = ipAddress; 293 } 294 295 public Integer getMaxMessageFetcherMessages() { 296 return this.maxMessageFetcherMessages; 297 } 298 299 public void setMaxMessageFetcherMessages(Integer maxMessageFetcherMessages) { 300 this.maxMessageFetcherMessages = maxMessageFetcherMessages; 301 } 302 303 public String getMyIpAddress() { 304 return this.myIpAddress; 305 } 306 307 public void setMyIpAddress(String myIpAddress) { 308 this.myIpAddress = myIpAddress; 309 } 310 311 public String getMyApplicationId() { 312 return this.myApplicationId; 313 } 314 315 public void setMyApplicationId(String myApplicationId) { 316 this.myApplicationId = myApplicationId; 317 } 318 319 public String getMessageDelivery() { 320 return this.messageDelivery; 321 } 322 323 public void setMessageDelivery(String messageDelivery) { 324 this.messageDelivery = messageDelivery; 325 } 326 327 public String getMessageOff() { 328 return this.messageOff; 329 } 330 331 public void setMessageOff(String messageOff) { 332 this.messageOff = messageOff; 333 } 334 335 public String getMessagePersistence() { 336 return this.messagePersistence; 337 } 338 339 public void setMessagePersistence(String messagePersistence) { 340 this.messagePersistence = messagePersistence; 341 } 342 343 /** 344 * Converts an incoming object to a timestamp. 345 * 346 * Adapted from org.apache.commons.beanutils.converters.SqlTimestampConverter 347 */ 348 public static class SqlTimestampConverter implements Converter { 349 350 /** 351 * Create a {@link org.apache.commons.beanutils.Converter} that will throw a {@link org.apache.commons.beanutils.ConversionException} 352 * if a conversion error occurs. 353 */ 354 public SqlTimestampConverter() { 355 this.defaultValue = null; 356 this.useDefault = true; 357 } 358 359 /** 360 * Create a {@link org.apache.commons.beanutils.Converter} that will return the specified default value 361 * if a conversion error occurs. 362 * 363 * @param defaultValue The default value to be returned 364 */ 365 public SqlTimestampConverter(Object defaultValue) { 366 this.defaultValue = defaultValue; 367 this.useDefault = true; 368 } 369 370 // ----------------------------------------------------- Instance Variables 371 372 /** 373 * The default value specified to our Constructor, if any. 374 */ 375 private Object defaultValue = null; 376 377 /** 378 * Should we return the default value on conversion errors? 379 */ 380 private boolean useDefault = true; 381 382 // --------------------------------------------------------- Public Methods 383 384 /** 385 * Convert the specified input object into an output object of the 386 * specified type. 387 * 388 * @param type Data type to which this value should be converted 389 * @param value The input value to be converted 390 * 391 * @exception org.apache.commons.beanutils.ConversionException if conversion cannot be performed 392 * successfully 393 */ 394 public Object convert(Class type, Object value) { 395 if (value == null) { 396 if (useDefault) { 397 return (defaultValue); 398 } else { 399 throw new ConversionException("No value specified"); 400 } 401 } 402 403 if (value instanceof Timestamp) { 404 return (value); 405 } 406 407 try { 408 return (Timestamp.valueOf(value.toString())); 409 } catch (Exception e) { 410 if (useDefault) { 411 return (defaultValue); 412 } else { 413 throw new ConversionException(e); 414 } 415 } 416 } 417 418 } 419 }