001/**
002 * Copyright 2005-2014 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 */
016package org.kuali.rice.ksb.messaging.web;
017
018import org.apache.commons.beanutils.ConversionException;
019import org.apache.commons.beanutils.ConvertUtils;
020import org.apache.commons.beanutils.Converter;
021import org.apache.struts.action.ActionForm;
022import org.kuali.rice.core.api.util.KeyValue;
023import org.kuali.rice.ksb.messaging.PersistedMessageBO;
024import org.kuali.rice.ksb.util.CodeTranslator;
025
026import java.sql.Timestamp;
027import java.util.ArrayList;
028import java.util.Collection;
029import java.util.List;
030
031
032/**
033 * Struts ActionForm for the {@link MessageQueueAction}.
034 *
035 * @author Kuali Rice Team (rice.collab@kuali.org)
036 */
037public class MessageQueueForm extends ActionForm {
038
039    private static final long serialVersionUID = -247925603792980036L;
040    public static final int DEFAULT_MAX_ROWS = 1000;
041    public static final int DEFAULT_PAGE_SIZE = 100;
042
043    private int maxRows = DEFAULT_MAX_ROWS;
044    private int pageSize = DEFAULT_PAGE_SIZE;
045    private Long messageId;
046    private String methodToCall = "";
047    private Collection<PersistedMessageBO> messageQueueRows;
048    private String showEdit;
049    private String command;
050    private PersistedMessageBO messageQueueFromDatabase;
051    private PersistedMessageBO messageQueueFromForm;
052    private String newQueueDate;
053    private String existingQueueDate;
054    private String ipAddress;
055
056    //  filter stuff
057    private String routeQueueIdFilter;
058    private String serviceNameFilter;
059    private String applicationIdFilter;
060    private String queueStatusFilter;
061    private String ipNumberFilter;
062    private String value1Filter;
063    private String value2Filter;
064    private String filterApplied;
065
066    private Integer maxMessageFetcherMessages = Integer.valueOf(50);
067
068    private String myIpAddress;
069    private String myApplicationId;
070    private String messagePersistence;
071    private String messageDelivery;
072    private String messageOff;
073    private List<KeyValue> ipAddresses = new ArrayList<KeyValue>();
074
075    static {
076        ConvertUtils.register(new SqlTimestampConverter(), Timestamp.class);
077    }
078
079    public MessageQueueForm() {
080        messageQueueFromForm = new PersistedMessageBO();
081        maxRows = DEFAULT_MAX_ROWS;
082        pageSize = DEFAULT_PAGE_SIZE;
083    }
084
085    public String getRouteQueueStatusLabel(String statusCode) {
086        return CodeTranslator.getRouteQueueStatusLabel(statusCode);
087    }
088
089    public String getMethodToCall() {
090        return methodToCall;
091    }
092
093    public void setMethodToCall(String methodToCall) {
094        this.methodToCall = methodToCall;
095    }
096
097    public Long getMessageId() {
098        return messageId;
099    }
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}