001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions
006: * are met:
007: *
008: * - Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: *
011: * - Redistribution in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in
013: * the documentation and/or other materials provided with the
014: * distribution.
015: *
016: * Neither the name of Sun Microsystems, Inc. or the names of
017: * contributors may be used to endorse or promote products derived
018: * from this software without specific prior written permission.
019: *
020: * This software is provided "AS IS," without a warranty of any
021: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
022: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
024: * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
025: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
026: * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
027: * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
028: * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
029: * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
030: * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
031: * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
032: *
033: * You acknowledge that Software is not designed, licensed or intended
034: * for use in the design, construction, operation or maintenance of
035: * any nuclear facility.
036: */
037:
038: package com.sun.portal.oracleportlet.approval;
039:
040: import java.util.Vector;
041: import java.util.Hashtable;
042: import java.io.IOException;
043: import java.io.Writer;
044: import java.util.logging.*;
045:
046: import javax.portlet.*;
047: import javax.servlet.http.HttpServletRequest;
048:
049: import com.sun.portal.oracleportlet.util.*;
050: import com.sun.portal.iwayutil.config.*;
051: import com.sun.portal.iwayutil.sorting.*;
052:
053: /**
054: *
055: * This Portlet is used to retrieve and display data from iProcurement module of
056: * Oracle Applications. This Portlet is used to display data pertaining to requisitions
057: * with pending approval . This portlet uses Oracle JDBC driver to hit appropriate
058: * Oracle base tables and retrieve data
059: *
060: * @version 1.0
061: * @author Zahid Syed
062: * @date 10 June 2005
063: *
064: **/
065:
066: public class ReqApprovalPortlet extends GenericPortlet implements
067: OraclePortletConstants {
068:
069: Logger logger = null;
070: Hashtable responseCache = new Hashtable();
071: Hashtable pageCache = new Hashtable();
072:
073: /**
074: * This method is invoked by the portlet container to initialize the portlet
075: **/
076:
077: public void init(PortletConfig config) throws PortletException {
078: super .init(config);
079: logger = OraclePortletLogger.getLogger();
080:
081: }
082:
083: /**
084: * This method displays the content for online help of the portlet
085: **/
086: public void doHelp(RenderRequest request, RenderResponse response)
087: throws PortletException, IOException {
088:
089: logMessage(Level.INFO, "In doHelp : ");
090: response.setContentType("text/html");
091: PortletSession session = request.getPortletSession(true);
092: PortletContext ctx = session.getPortletContext();
093: PortletRequestDispatcher reqDisp = ctx
094: .getRequestDispatcher(HELP_APPROVAL_JSP);
095: reqDisp.include(request, response);
096: }
097:
098: /**
099: * This method is invoked by the portlet container after a user action
100: **/
101:
102: public void processAction(ActionRequest request,
103: ActionResponse response) throws PortletException,
104: IOException {
105:
106: logMessage(Level.INFO, "In processAction : ");
107: //Obtain the paremeter that forms a part of the query string
108: String queryValue1 = request.getParameter("QueryValue1");
109:
110: //Obtain parameters used for pagination
111: String curSummPage = (String) request
112: .getParameter("CurrentSummaryPage");
113: String curPage = (String) request.getParameter("CurrentPage");
114: String requestType = (String) request
115: .getParameter("RequestType");
116: String queryField = (String) request.getParameter("QueryField");
117: String queryValue = (String) request.getParameter("QueryValue");
118: String tableSize = (String) request.getParameter("TableSize");
119:
120: if (queryValue1 != null) {
121: response.setRenderParameter("QueryValue1", queryValue1);
122: }
123:
124: if (curSummPage != null) {
125: response.setRenderParameter("CurrentSummaryPage",
126: curSummPage.trim());
127: }
128: if (curPage != null) {
129: response.setRenderParameter("CurrentPage", curPage.trim());
130: }
131: if (requestType != null) {
132: response.setRenderParameter("RequestType", requestType
133: .trim());
134: }
135: if (queryField != null) {
136: response
137: .setRenderParameter("QueryField", queryField.trim());
138: }
139: if (queryValue != null) {
140: response
141: .setRenderParameter("QueryValue", queryValue.trim());
142: }
143: if (tableSize != null) {
144: response.setRenderParameter("TableSize", tableSize.trim());
145: }
146:
147: }
148:
149: /**
150: * This method generates the content that is displayed in the portlet
151: **/
152: public void doView(RenderRequest request, RenderResponse response)
153: throws PortletException, IOException {
154:
155: logMessage(Level.INFO, "In doView : ");
156: // Obtain the value of SEGMENT1 (requisition no), using which details are retrieved
157: // Initially, QueryValue1 would be null. This attribute is set in processAction method
158:
159: String queryValue1 = request.getParameter("QueryValue1");
160:
161: //For pagination
162: String queryField = request.getParameter("QueryField");
163: String queryValue = request.getParameter("QueryValue");
164: String requestType = request.getParameter("RequestType");
165: String curSummPage = request.getParameter("CurrentSummaryPage");
166: String curPage = request.getParameter("CurrentPage");
167: String tableSize = request.getParameter("TableSize");
168: //End - For Pagination
169:
170: Vector records = null;
171: PortletSession session = request.getPortletSession(true);
172: PortletContext ctx = session.getPortletContext();
173: String sessionID = session.getId();
174:
175: HttpServletRequest httpReq = (HttpServletRequest) request
176: .getAttribute(HTTPREQ_ATTR_NAME);
177:
178: response.setContentType("text/html");
179:
180: if (requestType != null) {
181: if (queryField.equals("goTo")) {
182: queryValue = PaginationUtils.checkGoToValue(queryValue,
183: tableSize);
184: }
185: request.setAttribute("CurrentPage", queryValue);
186: request.setAttribute("CurrentSummaryPage", queryValue);
187:
188: records = PaginationUtils.getPageCacheData(request,
189: responseCache, "CurrentSummaryPage", sessionID);
190:
191: }
192:
193: // If the doView method was invoked previously, get records from the cache
194: if (queryValue1 != null) {
195:
196: records = (Vector) pageCache.get(sessionID);
197: request.setAttribute("QueryValue1", queryValue1);
198:
199: request.setAttribute("CurrentSummaryPage", curSummPage);
200: request.setAttribute("CurrentPage", curPage);
201: }
202:
203: try {
204: // This condition is met only the first time doView method is invoked
205: if (records == null) {
206: // Obtain the records in the form of a vector by using a utility method
207: records = ApprovalQueryUtils
208: .getPendingApprovalRecords(httpReq);
209: // Check whether we have obtained the records
210: if (records == null) {
211: logMessage(Level.INFO,
212: "In doView: No records obtained from getPendingApprovalRecords");
213: } else {
214: //For Pagination
215: int rowsToShow = PaginationUtils
216: .getNumberOfPaginationRows(records.size());
217: request.setAttribute("CurrentSummaryPage", "1");
218: request.setAttribute("CurrentPage", "1");
219: Vector cacheData = PaginationUtils
220: .splitPageCacheData(records, sessionID,
221: rowsToShow);
222: responseCache.put(sessionID, cacheData);
223: records = PaginationUtils.getPageCacheData(request,
224: responseCache, "CurrentSummaryPage",
225: sessionID);
226: //End - For Pagination
227: }
228: }
229:
230: } catch (Exception ex) {
231:
232: logMessage(Level.SEVERE,
233: "In doView : while obtaining approval records : "
234: + ex);
235: }
236:
237: try {
238:
239: //If we have records to display, set the PaginationRow attribute and dispatch records
240: if (records == null) {
241: // Dispatch the request to a JSP that displays error
242: PortletRequestDispatcher reqDisp = ctx
243: .getRequestDispatcher(NO_RECORDS_JSP);
244: reqDisp.include(request, response);
245:
246: } else {
247: Vector rowData = (Vector) responseCache.get(sessionID);
248: TablePagination.setPaginationRow(request, response,
249: "PaginateSummary", null, rowData.size());
250:
251: // Set the records as an attribute before dispatching to the JSP
252: request.setAttribute("ApprovalHeaders", records);
253: pageCache.put(sessionID, records);
254:
255: // Dispatch the request to a relevant JSP
256: PortletRequestDispatcher reqDisp = ctx
257: .getRequestDispatcher(APPROVAL_HEADERS_JSP);
258: reqDisp.include(request, response);
259: }
260:
261: // If the request is for the details, obtain the details
262: // from the method defined in utility class and append it below the records
263: if (requestType == null) {
264: if (queryValue1 != null) {
265:
266: ApprovalQueryUtils.appendApprovalLines(queryValue1,
267: request, response, session, httpReq);
268: }
269: }
270:
271: } catch (Exception ex) {
272:
273: logMessage(Level.SEVERE,
274: "In doView : while dispatching to the JSP : " + ex);
275: }
276:
277: }
278:
279: /**
280: * This method logs the debug messages
281: **/
282: private void logMessage(Object debugLevel, String msg) {
283:
284: logger.log((Level) debugLevel, msg);
285: }
286: }
|