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.ActionForm;
026: import org.apache.struts.action.ActionForward;
027: import org.apache.struts.action.ActionMapping;
028: import org.kuali.kfs.context.SpringContext;
029: import org.kuali.module.pdp.action.BaseAction;
030: import org.kuali.module.pdp.bo.Bank;
031: import org.kuali.module.pdp.form.bank.BankForm;
032: import org.kuali.module.pdp.service.BankService;
033: import org.kuali.module.pdp.service.SecurityRecord;
034:
035: /**
036: * @author jsissom
037: */
038: public class BankAction extends BaseAction {
039: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
040: .getLogger(BankAction.class);
041:
042: private BankService bankService;
043:
044: public BankAction() {
045: super ();
046: setBankService(SpringContext.getBean(BankService.class));
047: }
048:
049: public void setBankService(BankService b) {
050: bankService = b;
051: }
052:
053: protected boolean isAuthorized(ActionMapping mapping,
054: ActionForm form, HttpServletRequest request,
055: HttpServletResponse response) {
056: SecurityRecord sr = getSecurityRecord(request);
057: return sr.isSysAdminRole();
058: }
059:
060: protected ActionForward executeLogic(ActionMapping mapping,
061: ActionForm form, HttpServletRequest request,
062: HttpServletResponse response) throws Exception {
063: // Go to the bank list screen if there is no bankId passed, otherwise, go to
064: // the edit screen for a single bank
065:
066: String b = request.getParameter("bankId");
067: if (b != null) {
068: int bankId = -1;
069: try {
070: bankId = Integer.parseInt(b);
071: } catch (NumberFormatException e) {
072: // Bad number - we don't need to do anything here
073: }
074: if (bankId == 0) {
075: LOG.debug("executeLogic() add bank");
076:
077: // Add a new bank
078: BankForm bf = new BankForm();
079: bf.setActive(Boolean.TRUE);
080:
081: request.setAttribute("BankForm", bf);
082:
083: return mapping.findForward("edit");
084: } else if (bankId == -1) {
085: // No bank Id or invalid bank ID, go back to the list
086: return mapping.findForward("list");
087: } else {
088: LOG.debug("executeLogic() edit bank");
089:
090: // Load the bank to edit it
091: Bank bank = bankService.get(bankId);
092: BankForm bf = new BankForm(bank);
093:
094: request.setAttribute("PdpBankForm", bf);
095:
096: return mapping.findForward("edit");
097: }
098: } else {
099: return mapping.findForward("list");
100: }
101: }
102: }
|