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: package org.kuali.module.pdp.form.disbursementnumbermaintenance;
017:
018: import java.sql.Timestamp;
019:
020: import javax.servlet.http.HttpServletRequest;
021:
022: import org.apache.struts.action.ActionErrors;
023: import org.apache.struts.action.ActionForm;
024: import org.apache.struts.action.ActionMapping;
025: import org.apache.struts.action.ActionMessage;
026: import org.kuali.module.pdp.bo.DisbursementNumberRange;
027: import org.kuali.module.pdp.bo.PdpUser;
028: import org.kuali.module.pdp.utilities.DateHandler;
029: import org.kuali.module.pdp.utilities.GeneralUtilities;
030:
031: public class DisbursementNumberMaintenanceForm extends ActionForm {
032: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
033: .getLogger(DisbursementNumberMaintenanceForm.class);
034:
035: private Integer id; // DISB_NBR_RANGE_ID
036: private String physCampusProcCode; // PHYS_CMP_PROC_CD
037: private String beginDisbursementNbr; // BEG_DISB_NBR
038: private String lastAssignedDisbNbr; // LST_ASND_DISB_NBR
039: private String endDisbursementNbr; // END_DISB_NBR
040: private String disbNbrEffectiveDt; // DISB_NBR_EFF_DT
041: private String disbNbrExpirationDt; // DISB_NBR_EXPR_DT
042: private Timestamp lastUpdate; // LST_UPDT_TS
043: private PdpUser lastUpdateUser;
044: private String lastUpdateUserId; // LST_UPDT_USR_ID
045: private Integer version; // VER_NBR
046: private Integer bankId;
047:
048: public DisbursementNumberMaintenanceForm() {
049:
050: }
051:
052: public DisbursementNumberMaintenanceForm(DisbursementNumberRange dnr) {
053: setForm(dnr);
054: }
055:
056: public void setForm(DisbursementNumberRange dnr) {
057: this .setBankId(dnr.getBank().getId());
058: this .setBeginDisbursementNbr(GeneralUtilities
059: .convertIntegerToString(dnr.getBeginDisbursementNbr()));
060: this .setDisbNbrEffectiveDt(GeneralUtilities
061: .convertDateToString(dnr.getDisbNbrEffectiveDt()));
062: this .setDisbNbrExpirationDt(GeneralUtilities
063: .convertDateToString(dnr.getDisbNbrExpirationDt()));
064: this .setEndDisbursementNbr(GeneralUtilities
065: .convertIntegerToString(dnr.getEndDisbursementNbr()));
066: this .setId(dnr.getId());
067: this .setLastAssignedDisbNbr(GeneralUtilities
068: .convertIntegerToString(dnr.getLastAssignedDisbNbr()));
069: this .setLastUpdate(dnr.getLastUpdate());
070: this .setLastUpdateUser(dnr.getLastUpdateUser());
071: this .setLastUpdateUserId(dnr.getLastUpdateUserId());
072: this .setPhysCampusProcCode(dnr.getPhysCampusProcCode());
073: this .setVersion(dnr.getVersion());
074: }
075:
076: public DisbursementNumberRange getDisbursementNumberRange() {
077: DisbursementNumberRange dnr = new DisbursementNumberRange();
078: dnr
079: .setBeginDisbursementNbr(GeneralUtilities
080: .convertStringToInteger(this
081: .getBeginDisbursementNbr()));
082: try {
083: dnr.setDisbNbrEffectiveDt(DateHandler
084: .makeStringTimestamp(this .getDisbNbrEffectiveDt()));
085: } catch (Exception e) {
086: // Form Validation Nullifies this
087: }
088: try {
089: dnr
090: .setDisbNbrExpirationDt(DateHandler
091: .makeStringTimestamp(this
092: .getDisbNbrExpirationDt()));
093: } catch (Exception e) {
094: // Form Validation Nullifies this
095: }
096: dnr.setEndDisbursementNbr(GeneralUtilities
097: .convertStringToInteger(this .getEndDisbursementNbr()));
098: dnr.setId(this .getId());
099: dnr.setLastAssignedDisbNbr(GeneralUtilities
100: .convertStringToInteger(this .getLastAssignedDisbNbr()));
101: dnr.setLastUpdate(this .getLastUpdate());
102: dnr.setLastUpdateUser(this .getLastUpdateUser());
103: dnr.setLastUpdateUserId(this .getLastUpdateUserId());
104: dnr.setPhysCampusProcCode(this .getPhysCampusProcCode()
105: .toUpperCase());
106: dnr.setVersion(this .getVersion());
107:
108: return dnr;
109: }
110:
111: public ActionErrors validate(ActionMapping mapping,
112: HttpServletRequest request) {
113: LOG.debug("validate() started");
114:
115: ActionErrors actionErrors = new ActionErrors();
116:
117: String buttonPressed = GeneralUtilities
118: .whichButtonWasPressed(request);
119: if (buttonPressed.startsWith("btnSave")) {
120: // check for bank radio button being selected
121: if (this .getBankId() == null) {
122: actionErrors
123: .add(
124: "errors",
125: new ActionMessage(
126: "DisbursementNumberMaintenanceForm.bankId.missing"));
127: }
128: // Check for validity of the Dates entered
129: if (!GeneralUtilities.isStringEmpty(this
130: .getDisbNbrEffectiveDt())) {
131: actionErrors = DateHandler.validDate(actionErrors,
132: "errors", this .getDisbNbrEffectiveDt());
133: } else {
134: actionErrors
135: .add(
136: "errors",
137: new ActionMessage(
138: "DisbursementNumberMaintenanceForm.disbNbrEffectiveDt.missing"));
139: }
140: if (!GeneralUtilities.isStringEmpty(this
141: .getDisbNbrExpirationDt())) {
142: actionErrors = DateHandler.validDate(actionErrors,
143: "errors", this .getDisbNbrExpirationDt());
144: } else {
145: actionErrors
146: .add(
147: "errors",
148: new ActionMessage(
149: "DisbursementNumberMaintenanceForm.disbNbrExpirationDt.missing"));
150: }
151:
152: // Check that the Disbursement Numbers are Integers
153: int begin = 0;
154: int end = 0;
155: int last = 0;
156:
157: try {
158: beginDisbursementNbr = beginDisbursementNbr.trim();
159: begin = Integer.parseInt(beginDisbursementNbr);
160: if (begin <= 0) {
161: actionErrors
162: .add(
163: "errors",
164: new ActionMessage(
165: "DisbursementNumberMaintenanceForm.beginDisbursementNbr.invalid"));
166: }
167: } catch (NumberFormatException nfe) {
168: actionErrors
169: .add(
170: "errors",
171: new ActionMessage(
172: "DisbursementNumberMaintenanceForm.beginDisbursementNbr.invalid"));
173: }
174: try {
175: endDisbursementNbr = endDisbursementNbr.trim();
176: end = Integer.parseInt(endDisbursementNbr);
177: if (end <= 0) {
178: actionErrors
179: .add(
180: "errors",
181: new ActionMessage(
182: "DisbursementNumberMaintenanceForm.endDisbursementNbr.invalid"));
183: }
184: } catch (NumberFormatException nfe) {
185: actionErrors
186: .add(
187: "errors",
188: new ActionMessage(
189: "DisbursementNumberMaintenanceForm.endDisbursementNbr.invalid"));
190: }
191: lastAssignedDisbNbr = lastAssignedDisbNbr.trim();
192: if (!GeneralUtilities.isStringEmpty(this
193: .getLastAssignedDisbNbr())) {
194: try {
195: last = Integer.parseInt(lastAssignedDisbNbr);
196: if (last <= 0) {
197: actionErrors
198: .add(
199: "errors",
200: new ActionMessage(
201: "DisbursementNumberMaintenanceForm.lastAssignedDisburseNbr.invalid"));
202: }
203: } catch (NumberFormatException nfe) {
204: actionErrors
205: .add(
206: "errors",
207: new ActionMessage(
208: "DisbursementNumberMaintenanceForm.lastAssignedDisburseNbr.invalid"));
209: }
210: } else {
211: last = begin;
212: lastAssignedDisbNbr = beginDisbursementNbr;
213: }
214: if (actionErrors.size() == 0) {
215: if (end < begin) {
216: actionErrors
217: .add(
218: "errors",
219: new ActionMessage(
220: "DisbursementNumberMaintenanceForm.endAssignedDisburseNbr.smaller"));
221: }
222: if ((last < begin) || (last > end)) {
223: actionErrors
224: .add(
225: "errors",
226: new ActionMessage(
227: "DisbursementNumberMaintenanceForm.lastAssignedDisburseNbr.outofrange"));
228: }
229: }
230: if (GeneralUtilities.isStringEmpty(this
231: .getPhysCampusProcCode())) {
232: actionErrors
233: .add(
234: "errors",
235: new ActionMessage(
236: "DisbursementNumberMaintenanceForm.physCampusProcCode.invalid"));
237: }
238: }
239:
240: LOG.debug("validate() There were " + actionErrors.size()
241: + " ActionMessages found.");
242: return actionErrors;
243: }
244:
245: /**
246: * @return
247: */
248: public void clearForm() {
249:
250: this .setBankId(null);
251: this .setBeginDisbursementNbr(null);
252: this .setDisbNbrEffectiveDt(null);
253: this .setDisbNbrExpirationDt(null);
254: this .setEndDisbursementNbr(null);
255: this .setId(null);
256: this .setLastAssignedDisbNbr(null);
257: this .setLastUpdate(null);
258: this .setLastUpdateUser(null);
259: this .setLastUpdateUserId(null);
260: this .setPhysCampusProcCode(null);
261: this .setVersion(null);
262:
263: }
264:
265: /**
266: * @return Returns the bank.
267: */
268: public Integer getBankId() {
269: return bankId;
270: }
271:
272: /**
273: * @return Returns the beginDisbursementNbr.
274: */
275: public String getBeginDisbursementNbr() {
276: return beginDisbursementNbr;
277: }
278:
279: /**
280: * @return Returns the disbNbrEffectiveDt.
281: */
282: public String getDisbNbrEffectiveDt() {
283: return disbNbrEffectiveDt;
284: }
285:
286: /**
287: * @return Returns the disbNbrExpirationDt.
288: */
289: public String getDisbNbrExpirationDt() {
290: return disbNbrExpirationDt;
291: }
292:
293: /**
294: * @return Returns the endDisbursementNbr.
295: */
296: public String getEndDisbursementNbr() {
297: return endDisbursementNbr;
298: }
299:
300: /**
301: * @return Returns the id.
302: */
303: public Integer getId() {
304: return id;
305: }
306:
307: /**
308: * @return Returns the lastAssignedDisbNbr.
309: */
310: public String getLastAssignedDisbNbr() {
311: return lastAssignedDisbNbr;
312: }
313:
314: /**
315: * @return Returns the lastUpdate.
316: */
317: public Timestamp getLastUpdate() {
318: return lastUpdate;
319: }
320:
321: /**
322: * @return Returns the lastUpdateUser.
323: */
324: public PdpUser getLastUpdateUser() {
325: return lastUpdateUser;
326: }
327:
328: /**
329: * @return Returns the lastUpdateUserId.
330: */
331: public String getLastUpdateUserId() {
332: return lastUpdateUserId;
333: }
334:
335: /**
336: * @return Returns the physCampusProcCode.
337: */
338: public String getPhysCampusProcCode() {
339: return physCampusProcCode;
340: }
341:
342: /**
343: * @return Returns the version.
344: */
345: public Integer getVersion() {
346: return version;
347: }
348:
349: /**
350: * @param bank The bank to set.
351: */
352: public void setBankId(Integer bankId) {
353: this .bankId = bankId;
354: }
355:
356: /**
357: * @param beginDisbursementNbr The beginDisbursementNbr to set.
358: */
359: public void setBeginDisbursementNbr(String beginDisbursementNbr) {
360: this .beginDisbursementNbr = beginDisbursementNbr;
361: }
362:
363: /**
364: * @param disbNbrEffectiveDt The disbNbrEffectiveDt to set.
365: */
366: public void setDisbNbrEffectiveDt(String disbNbrEffectiveDt) {
367: this .disbNbrEffectiveDt = disbNbrEffectiveDt;
368: }
369:
370: /**
371: * @param disbNbrExpirationDt The disbNbrExpirationDt to set.
372: */
373: public void setDisbNbrExpirationDt(String disbNbrExpirationDt) {
374: this .disbNbrExpirationDt = disbNbrExpirationDt;
375: }
376:
377: /**
378: * @param endDisbursementNbr The endDisbursementNbr to set.
379: */
380: public void setEndDisbursementNbr(String endDisbursementNbr) {
381: this .endDisbursementNbr = endDisbursementNbr;
382: }
383:
384: /**
385: * @param id The id to set.
386: */
387: public void setId(Integer id) {
388: this .id = id;
389: }
390:
391: /**
392: * @param lastAssignedDisbNbr The lastAssignedDisbNbr to set.
393: */
394: public void setLastAssignedDisbNbr(String lastAssignedDisbNbr) {
395: this .lastAssignedDisbNbr = lastAssignedDisbNbr;
396: }
397:
398: /**
399: * @param lastUpdate The lastUpdate to set.
400: */
401: public void setLastUpdate(Timestamp lastUpdate) {
402: this .lastUpdate = lastUpdate;
403: }
404:
405: /**
406: * @param lastUpdateUser The lastUpdateUser to set.
407: */
408: public void setLastUpdateUser(PdpUser lastUpdateUser) {
409: this .lastUpdateUser = lastUpdateUser;
410: }
411:
412: /**
413: * @param lastUpdateUserId The lastUpdateUserId to set.
414: */
415: public void setLastUpdateUserId(String lastUpdateUserId) {
416: this .lastUpdateUserId = lastUpdateUserId;
417: }
418:
419: /**
420: * @param physCampusProcCode The physCampusProcCode to set.
421: */
422: public void setPhysCampusProcCode(String physCampusProcCode) {
423: this .physCampusProcCode = physCampusProcCode;
424: }
425:
426: /**
427: * @param version The version to set.
428: */
429: public void setVersion(Integer version) {
430: this.version = version;
431: }
432: }
|