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: package com.sun.portal.siebelportlet.util;
038:
039: import java.util.Enumeration;
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:
048: import com.sun.portal.iwayutil.config.*;
049: import com.sun.portal.iwayutil.connection.*;
050:
051: /**
052: *
053: * This class provided the utility methods to get the Account related
054: * information from Siebel Server.
055: *
056: * @version 1.0
057: * @author Deepak H P
058: * @date 25 Feb 2005
059: *
060: **/
061: public class SiebelAccountRequestUtils implements SiebelConstants {
062:
063: // Name of the Siebel business object from where the Accounts data
064: // should be obtained.
065: static String businessMethod = "<Siebel location=\"S/BO/Account/Account/query\">";
066:
067: static Logger logger = SiebelLogger.getLogger();
068:
069: // Fields that should be obtained in the result set for Account Summary
070: public static final String[] accountSummaryFields = { "Id", "Name",
071: "Location", "Main Phone Number", "Main Fax Number",
072: "Account Status", "Sales Rep", "Territory" };
073:
074: // Fields that should be obtained in the result set for Account Details
075: public static final String[] accountDetailsFields = { "Id", "Name",
076: "Location", "Street Address", "City", "State",
077: "Postal Code", "Country", "Main Phone Number",
078: "Main Fax Number", "Home Page", "Account Status", "Type",
079: "Sales Rep", "Territory", "Industry" };
080:
081: /**
082: * This method returns the XML query to get the Siebel Account Summary
083: */
084: public static String getSiebelCustomerAccountsSummaryQuery(
085: String query) {
086: return getSiebelQuery(query, accountSummaryFields);
087: }
088:
089: /**
090: * This method returns the XML query to get the Siebel Account Details
091: */
092: public static String getSiebelCustomerAccountsDetailsQuery(
093: String query) {
094: return getSiebelQuery(query, accountDetailsFields);
095: }
096:
097: /**
098: * Utility method to form the query
099: */
100: private static String getSiebelQuery(String query, String[] fields) {
101:
102: StringBuffer qBuf = new StringBuffer();
103: qBuf.append(businessMethod);
104: qBuf.append("<select>");
105: qBuf.append(query);
106: qBuf.append("</select>");
107:
108: for (int i = 0; i < fields.length; i++) {
109: qBuf.append("<field>");
110: qBuf.append(fields[i]);
111: qBuf.append("</field>");
112: }
113: qBuf.append("</Siebel>");
114: return qBuf.toString();
115: }
116:
117: /**
118: * This method will determine the query and dispatches the request to
119: * corresponding handlers.
120: **/
121: public static void displayDetails(String linkType,
122: String queryField, String queryValue,
123: RenderRequest request, RenderResponse response,
124: PortletSession session) throws PortletException,
125: IOException {
126:
127: String query = null;
128: String searchType = linkType;
129:
130: try {
131:
132: if (searchType == null) {
133: searchType = "Details";
134: }
135: query = "<" + queryField + ">" + queryValue + "</"
136: + queryField + ">";
137:
138: debug("displayDetails()", "Setting Account ID : "
139: + queryValue);
140: request.setAttribute("AccountID", queryValue);
141: debug("displayDetails()", "QUERY : " + query);
142: if (searchType.equals("Details")) {
143: SiebelCustomerAccountDetailsUtils.handleDetailsRequest(
144: query, session, request, response);
145: } else if ((searchType.equals("Contacts"))
146: || (searchType.equals("ContactDetails"))
147: || (searchType.equals("PaginateContact"))) {
148: SiebelContactRequestUtils.handleContactsRequest(query,
149: session, request, response);
150: } else if ((searchType.equals("Activities"))
151: || (searchType.equals("ActivityDetails"))
152: || (searchType.equals("PaginateActivity"))) {
153: SiebelActivityRequestUtils.handleActivitiesRequest(
154: query, session, request, response);
155: } else if ((searchType.equals("Opportunities"))
156: || (searchType.equals("OpportunityDetails"))
157: || (searchType.equals("PaginateOpportunity"))) {
158: SiebelOpportunityRequestUtils
159: .handleOpportunitiesRequest(query, session,
160: request, response);
161: } else if ((searchType.equals("Invoices"))
162: || (searchType.equals("InvoiceDetails"))
163: || (searchType.equals("PaginateInvoice"))) {
164: SiebelInvoiceRequestUtils.handleInvoicesRequest(query,
165: session, request, response);
166: } else if ((searchType.equals("Forecasts"))
167: || (searchType.equals("ForecastDetails"))
168: || (searchType.equals("PaginateForecast"))) {
169: SiebelForecastRequestUtils.handleForecastsRequest(
170: query, session, request, response);
171: }
172: } catch (Exception ex) {
173: debug("displayDetails()", "Exp " + ex);
174: }
175: }
176:
177: public static void resetCache(String sessionID) {
178:
179: SiebelCustomerAccountDetailsUtils.resetCache(sessionID);
180: SiebelContactRequestUtils.resetCache(sessionID);
181: SiebelActivityRequestUtils.resetCache(sessionID);
182: SiebelOpportunityRequestUtils.resetCache(sessionID);
183: SiebelInvoiceRequestUtils.resetCache(sessionID);
184: SiebelForecastRequestUtils.resetCache(sessionID);
185: }
186:
187: public static void resetDetailsCache(String sessionID) {
188:
189: SiebelContactRequestUtils.resetCache(sessionID);
190: SiebelActivityRequestUtils.resetCache(sessionID);
191: SiebelOpportunityRequestUtils.resetCache(sessionID);
192: SiebelInvoiceRequestUtils.resetCache(sessionID);
193: SiebelForecastRequestUtils.resetCache(sessionID);
194: }
195:
196: public static Vector setPageCacheData(Vector records,
197: String sessionID, int rowsToShow) {
198:
199: int size = records.size();
200: int i = 0;
201: boolean added = false;
202: Vector rowData = new Vector();
203: Vector rows = new Vector();
204:
205: debug("setResponseCacheData()", "rowsToShow : " + rowsToShow);
206: debug("setResponseCacheData()", "size : " + size);
207:
208: for (i = 1; i <= size; i++) {
209: added = false;
210: rows.addElement(records.elementAt(i - 1));
211:
212: if ((i % rowsToShow) == 0) {
213: rowData.addElement(rows);
214: rows = new Vector();
215: added = true;
216: }
217: }
218:
219: if (added == false) {
220: rowData.addElement(rows);
221: }
222: return rowData;
223: }
224:
225: public static Vector resetPageCacheData(Vector rowData,
226: String sessionID, int rowsToShow) {
227:
228: int size = rowData.size();
229: int i = 0;
230: int j = 0;
231: int rowSize = 0;
232: boolean added = false;
233: Vector records = new Vector();
234: Vector rows = new Vector();
235: Object row = null;
236:
237: debug("resetPageCacheData()", "rowsToShow : " + rowsToShow);
238: debug("resetPageCacheData()", "size : " + size);
239:
240: for (i = 0; i < size; i++) {
241: rows = (Vector) rowData.elementAt(i);
242: rowSize = rows.size();
243:
244: for (j = 0; j < rowSize; j++) {
245: row = rows.elementAt(j);
246: records.addElement(row);
247: }
248: }
249: return setPageCacheData(records, sessionID, rowsToShow);
250: }
251:
252: public static Vector getPageCacheData(RenderRequest request,
253: Hashtable cache, String attributeName, String sessionID) {
254:
255: Vector retVal = null;
256: Vector rowData = (Vector) cache.get(sessionID);
257: int curPage = 0;
258:
259: debug("getPageCacheData()", "attributeName " + attributeName);
260:
261: if (rowData != null) {
262: int size = rowData.size();
263:
264: String curPageStr = (String) request
265: .getAttribute(attributeName);
266: try {
267: curPage = Integer.parseInt(curPageStr);
268: } catch (Exception ex) {
269:
270: if (size > 0) {
271: curPage = 1;
272: } else {
273: curPage = 0;
274: }
275: }
276: }
277:
278: debug("getPageCacheData()", "curPage " + curPage);
279: if (curPage > 0) {
280: retVal = (Vector) rowData.elementAt(curPage - 1);
281: }
282: debug("getPageCacheData()", "returning ");
283: return retVal;
284: }
285:
286: public static Vector getMergedCacheData(Hashtable cache,
287: String sessionID) {
288:
289: Vector retVal = null;
290: Vector rowData = (Vector) cache.get(sessionID);
291:
292: debug("getMergedCacheData()", "Entering");
293:
294: if (rowData != null) {
295: retVal = new Vector();
296:
297: int size = rowData.size();
298:
299: for (int i = 0; i < size; i++) {
300: Vector tempVector = (Vector) rowData.elementAt(i);
301: retVal.addAll(tempVector);
302: }
303: }
304: debug("getMergedCacheData()", "Returning ");
305: return retVal;
306: }
307:
308: public static String checkGoToValue(String queryValue,
309: String tableSize) {
310:
311: String retVal = queryValue;
312:
313: try {
314: int qVal = Integer.parseInt(queryValue);
315: int tVal = Integer.parseInt(tableSize);
316:
317: if ((qVal < 1) || (qVal > tVal)) {
318: retVal = "1";
319: }
320:
321: } catch (Exception ex) {
322: retVal = "1";
323: }
324: return retVal;
325: }
326:
327: public static void dispatchToConfigErrorPage(RenderRequest request,
328: RenderResponse response) throws PortletException,
329: IOException {
330: PortletSession session = request.getPortletSession(true);
331: PortletContext ctx = session.getPortletContext();
332: response.setContentType(request.getResponseContentType());
333: PortletRequestDispatcher dispatcher = ctx
334: .getRequestDispatcher(USER_NO_CONFIG_PAGE);
335: dispatcher.include(request, response);
336: }
337:
338: public static void dispatchToNOSSOErrorPage(RenderRequest request,
339: RenderResponse response) throws PortletException,
340: IOException {
341: PortletSession session = request.getPortletSession(true);
342: PortletContext ctx = session.getPortletContext();
343: response.setContentType(request.getResponseContentType());
344: PortletRequestDispatcher dispatcher = ctx
345: .getRequestDispatcher(USER_NO_SSOA_PAGE);
346: dispatcher.include(request, response);
347: }
348:
349: public static void dispatchToConfigLoginPage(RenderRequest request,
350: RenderResponse response) throws PortletException,
351: IOException {
352: PortletSession session = request.getPortletSession(true);
353: PortletContext ctx = session.getPortletContext();
354: response.setContentType(request.getResponseContentType());
355: PortletRequestDispatcher dispatcher = ctx
356: .getRequestDispatcher(USER_CONFIG_PAGE);
357: dispatcher.include(request, response);
358: }
359:
360: /**
361: * This method will print the log the messages.
362: **/
363: private static void debug(String methodName, String msg) {
364: logger.log(Level.INFO,
365: "com.sun.portal.siebelportlet.util.SiebelAccountRequestUtils:"
366: + methodName + ":" + msg);
367: }
368: }
|