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 Jan 14, 2005
018: *
019: */
020: package org.kuali.module.pdp.action.format;
021:
022: import java.util.Collections;
023: import java.util.Iterator;
024: import java.util.List;
025:
026: import javax.servlet.http.HttpServletRequest;
027: import javax.servlet.http.HttpServletResponse;
028:
029: import org.apache.struts.action.ActionErrors;
030: import org.apache.struts.action.ActionForm;
031: import org.apache.struts.action.ActionForward;
032: import org.apache.struts.action.ActionMapping;
033: import org.kuali.kfs.context.SpringContext;
034: import org.kuali.module.pdp.action.BaseAction;
035: import org.kuali.module.pdp.form.format.FormatSummaryForm;
036: import org.kuali.module.pdp.service.FormatResult;
037: import org.kuali.module.pdp.service.FormatService;
038: import org.kuali.module.pdp.service.SecurityRecord;
039: import org.kuali.module.pdp.utilities.GeneralUtilities;
040:
041: /**
042: * @author delyea
043: */
044: public class FormatSummaryAction extends BaseAction {
045: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
046: .getLogger(FormatAction.class);
047:
048: private FormatService formatService;
049:
050: public FormatSummaryAction() {
051: super ();
052: setFormatService(SpringContext.getBean(FormatService.class));
053: }
054:
055: public void setFormatService(FormatService fs) {
056: formatService = fs;
057: }
058:
059: protected boolean isAuthorized(ActionMapping mapping,
060: ActionForm form, HttpServletRequest request,
061: HttpServletResponse response) {
062: SecurityRecord sr = getSecurityRecord(request);
063: return sr.isProcessRole();
064: }
065:
066: protected ActionForward executeLogic(ActionMapping mapping,
067: ActionForm form, HttpServletRequest request,
068: HttpServletResponse response) throws Exception {
069: LOG.debug("executeLogic() started");
070:
071: String id = request.getParameter("id");
072: FormatSummaryForm fsf = (FormatSummaryForm) form;
073:
074: ActionErrors actionErrors = new ActionErrors();
075:
076: if (GeneralUtilities.isStringEmpty(id)) {
077: if (fsf != null) {
078: if (fsf.getProcessId() != null) {
079: actionErrors.add(fsf.validate(mapping, request));
080: if (actionErrors.isEmpty()) {
081: id = fsf.getProcessId().toString();
082: } else {
083: getRecentFormats(request);
084: saveErrors(request, actionErrors);
085: return mapping.findForward("selection");
086: }
087: } else {
088: getRecentFormats(request);
089: return mapping.findForward("selection");
090: }
091: } else {
092: getRecentFormats(request);
093: return mapping.findForward("selection");
094: }
095: } else {
096: if (!(GeneralUtilities.isStringAllNumbers(id))) {
097: return mapping.findForward("pdp_error");
098: }
099: }
100:
101: List results = formatService.getFormatSummary(new Integer(id));
102: Collections.sort(results);
103: FormatResult total = new FormatResult();
104: for (Iterator iter = results.iterator(); iter.hasNext();) {
105: FormatResult element = (FormatResult) iter.next();
106: total.setPayments(total.getPayments()
107: + element.getPayments());
108: total.setAmount(total.getAmount().add(element.getAmount()));
109:
110: }
111: request.setAttribute("procId", id);
112: request.setAttribute("formatResultList", results);
113: request.setAttribute("total", total);
114: return mapping.findForward("finished");
115:
116: }
117:
118: protected void getRecentFormats(HttpServletRequest request) {
119: List recentFormats = formatService.getMostCurrentProcesses();
120: request.setAttribute("recentFormats", recentFormats);
121: }
122: }
|