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 12, 2004
018: *
019: */
020: package org.kuali.module.pdp.action.format;
021:
022: import java.text.SimpleDateFormat;
023: import java.util.Date;
024: import java.util.Iterator;
025: import java.util.List;
026:
027: import javax.servlet.http.HttpServletRequest;
028: import javax.servlet.http.HttpServletResponse;
029: import javax.servlet.http.HttpSession;
030:
031: import org.apache.struts.action.ActionForm;
032: import org.apache.struts.action.ActionForward;
033: import org.apache.struts.action.ActionMapping;
034: import org.kuali.kfs.context.SpringContext;
035: import org.kuali.kfs.service.ParameterService;
036: import org.kuali.module.pdp.action.BaseAction;
037: import org.kuali.module.pdp.bo.CustomerProfile;
038: import org.kuali.module.pdp.bo.PdpUser;
039: import org.kuali.module.pdp.form.format.FormatSelectionForm;
040: import org.kuali.module.pdp.service.FormatSelection;
041: import org.kuali.module.pdp.service.FormatService;
042: import org.kuali.module.pdp.service.SecurityRecord;
043:
044: /**
045: * @author jsissom
046: */
047: public class FormatSelectionAction extends BaseAction {
048: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
049: .getLogger(FormatSelectionAction.class);
050: private FormatService formatService;
051: private ParameterService parameterService;
052:
053: public FormatSelectionAction() {
054: super ();
055: setFormatService(SpringContext.getBean(FormatService.class));
056: setParameterService(SpringContext
057: .getBean(ParameterService.class));
058: }
059:
060: protected boolean isAuthorized(ActionMapping mapping,
061: ActionForm form, HttpServletRequest request,
062: HttpServletResponse response) {
063: SecurityRecord sr = getSecurityRecord(request);
064: return sr.isProcessRole();
065: }
066:
067: protected ActionForward executeLogic(ActionMapping mapping,
068: ActionForm form, HttpServletRequest request,
069: HttpServletResponse response) throws Exception {
070: LOG.debug("executeLogic() starting");
071:
072: HttpSession session = request.getSession();
073:
074: PdpUser user = getUser(request);
075: FormatSelection fs = formatService.formatSelectionAction(user,
076: request.getParameter("clear") != null);
077:
078: // Get the user's campus
079: session.setAttribute("campus", user.getUniversalUser()
080: .getCampusCode());
081:
082: // Note, customers, ranges and FormatSelectionForm have to be in session so
083: // validate works. If they weren't in session, the page wouldn't have all the
084: // data it needs to display after a validate failure.
085:
086: if (fs.getStartDate() != null) {
087: LOG.debug("executeLogic() Format is already running for "
088: + user.getUniversalUser().getCampusCode());
089:
090: session.removeAttribute("customers");
091: session.removeAttribute("ranges");
092: session.removeAttribute("PdPFormatSelectionForm");
093:
094: // Format is already running, put up message
095: request.setAttribute("formatStart", fs.getStartDate());
096: return mapping.findForward("running");
097: }
098:
099: // Get the data we need
100: List customers = fs.getCustomerList();
101: List ranges = fs.getRangeList();
102:
103: FormatSelectionForm fsf = new FormatSelectionForm();
104: String[] cid = new String[customers.size()];
105: fsf.setCustomerProfileId(cid);
106: fsf.setPaymentTypes("A");
107:
108: int i = 0;
109: for (Iterator iter = customers.iterator(); iter.hasNext();) {
110: CustomerProfile element = (CustomerProfile) iter.next();
111: if (fs.getCampus().equals(
112: element.getDefaultPhysicalCampusProcessingCode())) {
113: cid[i] = "on";
114: }
115: i++;
116: }
117:
118: SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
119: Date today = new Date();
120: fsf.setPaymentDate(sdf.format(today));
121:
122: // Save all the stuff in the session
123: session.setAttribute("customers", customers);
124: session.setAttribute("ranges", ranges);
125:
126: session.setAttribute("PdpFormatSelectionForm", fsf);
127:
128: return mapping.findForward("selection");
129: }
130:
131: public void setFormatService(FormatService fas) {
132: formatService = fas;
133: }
134:
135: public void setParameterService(ParameterService ps) {
136: parameterService = ps;
137: }
138: }
|