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 2, 2004
018: *
019: */
020: package org.kuali.module.pdp.action;
021:
022: import java.sql.Timestamp;
023: import java.util.Enumeration;
024: import java.util.List;
025:
026: import javax.servlet.http.HttpServletRequest;
027: import javax.servlet.http.HttpServletResponse;
028: import javax.servlet.http.HttpSession;
029:
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.kfs.service.ParameterService;
035: import org.kuali.kfs.service.impl.ParameterConstants;
036: import org.kuali.module.pdp.bo.PaymentDetailSearch;
037: import org.kuali.module.pdp.form.paymentsearch.PaymentDetailSearchForm;
038: import org.kuali.module.pdp.service.PaymentDetailSearchService;
039: import org.kuali.module.pdp.service.SecurityRecord;
040: import org.kuali.module.pdp.utilities.GeneralUtilities;
041:
042: /**
043: * @author delyea
044: */
045: public class SessionTestAction extends BaseAction {
046: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
047: .getLogger(SessionTestAction.class);
048:
049: private PaymentDetailSearchService paymentDetailSearchService;
050:
051: protected boolean isAuthorized(ActionMapping mapping,
052: ActionForm form, HttpServletRequest request,
053: HttpServletResponse response) {
054: SecurityRecord sr = getSecurityRecord(request);
055: return true;
056: }
057:
058: private int getSearchResultsPerPage() {
059: return GeneralUtilities.getParameterInteger(SpringContext
060: .getBean(ParameterService.class),
061: ParameterConstants.PRE_DISBURSEMENT_LOOKUP.class,
062: "SEARCH_RESULTS_PER_PAGE");
063: }
064:
065: protected ActionForward executeLogic(ActionMapping mapping,
066: ActionForm form, HttpServletRequest request,
067: HttpServletResponse response) throws Exception {
068: LOG.info("executeLogic() starting");
069: String forward = "test";
070: String searchStatus = (String) request
071: .getParameter("searchStatus");
072: HttpSession session = request.getSession();
073: HttpSession session2 = request.getSession(false);
074: StringBuffer displayString = new StringBuffer();
075:
076: displayString.append("<br><br><br>");
077: displayString.append("COMING INTO ACTION...");
078: displayString.append("<br><br><br>");
079: displayString
080: .append("Variable 'session' has attribute names:<br>");
081: String str = "SESSION ID = " + session.getId()
082: + " and created "
083: + (new Timestamp(session.getCreationTime())).toString();
084: displayString.append(str + "<br>");
085: Enumeration enumer = session.getAttributeNames();
086: while (enumer.hasMoreElements()) {
087: String paramName = (String) enumer.nextElement();
088: displayString.append(paramName + "<br>");
089: }
090: displayString.append("<br><br><br>");
091: displayString
092: .append("Variable 'session2' has attribute names:<br>");
093: str = "SESSION ID = "
094: + session2.getId()
095: + " and created "
096: + (new Timestamp(session2.getCreationTime()))
097: .toString();
098: displayString.append(str + "<br>");
099: Enumeration enumer2 = session2.getAttributeNames();
100: while (enumer2.hasMoreElements()) {
101: String paramName = (String) enumer2.nextElement();
102: displayString.append(paramName + "<br>");
103: }
104: displayString.append("<br><br><br>");
105:
106: LOG.debug("executeLogic() " + str);
107: Object perPage = session.getAttribute("perPage");
108: if (perPage != null) {
109: str = " Variable 'perPage' = " + perPage;
110: } else {
111: Integer variable = getSearchResultsPerPage();
112: str = " Variable 'perPage' is null setting as = "
113: + variable;
114: session.setAttribute("perPage", variable);
115: }
116: displayString.append(str + "<br><br>");
117:
118: if (searchStatus == null) {
119: searchStatus = "HELD";
120: }
121: displayString.append("Using search status '" + searchStatus
122: + "'<br><br>");
123:
124: String buttonPressed = GeneralUtilities
125: .whichButtonWasPressed(request);
126: PaymentDetailSearchForm pdsf = (PaymentDetailSearchForm) form;
127: LOG.debug("executeLogic() pdsf is " + pdsf);
128: LOG.debug("executeLogic() buttonPressed is " + buttonPressed);
129: if (buttonPressed.startsWith("btnSubmit")) {
130: // Code for Searching for Individual Payments
131: PaymentDetailSearch pds = new PaymentDetailSearch();
132: pds.setPaymentStatusCode(searchStatus);
133: List searchResults = paymentDetailSearchService
134: .getAllPaymentsForSearchCriteria(pds);
135:
136: session.removeAttribute("indivSearchResults");
137: displayString
138: .append("removing attribute 'indivSearchResults' in 'session' variable<br>");
139: if (searchResults != null) {
140: displayString.append("Search returned having found "
141: + searchResults.size() + " results<br><br>");
142: session.setAttribute("indivSearchResults",
143: searchResults);
144: displayString
145: .append("set up attribute 'indivSearchResults' in 'session' variable<br>");
146: } else {
147: displayString
148: .append("Search returned having found NO results<br><br>");
149: }
150: pdsf.setPaymentStatusCode(searchStatus);
151: session
152: .setAttribute("PaymentDetailSearchFormSession",
153: pdsf);
154: displayString
155: .append("set up attribute 'PaymentDetailSearchFormSession' in 'session' variable<br>");
156: }
157: request.setAttribute("PaymentDetailSearchForm", pdsf);
158: displayString.append("<br><br><br>");
159: displayString.append("BEFORE USING FORWARD...");
160: displayString.append("<br><br><br>");
161: displayString
162: .append("Variable 'session' has attribute names:<br>");
163: str = "SESSION ID = " + session.getId() + " and created "
164: + (new Timestamp(session.getCreationTime())).toString();
165: displayString.append(str + "<br>");
166: Enumeration enumer3 = session.getAttributeNames();
167: while (enumer3.hasMoreElements()) {
168: String paramName = (String) enumer3.nextElement();
169: displayString.append(paramName + "<br>");
170: }
171: displayString.append("<br><br><br>");
172: displayString
173: .append("Variable 'session2' has attribute names:<br>");
174: str = "SESSION ID = "
175: + session2.getId()
176: + " and created "
177: + (new Timestamp(session2.getCreationTime()))
178: .toString();
179: displayString.append(str + "<br>");
180: Enumeration enumer4 = session2.getAttributeNames();
181: while (enumer4.hasMoreElements()) {
182: String paramName = (String) enumer4.nextElement();
183: displayString.append(paramName + "<br>");
184: }
185: displayString.append("<br><br><br>");
186: request.setAttribute("logMessages", displayString.toString());
187: return mapping.findForward(forward);
188: }
189:
190: public void setPaymentDetailSearchService(
191: PaymentDetailSearchService p) {
192: paymentDetailSearchService = p;
193: }
194: }
|