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 11, 2004
018: *
019: */
020: package org.kuali.module.pdp.action.paymentdetail;
021:
022: import java.sql.Timestamp;
023: import java.util.ArrayList;
024: import java.util.HashMap;
025: import java.util.Iterator;
026: import java.util.List;
027: import java.util.Map;
028:
029: import javax.servlet.http.HttpServletRequest;
030: import javax.servlet.http.HttpServletResponse;
031: import javax.servlet.http.HttpSession;
032:
033: import org.apache.struts.action.ActionForm;
034: import org.apache.struts.action.ActionForward;
035: import org.apache.struts.action.ActionMapping;
036: import org.kuali.kfs.context.SpringContext;
037: import org.kuali.module.pdp.PdpConstants;
038: import org.kuali.module.pdp.action.BaseAction;
039: import org.kuali.module.pdp.bo.PaymentDetail;
040: import org.kuali.module.pdp.bo.PaymentGroup;
041: import org.kuali.module.pdp.service.PaymentDetailService;
042: import org.kuali.module.pdp.service.PaymentGroupService;
043: import org.kuali.module.pdp.service.SecurityRecord;
044: import org.kuali.module.pdp.utilities.GeneralUtilities;
045:
046: /**
047: * @author delyea
048: */
049: public class PaymentDetailAction extends BaseAction {
050: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
051: .getLogger(PaymentDetailAction.class);
052: private PaymentDetailService paymentDetailService;
053: private PaymentGroupService paymentGroupService;
054: private Map payees;
055:
056: public PaymentDetailAction() {
057: setPaymentGroupService(SpringContext
058: .getBean(PaymentGroupService.class));
059: setPaymentDetailService(SpringContext
060: .getBean(PaymentDetailService.class));
061:
062: // TODO This should probably be a table
063: payees = new HashMap();
064: payees.put(PdpConstants.PayeeIdTypeCodes.PAYEE_ID, "Payee ID");
065: payees.put(PdpConstants.PayeeIdTypeCodes.SSN, "SSN");
066: payees.put(PdpConstants.PayeeIdTypeCodes.EMPLOYEE_ID,
067: "Employee ID");
068: payees.put(PdpConstants.PayeeIdTypeCodes.FEIN, "FEIN");
069: payees
070: .put(PdpConstants.PayeeIdTypeCodes.VENDOR_ID,
071: "Vendor ID");
072: payees.put(PdpConstants.PayeeIdTypeCodes.OTHER, "Other");
073: }
074:
075: protected boolean isAuthorized(ActionMapping mapping,
076: ActionForm form, HttpServletRequest request,
077: HttpServletResponse response) {
078: SecurityRecord sr = getSecurityRecord(request);
079: return sr.isLimitedViewRole() || sr.isViewAllRole()
080: || sr.isViewIdRole() || sr.isViewBankRole();
081: }
082:
083: protected ActionForward executeLogic(ActionMapping mapping,
084: ActionForm form, HttpServletRequest request,
085: HttpServletResponse response) throws Exception {
086: LOG.debug("executeLogic() started");
087: HttpSession session = request.getSession();
088: LOG
089: .debug("executeLogic() ************* SESSION ID = "
090: + session.getId()
091: + " and created "
092: + (new Timestamp(session.getCreationTime()))
093: .toString());
094:
095: String buttonPressed = GeneralUtilities
096: .whichButtonWasPressed(request);
097: LOG.debug("executeLogic() btnPressed is " + buttonPressed);
098: Integer detailId;
099: PaymentDetail pd = (PaymentDetail) session
100: .getAttribute("PaymentDetail");
101: List indivList = (List) session
102: .getAttribute("indivSearchResults");
103: List batchIndivList = (List) session
104: .getAttribute("batchIndivSearchResults");
105:
106: if ((indivList == null) && (batchIndivList == null)
107: && (pd == null)) {
108: // Handle Session Expiration
109: LOG
110: .info("executeLogic() Payment Detail and both search results are null");
111: return mapping.findForward("pdp_session_timeout");
112: } else {
113: if (request.getParameter("DetailId") != null) {
114: // Payment Detail ID was passed - find payment Detail with the ID
115: LOG.debug("executeLogic() Detail ID passed in Parms: "
116: + request.getParameter("DetailId"));
117: detailId = new Integer(request.getParameter("DetailId"));
118: pd = paymentDetailService.get(detailId);
119:
120: pd.setLastDisbursementActionDate(this
121: .getDisbursementActionExpirationDate(request));
122: getPayeeDescriptor(session, pd);
123: getDisbursementPaymentList(session, pd);
124: session.setAttribute("size", new Integer(pd
125: .getPaymentGroup().getPaymentDetails().size()));
126: session.setAttribute("PaymentDetail", pd);
127: } else if (pd == null) {
128: // Handle Session Expiration
129: LOG
130: .info("executeLogic() Payment Detail object 'pd' is null");
131: return mapping.findForward("pdp_session_timeout");
132: } else if (buttonPressed.startsWith("btnUpdate")) {
133: // Update Payment Detail in Session after action has been performed
134: // (status might have changed)
135: detailId = pd.getId();
136: pd = paymentDetailService.get(detailId);
137:
138: pd.setLastDisbursementActionDate(this
139: .getDisbursementActionExpirationDate(request));
140: getPayeeDescriptor(session, pd);
141: getDisbursementPaymentList(session, pd);
142: session.setAttribute("size", new Integer(pd
143: .getPaymentGroup().getPaymentDetails().size()));
144: session.setAttribute("PaymentDetail", pd);
145: }
146: // Use of a default tab (Summary Tab)
147: if ((GeneralUtilities.isStringEmpty(buttonPressed))
148: || (buttonPressed.startsWith("btnUpdate"))) {
149: request.setAttribute("btnPressed", "btnSummaryTab");
150: } else {
151: request.setAttribute("btnPressed", buttonPressed);
152: }
153: }
154:
155: return mapping.findForward("display");
156: }
157:
158: private void getPayeeDescriptor(HttpSession session,
159: PaymentDetail pd) {
160: // Get descriptor of Payee ID Type based on Code in DB
161: Iterator i = payees.keySet().iterator();
162: while (i.hasNext()) {
163: String key = (String) i.next();
164: if (pd != null) {
165: if (key.equals(pd.getPaymentGroup().getPayeeIdTypeCd())) {
166: session.setAttribute("payeeIdTypeDesc", payees
167: .get(key));
168: }
169: if (key.equals(pd.getPaymentGroup()
170: .getAlternatePayeeIdTypeCd())) {
171: session.setAttribute("alternatePayeeIdTypeDesc",
172: payees.get(key));
173: }
174: }
175: }
176: }
177:
178: private void getDisbursementPaymentList(HttpSession session,
179: PaymentDetail pd) {
180: List paymentDetailList = new ArrayList();
181: Integer disbNbr = pd.getPaymentGroup().getDisbursementNbr();
182: session.removeAttribute("disbNbrTotalPayments");
183: session.removeAttribute("disbursementDetailsList");
184:
185: if ((disbNbr != null) && (disbNbr != new Integer(0))) {
186: List paymentGroupList = paymentGroupService
187: .getByDisbursementNumber(disbNbr);
188: for (Iterator iter = paymentGroupList.iterator(); iter
189: .hasNext();) {
190: PaymentGroup elem = (PaymentGroup) iter.next();
191: paymentDetailList.addAll(elem.getPaymentDetails());
192: }
193: session.setAttribute("disbNbrTotalPayments", new Integer(
194: paymentDetailList.size()));
195: session.setAttribute("disbursementDetailsList",
196: paymentDetailList);
197: }
198: }
199:
200: public void setPayees(Map m) {
201: payees = m;
202: }
203:
204: public void setPaymentDetailService(PaymentDetailService p) {
205: paymentDetailService = p;
206: }
207:
208: public void setPaymentGroupService(PaymentGroupService p) {
209: paymentGroupService = p;
210: }
211: }
|