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