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.action.format;
017:
018: import java.util.Collections;
019: import java.util.Iterator;
020: import java.util.List;
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.apache.struts.action.ActionMessage;
030: import org.apache.struts.action.ActionMessages;
031: import org.kuali.kfs.context.SpringContext;
032: import org.kuali.module.pdp.action.BaseAction;
033: import org.kuali.module.pdp.form.format.FormatProcessForm;
034: import org.kuali.module.pdp.service.DisbursementRangeExhaustedException;
035: import org.kuali.module.pdp.service.FormatResult;
036: import org.kuali.module.pdp.service.FormatService;
037: import org.kuali.module.pdp.service.MissingDisbursementRangeException;
038: import org.kuali.module.pdp.service.NoBankForCustomerException;
039: import org.kuali.module.pdp.service.SecurityRecord;
040:
041: public class FormatAction extends BaseAction {
042: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
043: .getLogger(FormatAction.class);
044:
045: private FormatService formatService;
046:
047: public FormatAction() {
048: super ();
049: setFormatService(SpringContext.getBean(FormatService.class));
050: }
051:
052: public void setFormatService(FormatService fs) {
053: formatService = fs;
054: }
055:
056: protected boolean isAuthorized(ActionMapping mapping,
057: ActionForm form, HttpServletRequest request,
058: HttpServletResponse response) {
059: SecurityRecord sr = getSecurityRecord(request);
060: return sr.isProcessRole();
061: }
062:
063: protected ActionForward executeLogic(ActionMapping mapping,
064: ActionForm form, HttpServletRequest request,
065: HttpServletResponse response) throws Exception {
066: LOG.debug("executeLogic() started");
067:
068: FormatProcessForm fpf = (FormatProcessForm) form;
069:
070: if ("btnCancel".equals(whichButtonWasPressed(request))) {
071: // Clear the format
072: formatService.clearUnfinishedFormat(fpf.getProcId());
073: return mapping.findForward("cleared");
074: }
075:
076: try {
077: List results = formatService.performFormat(fpf.getProcId());
078: Collections.sort(results);
079: FormatResult total = new FormatResult();
080: for (Iterator iter = results.iterator(); iter.hasNext();) {
081: FormatResult element = (FormatResult) iter.next();
082: total.setPayments(total.getPayments()
083: + element.getPayments());
084: total.setAmount(total.getAmount().add(
085: element.getAmount()));
086: }
087: request.setAttribute("campusCd", fpf.getCampusCd());
088: request.setAttribute("procId", fpf.getProcId());
089: request.setAttribute("formatResultList", results);
090: request.setAttribute("total", total);
091: request.removeAttribute("FormatProcessForm");
092: request.getSession().removeAttribute("FormatSelectionForm");
093: request.getSession().removeAttribute("campus");
094: return mapping.findForward("finished");
095: } catch (NoBankForCustomerException nbfce) {
096: LOG.error("executeLogic() No Bank For Customer Exception",
097: nbfce);
098: ActionErrors ae = new ActionErrors();
099: ae.add("global", new ActionMessage("format.bank.missing",
100: nbfce.getCustomerProfile()));
101: saveErrors(request, ae);
102: return mapping.findForward("pdp_message");
103: } catch (DisbursementRangeExhaustedException e) {
104: LOG
105: .error(
106: "executeLogic() Disbursement Range Exhausted Exception",
107: e);
108: ActionErrors ae = new ActionErrors();
109: ae
110: .add("global", new ActionMessage(
111: "format.disb.exhausted"));
112: saveErrors(request, ae);
113: return mapping.findForward("pdp_message");
114: } catch (MissingDisbursementRangeException e) {
115: LOG.error(
116: "executeLogic() Missing Disbursment Number Range",
117: e);
118: ActionMessages ae = new ActionMessages();
119: ae.add("global", new ActionMessage("format.disb.missing"));
120: saveErrors(request, ae);
121: return mapping.findForward("pdp_message");
122: }
123: }
124: }
|