View Javadoc

1   /**
2    * Copyright 2005-2013 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.ksb.messaging.web;
17  
18  import org.apache.commons.beanutils.ConversionException;
19  import org.apache.commons.beanutils.ConvertUtils;
20  import org.apache.commons.beanutils.Converter;
21  import org.apache.struts.action.ActionForm;
22  import org.kuali.rice.core.api.util.KeyValue;
23  import org.kuali.rice.ksb.messaging.PersistedMessageBO;
24  import org.kuali.rice.ksb.util.CodeTranslator;
25  
26  import java.sql.Timestamp;
27  import java.util.ArrayList;
28  import java.util.Collection;
29  import java.util.List;
30  
31  
32  /**
33   * Struts ActionForm for the {@link MessageQueueAction}.
34   *
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  public class MessageQueueForm extends ActionForm {
38  
39      private static final long serialVersionUID = -247925603792980036L;
40      public static final int DEFAULT_MAX_ROWS = 1000;
41      public static final int DEFAULT_PAGE_SIZE = 100;
42  
43      private int maxRows = DEFAULT_MAX_ROWS;
44      private int pageSize = DEFAULT_PAGE_SIZE;
45      private Long messageId;
46      private String methodToCall = "";
47      private Collection<PersistedMessageBO> messageQueueRows;
48      private String showEdit;
49      private String command;
50      private PersistedMessageBO messageQueueFromDatabase;
51      private PersistedMessageBO messageQueueFromForm;
52      private String newQueueDate;
53      private String existingQueueDate;
54      private String ipAddress;
55  
56      //  filter stuff
57      private String routeQueueIdFilter;
58      private String serviceNameFilter;
59      private String applicationIdFilter;
60      private String queueStatusFilter;
61      private String ipNumberFilter;
62      private String value1Filter;
63      private String value2Filter;
64      private String filterApplied;
65  
66      private Integer maxMessageFetcherMessages = Integer.valueOf(50);
67  
68      private String myIpAddress;
69      private String myApplicationId;
70      private String messagePersistence;
71      private String messageDelivery;
72      private String messageOff;
73      private List<KeyValue> ipAddresses = new ArrayList<KeyValue>();
74  
75      static {
76          ConvertUtils.register(new SqlTimestampConverter(), Timestamp.class);
77      }
78  
79      public MessageQueueForm() {
80          messageQueueFromForm = new PersistedMessageBO();
81          maxRows = DEFAULT_MAX_ROWS;
82          pageSize = DEFAULT_PAGE_SIZE;
83      }
84  
85      public String getRouteQueueStatusLabel(String statusCode) {
86          return CodeTranslator.getRouteQueueStatusLabel(statusCode);
87      }
88  
89      public String getMethodToCall() {
90          return methodToCall;
91      }
92  
93      public void setMethodToCall(String methodToCall) {
94          this.methodToCall = methodToCall;
95      }
96  
97      public Long getMessageId() {
98          return messageId;
99      }
100 
101     public void setMessageId(Long routeQueueId) {
102         this.messageId = routeQueueId;
103     }
104 
105     public Collection<PersistedMessageBO> getMessageQueueRows() {
106         return messageQueueRows;
107     }
108 
109     public void setMessageQueueRows(Collection<PersistedMessageBO> routeQueueRows) {
110         this.messageQueueRows = routeQueueRows;
111     }
112 
113     public int getMessageQueueRowsSize() {
114         if (messageQueueRows == null) {
115             return 0;
116         }
117         return messageQueueRows.size();
118     }
119 
120     public String getCommand() {
121         return command;
122     }
123 
124     public void setCommand(String command) {
125         this.command = command;
126     }
127 
128     public PersistedMessageBO getMessageQueueFromDatabase() {
129         return messageQueueFromDatabase;
130     }
131 
132     public void setMessageQueueFromDatabase(PersistedMessageBO existingRouteQueue) {
133         this.messageQueueFromDatabase = existingRouteQueue;
134     }
135 
136     public PersistedMessageBO getMessageQueueFromForm() {
137         return messageQueueFromForm;
138     }
139 
140     public void setMessageQueueFromForm(PersistedMessageBO routeQueue) {
141         this.messageQueueFromForm = routeQueue;
142     }
143 
144     public String getShowEdit() {
145         return showEdit;
146     }
147 
148     public void setShowEdit(String showEdit) {
149         this.showEdit = showEdit;
150     }
151 
152     public String getExistingQueueDate() {
153         return existingQueueDate;
154     }
155 
156     public void setExistingQueueDate(String existingQueueDate) {
157         this.existingQueueDate = existingQueueDate;
158     }
159 
160     public String getNewQueueDate() {
161         return newQueueDate;
162     }
163 
164     public void setNewQueueDate(String newQueueDate) {
165         this.newQueueDate = newQueueDate;
166     }
167 
168     public int getMaxRows() {
169         return maxRows;
170     }
171 
172     public void setMaxRows(int maxRows) {
173         this.maxRows = maxRows;
174     }
175 
176     public int getPageSize() {
177         return this.pageSize;
178     }
179 
180     public void setPageSize(int pageSize) {
181         this.pageSize = pageSize;
182     }
183 
184     /**
185      * @return the ipNumberFilter
186      */
187     public String getIpNumberFilter() {
188       return ipNumberFilter;
189     }
190 
191     /**
192      * @param ipNumberFilter the ipNumberFilter to set
193      */
194     public void setIpNumberFilter(String ipNumberFilter) {
195       this.ipNumberFilter = ipNumberFilter;
196     }
197 
198     /**
199      * @return the applicationIdFilter
200      */
201     public String getApplicationIdFilter() {
202       return applicationIdFilter;
203     }
204 
205     /**
206      * @param applicationIdFilter the applicationIdFilter to set
207      */
208     public void setApplicationIdFilter(String applicationIdFilter) {
209       this.applicationIdFilter = applicationIdFilter;
210     }
211 
212     /**
213      * @return the queueStatusFilter
214      */
215     public String getQueueStatusFilter() {
216       return queueStatusFilter;
217     }
218 
219     /**
220      * @param queueStatusFilter the queueStatusFilter to set
221      */
222     public void setQueueStatusFilter(String queueStatusFilter) {
223       this.queueStatusFilter = queueStatusFilter;
224     }
225 
226     /**
227      * @return the serviceNameFilter
228      */
229     public String getServiceNameFilter() {
230       return serviceNameFilter;
231     }
232 
233     /**
234      * @param serviceNameFilter the serviceNameFilter to set
235      */
236     public void setServiceNameFilter(String serviceNameFilter) {
237       this.serviceNameFilter = serviceNameFilter;
238     }
239 
240     /**
241      * @return the filterApplied
242      */
243     public String getFilterApplied() {
244       return filterApplied;
245     }
246 
247     /**
248      * @param filterApplied the filterApplied to set
249      */
250     public void setFilterApplied(String filterApplied) {
251       this.filterApplied = filterApplied;
252     }
253 
254     public String getRouteQueueIdFilter() {
255         return this.routeQueueIdFilter;
256     }
257 
258     public void setRouteQueueIdFilter(String messageIdFilter) {
259         this.routeQueueIdFilter = messageIdFilter;
260     }
261 
262     public String getValue1Filter() {
263         return this.value1Filter;
264     }
265 
266     public void setValue1Filter(String value1Filter) {
267         this.value1Filter = value1Filter;
268     }
269 
270     public String getValue2Filter() {
271         return this.value2Filter;
272     }
273 
274     public void setValue2Filter(String value2Filter) {
275         this.value2Filter = value2Filter;
276     }
277 
278     public List<KeyValue> getIpAddresses() {
279         return this.ipAddresses;
280     }
281 
282     public void setIpAddresses(List<KeyValue> ipAddresses) {
283         this.ipAddresses = ipAddresses;
284     }
285 
286     public String getIpAddress() {
287         return this.ipAddress;
288     }
289 
290     public void setIpAddress(String ipAddress) {
291         this.ipAddress = ipAddress;
292     }
293 
294     public Integer getMaxMessageFetcherMessages() {
295         return this.maxMessageFetcherMessages;
296     }
297 
298     public void setMaxMessageFetcherMessages(Integer maxMessageFetcherMessages) {
299         this.maxMessageFetcherMessages = maxMessageFetcherMessages;
300     }
301 
302     public String getMyIpAddress() {
303         return this.myIpAddress;
304     }
305 
306     public void setMyIpAddress(String myIpAddress) {
307         this.myIpAddress = myIpAddress;
308     }
309 
310     public String getMyApplicationId() {
311         return this.myApplicationId;
312     }
313 
314     public void setMyApplicationId(String myApplicationId) {
315         this.myApplicationId = myApplicationId;
316     }
317 
318     public String getMessageDelivery() {
319         return this.messageDelivery;
320     }
321 
322     public void setMessageDelivery(String messageDelivery) {
323         this.messageDelivery = messageDelivery;
324     }
325 
326     public String getMessageOff() {
327         return this.messageOff;
328     }
329 
330     public void setMessageOff(String messageOff) {
331         this.messageOff = messageOff;
332     }
333 
334     public String getMessagePersistence() {
335         return this.messagePersistence;
336     }
337 
338     public void setMessagePersistence(String messagePersistence) {
339         this.messagePersistence = messagePersistence;
340     }
341 
342     /**
343      * Converts an incoming object to a timestamp.
344      *
345      * Adapted from org.apache.commons.beanutils.converters.SqlTimestampConverter
346      */
347     public static class SqlTimestampConverter implements Converter {
348 
349         /**
350          * Create a {@link org.apache.commons.beanutils.Converter} that will throw a {@link org.apache.commons.beanutils.ConversionException}
351          * if a conversion error occurs.
352          */
353         public SqlTimestampConverter() {
354             this.defaultValue = null;
355             this.useDefault = true;
356         }
357 
358         /**
359          * Create a {@link org.apache.commons.beanutils.Converter} that will return the specified default value
360          * if a conversion error occurs.
361          *
362          * @param defaultValue The default value to be returned
363          */
364         public SqlTimestampConverter(Object defaultValue) {
365             this.defaultValue = defaultValue;
366             this.useDefault = true;
367         }
368 
369         // ----------------------------------------------------- Instance Variables
370 
371         /**
372          * The default value specified to our Constructor, if any.
373          */
374         private Object defaultValue = null;
375 
376         /**
377          * Should we return the default value on conversion errors?
378          */
379         private boolean useDefault = true;
380 
381         // --------------------------------------------------------- Public Methods
382 
383         /**
384          * Convert the specified input object into an output object of the
385          * specified type.
386          *
387          * @param type Data type to which this value should be converted
388          * @param value The input value to be converted
389          *
390          * @exception org.apache.commons.beanutils.ConversionException if conversion cannot be performed
391          *  successfully
392          */
393         public Object convert(Class type, Object value) {
394             if (value == null) {
395                 if (useDefault) {
396                     return (defaultValue);
397                 } else {
398                     throw new ConversionException("No value specified");
399                 }
400             }
401 
402             if (value instanceof Timestamp) {
403                 return (value);
404             }
405 
406             try {
407                 return (Timestamp.valueOf(value.toString()));
408             } catch (Exception e) {
409                 if (useDefault) {
410                     return (defaultValue);
411                 } else {
412                     throw new ConversionException(e);
413                 }
414             }
415         }
416 
417     }
418 }