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 30, 2004
018: *
019: */
020: package org.kuali.module.pdp.action.format;
021:
022: import java.math.BigDecimal;
023: import java.util.ArrayList;
024: import java.util.Date;
025: import java.util.Iterator;
026: import java.util.List;
027:
028: import javax.servlet.http.HttpServletRequest;
029: import javax.servlet.http.HttpServletResponse;
030: import javax.servlet.http.HttpSession;
031:
032: import org.apache.struts.action.ActionForm;
033: import org.apache.struts.action.ActionForward;
034: import org.apache.struts.action.ActionMapping;
035: import org.kuali.kfs.context.SpringContext;
036: import org.kuali.module.pdp.action.BaseAction;
037: import org.kuali.module.pdp.form.format.FormatProcessForm;
038: import org.kuali.module.pdp.form.format.FormatSelectionForm;
039: import org.kuali.module.pdp.service.FormatResult;
040: import org.kuali.module.pdp.service.FormatService;
041: import org.kuali.module.pdp.service.SecurityRecord;
042: import org.kuali.module.pdp.utilities.DateHandler;
043:
044: /**
045: * @author jsissom
046: */
047: public class FormatPrepareAction extends BaseAction {
048: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
049: .getLogger(FormatPrepareAction.class);
050:
051: private FormatService formatService;
052:
053: public FormatPrepareAction() {
054: super ();
055: setFormatService(SpringContext.getBean(FormatService.class));
056: }
057:
058: public void setFormatService(FormatService fs) {
059: formatService = fs;
060: }
061:
062: protected boolean isAuthorized(ActionMapping mapping,
063: ActionForm form, HttpServletRequest request,
064: HttpServletResponse response) {
065: SecurityRecord sr = getSecurityRecord(request);
066: return sr.isProcessRole();
067: }
068:
069: protected ActionForward executeLogic(ActionMapping mapping,
070: ActionForm form, HttpServletRequest request,
071: HttpServletResponse response) throws Exception {
072: LOG.debug("executeLogic() started");
073:
074: HttpSession session = request.getSession();
075:
076: if ("btnClear".equals(whichButtonWasPressed(request))) {
077: LOG
078: .debug("executeLogic() Clear fields and return to selection");
079: session.removeAttribute("customers");
080: session.removeAttribute("ranges");
081: session.removeAttribute("FormatSelectionForm");
082: return mapping.findForward("restart");
083: }
084:
085: String campus = (String) session.getAttribute("campus");
086: if (campus == null) {
087: return mapping.findForward("selection");
088: }
089:
090: FormatSelectionForm fsf = (FormatSelectionForm) form;
091:
092: List customers = (List) session.getAttribute("customers");
093: session.removeAttribute("customers");
094:
095: // Figure out which ones they have selected
096: List selectedCustomers = new ArrayList();
097: // TODO Session Check in Format?
098: for (int i = 0; i < customers.size(); i++) {
099: if ("on".equals(fsf.getCustomerProfileId(i))) {
100: selectedCustomers.add(customers.get(i));
101: }
102: }
103:
104: Date paymentDate = DateHandler.makeStringDate(fsf
105: .getPaymentDate());
106:
107: // Get rid of un-needed session stuff
108: session.removeAttribute("customers");
109: session.removeAttribute("ranges");
110: session.removeAttribute("FormatSelectionForm");
111:
112: List results = formatService.startFormatProcess(
113: getUser(request), campus, selectedCustomers,
114: paymentDate, "Y".equals(fsf.getImmediate()), fsf
115: .getPaymentTypes());
116: if (results.size() == 0) {
117: return mapping.findForward("no_payments");
118: }
119:
120: // Get the first one to get the process ID out of it
121: FormatResult fr = (FormatResult) results.get(0);
122:
123: FormatProcessForm fpf = new FormatProcessForm();
124: fpf.setProcId(fr.getProcId());
125: fpf.setCampusCd(campus);
126: request.setAttribute("PdpFormatProcessForm", fpf);
127:
128: int count = 0;
129: BigDecimal amount = new BigDecimal(0);
130:
131: for (Iterator iter = results.iterator(); iter.hasNext();) {
132: FormatResult element = (FormatResult) iter.next();
133:
134: count += element.getPayments();
135: amount = amount.add(element.getAmount());
136: }
137: FormatResult total = new FormatResult();
138: total.setAmount(amount);
139: total.setPayments(count);
140:
141: request.setAttribute("results", results);
142: request.setAttribute("total", total);
143:
144: return mapping.findForward("continue");
145: }
146: }
|