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 24, 2004
018: */
019: package org.kuali.module.pdp.action.paymentmaintenance;
020:
021: import java.util.List;
022:
023: import javax.servlet.http.HttpServletRequest;
024: import javax.servlet.http.HttpServletResponse;
025: import javax.servlet.http.HttpSession;
026:
027: import org.apache.struts.action.ActionErrors;
028: import org.apache.struts.action.ActionForm;
029: import org.apache.struts.action.ActionForward;
030: import org.apache.struts.action.ActionMapping;
031: import org.apache.struts.action.ActionMessage;
032: import org.kuali.kfs.context.SpringContext;
033: import org.kuali.module.pdp.action.BaseAction;
034: import org.kuali.module.pdp.bo.Batch;
035: import org.kuali.module.pdp.form.paymentmaintenance.PaymentMaintenanceForm;
036: import org.kuali.module.pdp.service.BatchMaintenanceService;
037: import org.kuali.module.pdp.service.SecurityRecord;
038: import org.kuali.module.pdp.utilities.GeneralUtilities;
039:
040: /**
041: * @author delyea
042: */
043: public class BatchMaintenanceAction extends BaseAction {
044: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
045: .getLogger(BatchMaintenanceAction.class);
046: private BatchMaintenanceService batchMaintenanceService;
047:
048: public BatchMaintenanceAction() {
049: setBatchMaintenanceService(SpringContext
050: .getBean(BatchMaintenanceService.class));
051: }
052:
053: public void setBatchMaintenanceService(BatchMaintenanceService p) {
054: this .batchMaintenanceService = p;
055: }
056:
057: protected boolean isAuthorized(ActionMapping mapping,
058: ActionForm form, HttpServletRequest request,
059: HttpServletResponse response) {
060: SecurityRecord sr = getSecurityRecord(request);
061: return sr.isLimitedViewRole() || sr.isViewAllRole()
062: || sr.isViewIdRole() || sr.isViewBankRole();
063: }
064:
065: protected ActionForward executeLogic(ActionMapping mapping,
066: ActionForm form, HttpServletRequest request,
067: HttpServletResponse response) throws Exception {
068: LOG.debug("executeLogic() started");
069:
070: HttpSession session = request.getSession();
071: List batchSearchList = (List) session
072: .getAttribute("batchIndivSearchResults");
073: SecurityRecord sr = (SecurityRecord) session
074: .getAttribute("SecurityRecord");
075: Batch b = (Batch) session.getAttribute("BatchDetail");
076: PaymentMaintenanceForm pmf = (PaymentMaintenanceForm) form;
077: String forward = "update";
078:
079: ActionErrors actionErrors = new ActionErrors();
080: String buttonPressed = GeneralUtilities
081: .whichButtonWasPressed(request);
082:
083: LOG
084: .debug("executeLogic() BatchMaintenanceAction ButtonPressed was "
085: + buttonPressed);
086: if (buttonPressed != null) {
087: if (b == null) {
088: LOG.info("executeLogic() Batch object 'b' is null");
089: return mapping.findForward("pdp_session_timeout");
090:
091: } else if (buttonPressed.startsWith("btnBatch")) {
092: // Action Originated from BatchDetail Screen
093: if (buttonPressed.startsWith("btnBatchHold")) {
094: pmf.setAction("batchHold");
095: if (batchMaintenanceService
096: .doBatchPaymentsHaveOpenStatus(b.getId())) {
097: pmf.setChangeId(b.getId());
098: } else {
099: actionErrors
100: .add(
101: "errors",
102: new ActionMessage(
103: "batchMaintenanceAction.batchStatus.notAllOpen"));
104: }
105: } else if (buttonPressed.startsWith("btnBatchCancel")) {
106: pmf.setAction("batchCancel");
107: if (batchMaintenanceService
108: .doBatchPaymentsHaveOpenOrHeldStatus(b
109: .getId())) {
110: pmf.setChangeId(b.getId());
111: } else {
112: actionErrors
113: .add(
114: "errors",
115: new ActionMessage(
116: "batchMaintenanceAction.batchStatus.notAllOpenOrHeld"));
117: }
118: } else if (buttonPressed
119: .startsWith("btnBatchRemoveHold")) {
120: pmf.setAction("batchRemoveHold");
121: if (batchMaintenanceService
122: .doBatchPaymentsHaveHeldStatus(b.getId())) {
123: pmf.setChangeId(b.getId());
124: } else {
125: actionErrors
126: .add(
127: "errors",
128: new ActionMessage(
129: "batchMaintenanceAction.batchStatus.notAllHeld"));
130: }
131: } else {
132: // Invalid Button was Pressed
133: return mapping.findForward("pdp_system_error");
134: }
135: if (!actionErrors.isEmpty()) {
136: forward = "batch";
137: }
138:
139: } else if (buttonPressed.startsWith("btnUpdate")) {
140: // Action Originated from Update page
141: if (buttonPressed.startsWith("btnUpdateClear")) {
142: pmf.setChangeText(null);
143: return mapping.findForward("update");
144:
145: } else if (buttonPressed.startsWith("btnUpdateSave")) {
146: String action = pmf.getAction();
147: LOG.debug("executeLogic() string 'action' is "
148: + action);
149:
150: // All Actions must be performed on Payment Group that Payment Detail is a member of
151: if (action.equals("batchHold")) {
152: if (sr.isHoldRole()) {
153: LOG
154: .debug("executeLogic() running holdPendingBatch now");
155: // ChangeID was previous set to BatchID
156: batchMaintenanceService.holdPendingBatch(
157: pmf.getChangeId(), pmf
158: .getChangeText(),
159: getUser(request));
160: actionErrors
161: .add(
162: "success",
163: new ActionMessage(
164: "success.paymentUpdate.saved"));
165: } else {
166: actionErrors
167: .add(
168: "error",
169: new ActionMessage(
170: "paymentMaintenanceAction.paymentUpdate.notAuthorized"));
171: }
172: } else if (action.equals("batchRemoveHold")) {
173: if (sr.isHoldRole()) {
174: LOG
175: .debug("executeLogic() running removeBatchHold now");
176: // ChangeID was previous set to BatchID
177: batchMaintenanceService.removeBatchHold(pmf
178: .getChangeId(),
179: pmf.getChangeText(),
180: getUser(request));
181: actionErrors
182: .add(
183: "success",
184: new ActionMessage(
185: "success.paymentUpdate.saved"));
186: } else {
187: actionErrors
188: .add(
189: "error",
190: new ActionMessage(
191: "paymentMaintenanceAction.paymentUpdate.notAuthorized"));
192: }
193: } else if (action.equals("batchCancel")) {
194: if (sr.isCancelRole()) {
195: LOG
196: .debug("executeLogic() running cancelPendingBatch now");
197: // ChangeID was previous set to BatchID
198: batchMaintenanceService.cancelPendingBatch(
199: pmf.getChangeId(), pmf
200: .getChangeText(),
201: getUser(request));
202: actionErrors
203: .add(
204: "success",
205: new ActionMessage(
206: "success.paymentUpdate.saved"));
207: } else {
208: actionErrors
209: .add(
210: "error",
211: new ActionMessage(
212: "paymentMaintenanceAction.paymentUpdate.notAuthorized"));
213: }
214: }
215: }
216: forward = "batch";
217: }
218: }
219:
220: // If we had errors, save them
221: if (!actionErrors.isEmpty()) {
222: saveErrors(request, actionErrors);
223: }
224:
225: request.setAttribute("PaymentMaintenanceForm", pmf);
226: return mapping.findForward(forward);
227: }
228:
229: }
|