001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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: /*
017: * Created on Aug 2, 2004
018: *
019: */
020: package org.kuali.module.pdp.form.paymentsearch;
021:
022: import java.util.List;
023:
024: import javax.servlet.http.HttpServletRequest;
025:
026: import org.apache.struts.action.ActionErrors;
027: import org.apache.struts.action.ActionForm;
028: import org.apache.struts.action.ActionMapping;
029: import org.apache.struts.action.ActionMessage;
030: import org.kuali.module.pdp.bo.BatchSearch;
031: import org.kuali.module.pdp.utilities.DateHandler;
032: import org.kuali.module.pdp.utilities.GeneralUtilities;
033:
034: /**
035: * @author delyea
036: */
037: public class BatchSearchForm extends ActionForm {
038: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
039: .getLogger(BatchSearchForm.class);
040:
041: private List indivSearchResults;
042: private String paymentSearchType;
043: private List batchSearchResults;
044:
045: private String batchId; // Integer
046: private String paymentCount; // Integer
047: private String paymentTotalAmount; // BigDecimal
048: private String beginDate; // Date
049: private String endDate; // Date
050: private String chartCode;
051: private String orgCode;
052: private String subUnitCode;
053:
054: /**
055: * @param advancedSearch
056: */
057: public BatchSearchForm() {
058: this .paymentSearchType = "B";
059: }
060:
061: public BatchSearch getBatchSearch() {
062: BatchSearch pds = new BatchSearch();
063:
064: pds.setBatchId(GeneralUtilities.convertStringToInteger(this
065: .getBatchId()));
066: pds.setChartCode(this .getChartCode());
067: pds.setOrgCode(this .getOrgCode());
068: pds.setSubUnitCode(this .getSubUnitCode());
069: pds.setPaymentCount(GeneralUtilities
070: .convertStringToInteger(this .getPaymentCount()));
071: pds
072: .setPaymentTotalAmount(GeneralUtilities
073: .convertStringToBigDecimal(this
074: .getPaymentTotalAmount()));
075: pds.setBeginDate(GeneralUtilities.convertStringToDate(this
076: .getBeginDate()));
077: pds.setEndDate(GeneralUtilities.convertStringToDate(this
078: .getEndDate()));
079:
080: // BOTH
081: pds.setChartCode(this .getChartCode());
082: pds.setOrgCode(this .getOrgCode());
083: pds.setSubUnitCode(this .getSubUnitCode());
084:
085: return pds;
086: }
087:
088: public void clearForm() {
089: this .indivSearchResults = null;
090:
091: this .setBatchId("");
092: this .setChartCode("");
093: this .setOrgCode("");
094: this .setSubUnitCode("");
095: this .setPaymentCount("");
096: this .setPaymentTotalAmount("");
097: this .setBeginDate("");
098: this .setEndDate("");
099: this .batchSearchResults = null;
100: }
101:
102: public ActionErrors validate(ActionMapping mapping,
103: HttpServletRequest request) {
104: LOG.debug("Entered validate().");
105: // create instance of ActionErrors to send errors to user
106: ActionErrors actionErrors = new ActionErrors();
107: String buttonPressed = GeneralUtilities
108: .whichButtonWasPressed(request);
109:
110: if (buttonPressed.startsWith("btnSearch")) {
111: if ((GeneralUtilities.isStringEmpty(this .batchId))
112: && (GeneralUtilities.isStringEmpty(this .chartCode))
113: && (GeneralUtilities.isStringEmpty(this .orgCode))
114: && (GeneralUtilities
115: .isStringEmpty(this .subUnitCode))
116: && (GeneralUtilities
117: .isStringEmpty(this .paymentCount))
118: && (GeneralUtilities
119: .isStringEmpty(this .paymentTotalAmount))
120: && (GeneralUtilities.isStringEmpty(this .beginDate))
121: && (GeneralUtilities.isStringEmpty(this .endDate))) {
122: actionErrors.add("errors", new ActionMessage(
123: "batchSearchForm.batchcriteria.noneEntered"));
124: } else {
125: if (!(GeneralUtilities.isStringEmpty(this .chartCode))) {
126: this .chartCode = this .chartCode.toUpperCase();
127: }
128: if (!(GeneralUtilities.isStringEmpty(this .orgCode))) {
129: this .orgCode = this .orgCode.toUpperCase();
130: }
131: if (!(GeneralUtilities.isStringEmpty(this .subUnitCode))) {
132: this .subUnitCode = this .subUnitCode.toUpperCase();
133: }
134: if ((!(GeneralUtilities.isStringEmpty(this .batchId)))
135: && (!(GeneralUtilities
136: .isStringAllNumbers(this .batchId)))) {
137: actionErrors.add("errors", new ActionMessage(
138: "batchSearchForm.batchId.invalid"));
139: }
140: if ((!(GeneralUtilities
141: .isStringEmpty(this .paymentCount)))
142: && (!(GeneralUtilities
143: .isStringAllNumbers(this .paymentCount)))) {
144: actionErrors.add("errors", new ActionMessage(
145: "batchSearchForm.paymentCount.invalid"));
146: }
147: if ((!(GeneralUtilities
148: .isStringEmpty(this .paymentTotalAmount)))
149: && (!(GeneralUtilities
150: .isStringAllNumbersOrASingleCharacter(
151: this .paymentTotalAmount, '.')))) {
152: actionErrors
153: .add(
154: "errors",
155: new ActionMessage(
156: "batchSearchForm.paymentTotalAmount.invalid"));
157: }
158: if (!(GeneralUtilities.isStringEmpty(this .beginDate))) {
159: actionErrors = DateHandler.validDate(actionErrors,
160: "errors", this .beginDate);
161: }
162: if (!(GeneralUtilities.isStringEmpty(this .endDate))) {
163: actionErrors = DateHandler.validDate(actionErrors,
164: "errors", this .endDate);
165: }
166:
167: // Defining Search Criteria needed for searching batches
168: if ((GeneralUtilities.isStringEmpty(this .batchId))
169: && (GeneralUtilities
170: .isStringEmpty(this .paymentCount))
171: && (GeneralUtilities
172: .isStringEmpty(this .paymentTotalAmount))) {
173: // If batchId, paymentCount, and paymentTotalAmount are empty then at least one date is required
174: if ((GeneralUtilities.isStringEmpty(this .beginDate))
175: && (GeneralUtilities
176: .isStringEmpty(this .endDate))) {
177: actionErrors
178: .add(
179: "errors",
180: new ActionMessage(
181: "batchSearchForm.batchcriteria.noDate"));
182: } else if (((!(GeneralUtilities
183: .isStringEmpty(this .beginDate))) || (!(GeneralUtilities
184: .isStringEmpty(this .endDate))))
185: && ((GeneralUtilities
186: .isStringEmpty(this .beginDate)) || (GeneralUtilities
187: .isStringEmpty(this .endDate)))) {
188: // If we have one (but not both) dates the user must enter either the chartCode, orgCode, or subUnitCode
189: if ((GeneralUtilities
190: .isStringEmpty(this .chartCode))
191: && (GeneralUtilities
192: .isStringEmpty(this .orgCode))
193: && (GeneralUtilities
194: .isStringEmpty(this .subUnitCode))) {
195: actionErrors
196: .add(
197: "errors",
198: new ActionMessage(
199: "batchSearchForm.batchcriteria.sourcemissing"));
200: }
201: }
202: }
203: }
204:
205: // Individual Search Variables in Session
206: request.getSession().removeAttribute("indivSearchResults");
207: request.getSession().removeAttribute(
208: "PaymentDetailSearchFormSession");
209:
210: // Batch Search Variables in Session
211: request.getSession().removeAttribute("batchSearchResults");
212: request.getSession().removeAttribute(
213: "batchIndivSearchResults");
214: request.getSession().removeAttribute("BatchDetail");
215: request.getSession().removeAttribute(
216: "BatchSearchFormSession");
217:
218: }
219:
220: LOG.debug("Exiting validate() There were "
221: + actionErrors.size() + " ActionMessages found.");
222: return actionErrors;
223: }
224:
225: /**
226: * @return Returns the paymentSearchType.
227: */
228: public String getPaymentSearchType() {
229: return paymentSearchType;
230: }
231:
232: /**
233: * @param paymentSearchType The paymentSearchType to set.
234: */
235: public void setPaymentSearchType(String paymentSearchType) {
236: this .paymentSearchType = paymentSearchType;
237: }
238:
239: /**
240: * @return Returns the batchSearchResults.
241: */
242: public List getBatchSearchResults() {
243: return batchSearchResults;
244: }
245:
246: /**
247: * @return Returns the indivSearchResults.
248: */
249: public List getIndivSearchResults() {
250: return indivSearchResults;
251: }
252:
253: /**
254: * @param batchSearchResults The batchSearchResults to set.
255: */
256: public void setBatchSearchResults(List batchSearchResults) {
257: this .batchSearchResults = batchSearchResults;
258: }
259:
260: /**
261: * @param indivSearchResults The indivSearchResults to set.
262: */
263: public void setIndivSearchResults(List indivSearchResults) {
264: this .indivSearchResults = indivSearchResults;
265: }
266:
267: /**
268: * @return Returns the batchId.
269: */
270: public String getBatchId() {
271: return batchId;
272: }
273:
274: /**
275: * @return Returns the chartCode.
276: */
277: public String getChartCode() {
278: return chartCode;
279: }
280:
281: /**
282: * @return Returns the orgCode.
283: */
284: public String getOrgCode() {
285: return orgCode;
286: }
287:
288: /**
289: * @return Returns the paymentCount.
290: */
291: public String getPaymentCount() {
292: return paymentCount;
293: }
294:
295: /**
296: * @return Returns the paymentTotalAmount.
297: */
298: public String getPaymentTotalAmount() {
299: return paymentTotalAmount;
300: }
301:
302: /**
303: * @return Returns the subUnitCode.
304: */
305: public String getSubUnitCode() {
306: return subUnitCode;
307: }
308:
309: /**
310: * @param batchId The batchId to set.
311: */
312: public void setBatchId(String batchId) {
313: this .batchId = batchId;
314: }
315:
316: /**
317: * @param chartCode The chartCode to set.
318: */
319: public void setChartCode(String chartCode) {
320: this .chartCode = chartCode;
321: }
322:
323: /**
324: * @param orgCode The orgCode to set.
325: */
326: public void setOrgCode(String orgCode) {
327: this .orgCode = orgCode;
328: }
329:
330: /**
331: * @param paymentCount The paymentCount to set.
332: */
333: public void setPaymentCount(String paymentCount) {
334: this .paymentCount = paymentCount;
335: }
336:
337: /**
338: * @param paymentTotalAmount The paymentTotalAmount to set.
339: */
340: public void setPaymentTotalAmount(String paymentTotalAmount) {
341: this .paymentTotalAmount = paymentTotalAmount;
342: }
343:
344: /**
345: * @param subUnitCode The subUnitCode to set.
346: */
347: public void setSubUnitCode(String subUnitCode) {
348: this .subUnitCode = subUnitCode;
349: }
350:
351: /**
352: * @return Returns the beginDate.
353: */
354: public String getBeginDate() {
355: return beginDate;
356: }
357:
358: /**
359: * @return Returns the endDate.
360: */
361: public String getEndDate() {
362: return endDate;
363: }
364:
365: /**
366: * @param beginDate The beginDate to set.
367: */
368: public void setBeginDate(String beginDate) {
369: this .beginDate = beginDate;
370: }
371:
372: /**
373: * @param endDate The endDate to set.
374: */
375: public void setEndDate(String endDate) {
376: this.endDate = endDate;
377: }
378: }
|