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.requisitions;
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 the
057: * requisitions made. 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 May 2005
063: *
064: **/
065:
066: public class RequisitionInfoPortlet 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_REQUISITIONS_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:
108: //Obtain the two paremeters those form a part of the query string
109: String queryValue1 = (String) request
110: .getParameter("QueryValue1");
111: String queryValue2 = (String) request
112: .getParameter("QueryValue2");
113:
114: //Obtain parameters used for pagination
115: String curSummPage = (String) request
116: .getParameter("CurrentSummaryPage");
117: String curPage = (String) request.getParameter("CurrentPage");
118: String requestType = (String) request
119: .getParameter("RequestType");
120: String queryField = (String) request.getParameter("QueryField");
121: String queryValue = (String) request.getParameter("QueryValue");
122: String tableSize = (String) request.getParameter("TableSize");
123:
124: if (queryValue1 != null) {
125: response.setRenderParameter("QueryValue1", queryValue1
126: .trim());
127: response.setRenderParameter("QueryValue2", queryValue2
128: .trim());
129: }
130: if (curSummPage != null) {
131: response.setRenderParameter("CurrentSummaryPage",
132: curSummPage.trim());
133: }
134: if (curPage != null) {
135: response.setRenderParameter("CurrentPage", curPage.trim());
136: }
137: if (requestType != null) {
138: response.setRenderParameter("RequestType", requestType
139: .trim());
140: }
141: if (queryField != null) {
142: response
143: .setRenderParameter("QueryField", queryField.trim());
144: }
145: if (queryValue != null) {
146: response
147: .setRenderParameter("QueryValue", queryValue.trim());
148: }
149: if (tableSize != null) {
150: response.setRenderParameter("TableSize", tableSize.trim());
151: }
152: }
153:
154: /**
155: * This method generates the content that is displayed in the portlet
156: **/
157: public void doView(RenderRequest request, RenderResponse response)
158: throws PortletException, IOException {
159:
160: logMessage(Level.INFO, "In doView : ");
161:
162: // Obtain the value of SEGMENT1 (requisition no), using which details are retrieved
163: // Initially, QueryValue1 would be null. This attribute is set in processAction method
164:
165: String queryValue1 = request.getParameter("QueryValue1");
166: String queryValue2 = request.getParameter("QueryValue2");
167:
168: //For pagination
169: String queryField = request.getParameter("QueryField");
170: String queryValue = request.getParameter("QueryValue");
171: String requestType = request.getParameter("RequestType");
172: String curSummPage = request.getParameter("CurrentSummaryPage");
173: String curPage = request.getParameter("CurrentPage");
174: String tableSize = request.getParameter("TableSize");
175: //End - For Pagination
176:
177: Vector records = null;
178: PortletSession session = request.getPortletSession(true);
179: PortletContext ctx = session.getPortletContext();
180: String sessionID = session.getId();
181:
182: HttpServletRequest httpReq = (HttpServletRequest) request
183: .getAttribute(HTTPREQ_ATTR_NAME);
184:
185: response.setContentType("text/html");
186:
187: if (requestType != null) {
188: if (queryField.equals("goTo")) {
189: queryValue = PaginationUtils.checkGoToValue(queryValue,
190: tableSize);
191: }
192: request.setAttribute("CurrentPage", queryValue);
193: request.setAttribute("CurrentSummaryPage", queryValue);
194:
195: records = PaginationUtils.getPageCacheData(request,
196: responseCache, "CurrentSummaryPage", sessionID);
197:
198: }
199:
200: // If the doView method was invoked previously, get records from the cache
201: if (queryValue1 != null) {
202:
203: records = (Vector) pageCache.get(sessionID);
204:
205: request.setAttribute("QueryValue1", queryValue1);
206: request.setAttribute("QueryValue2", queryValue2);
207:
208: request.setAttribute("CurrentSummaryPage", curSummPage);
209: request.setAttribute("CurrentPage", curPage);
210:
211: }
212:
213: try {
214: // This condition is met only the first time doView method is invoked
215: if (records == null) {
216: // Obtain the records in the form of a vector by using a utility method
217: String numberOfRecords = RequisitionQueryUtils
218: .getNumberOfRecordsToDisplay();
219: records = RequisitionQueryUtils
220: .getRequisitionInfoRecords(httpReq,
221: numberOfRecords);
222:
223: // Check whether we have obtained the records
224: if (records == null) {
225: logMessage(Level.WARNING,
226: "In doView: No records obtained from getRequisitionInfoRecords");
227: } else {
228: //For Pagination
229: int rowsToShow = PaginationUtils
230: .getNumberOfPaginationRows(records.size());
231: request.setAttribute("CurrentSummaryPage", "1");
232: request.setAttribute("CurrentPage", "1");
233: Vector cacheData = PaginationUtils
234: .splitPageCacheData(records, sessionID,
235: rowsToShow);
236: responseCache.put(sessionID, cacheData);
237: records = PaginationUtils.getPageCacheData(request,
238: responseCache, "CurrentSummaryPage",
239: sessionID);
240: //End - For Pagination
241: }
242: }
243:
244: } catch (Exception ex) {
245:
246: logMessage(Level.SEVERE,
247: "In doView : while obtaining requisition info records: "
248: + ex);
249:
250: }
251:
252: try {
253: //If we have records to display, set the PaginationRow attribute and dispatch records
254: if (records == null) {
255: // Dispatch the request to a JSP that displays error
256: PortletRequestDispatcher reqDisp = ctx
257: .getRequestDispatcher(NO_RECORDS_JSP);
258: reqDisp.include(request, response);
259:
260: } else {
261: Vector rowData = (Vector) responseCache.get(sessionID);
262: TablePagination.setPaginationRow(request, response,
263: "PaginateSummary", null, rowData.size());
264:
265: // Set the records as an attribute before dispatching to the JSP
266: request.setAttribute("RequisitionInfo", records);
267: pageCache.put(sessionID, records);
268:
269: // Dispatch the request to a relevant JSP
270: PortletRequestDispatcher reqDisp = ctx
271: .getRequestDispatcher(REQUISITION_INFO_JSP);
272: reqDisp.include(request, response);
273: }
274:
275: // If the request is for the details, obtain the details
276: // from the method defined in utility class and append it below the records
277: if (requestType == null) {
278: if (queryValue1 != null) {
279:
280: RequisitionQueryUtils.appendRequisitionDetails(
281: queryValue1, request, response, session,
282: httpReq);
283:
284: }
285: }
286:
287: } catch (Exception ex) {
288:
289: logMessage(Level.SEVERE,
290: "In doView : while dispatching to the JSP : " + ex);
291:
292: }
293:
294: }
295:
296: /**
297: * This method logs the debug messages
298: **/
299: private void logMessage(Object debugLevel, String msg) {
300:
301: logger.log((Level) debugLevel, msg);
302: }
303:
304: }
|