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 Sep 3, 2004
018: *
019: */
020: package org.kuali.module.pdp.action.bank;
021:
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpServletResponse;
024:
025: import org.apache.struts.action.ActionErrors;
026: import org.apache.struts.action.ActionForm;
027: import org.apache.struts.action.ActionForward;
028: import org.apache.struts.action.ActionMapping;
029: import org.kuali.kfs.context.SpringContext;
030: import org.kuali.module.pdp.action.BaseAction;
031: import org.kuali.module.pdp.bo.Bank;
032: import org.kuali.module.pdp.bo.DisbursementType;
033: import org.kuali.module.pdp.form.bank.BankForm;
034: import org.kuali.module.pdp.service.BankService;
035: import org.kuali.module.pdp.service.ReferenceService;
036: import org.kuali.module.pdp.service.SecurityRecord;
037:
038: public class BankSaveAction extends BaseAction {
039: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
040: .getLogger(BankSaveAction.class);
041:
042: private BankService bankService;
043: private ReferenceService referenceService;
044:
045: public BankSaveAction() {
046: super ();
047: setBankService(SpringContext.getBean(BankService.class));
048: setReferenceService(SpringContext
049: .getBean(ReferenceService.class));
050: }
051:
052: protected boolean isAuthorized(ActionMapping mapping,
053: ActionForm form, HttpServletRequest request,
054: HttpServletResponse response) {
055: SecurityRecord sr = getSecurityRecord(request);
056: return sr.isSysAdminRole();
057: }
058:
059: protected ActionForward executeLogic(ActionMapping mapping,
060: ActionForm form, HttpServletRequest request,
061: HttpServletResponse response) throws Exception {
062: LOG.debug("executeLogic() started");
063:
064: String btnPressed = whichButtonWasPressed(request);
065:
066: if ("btnCancel".equals(btnPressed)) {
067: LOG.debug("executeLogic() Cancelled, returning to list");
068: } else if ("btnSave".equals(btnPressed)) {
069: LOG.debug("executeLogic() Saving");
070:
071: BankForm bankForm = (BankForm) form;
072:
073: ActionErrors errors = bankForm.validate(mapping, request);
074: if (errors.size() > 0) {
075: saveErrors(request, errors);
076: return mapping.getInputForward();
077: }
078:
079: Bank bank = new Bank();
080:
081: bank.setAccountNumber(bankForm.getAccountNumber());
082: bank.setActive(bankForm.getActive());
083: bank.setDescription(bankForm.getDescription());
084: bank
085: .setDisbursementType((DisbursementType) referenceService
086: .getCode("DisbursementType", bankForm
087: .getDisbursementTypeCode()));
088: if ((bankForm.getId() == null)
089: || (bankForm.getId().intValue() == 0)) {
090: bank.setId(null);
091: } else {
092: bank.setId(bankForm.getId());
093: }
094: bank.setName(bankForm.getName());
095: bank.setRoutingNumber(bankForm.getRoutingNumber());
096: bank.setVersion(bankForm.getVersion());
097: bank.setLastUpdateUser(getUser(request));
098:
099: bankService.save(bank);
100: }
101: return mapping.findForward("list");
102: }
103:
104: public void setBankService(BankService b) {
105: bankService = b;
106: }
107:
108: public void setReferenceService(ReferenceService r) {
109: referenceService = r;
110: }
111: }
|