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:
050: /**
051: *
052: * This class provided the utility methods to get the Activity related
053: * information from Siebel Server.
054: *
055: * @version 1.0
056: * @author Deepak H P
057: * @date 25 Feb 2005
058: *
059: **/
060: public class SiebelCustomerAccountDetailsUtils {
061:
062: static Logger logger = SiebelLogger.getLogger();
063: static Hashtable detailsCache = new Hashtable();
064:
065: /**
066: * This method will handle the Account Details Tab request
067: **/
068: public static void handleDetailsRequest(String query,
069: PortletSession session, RenderRequest request,
070: RenderResponse response) {
071: PortletContext ctx = session.getPortletContext();
072: PortletRequestDispatcher reqDisp = null;
073: Vector records = null;
074: String sessionID = session.getId();
075: String actionType = request.getParameter("DetailsActionButton");
076: String xmlOutput = null;
077:
078: try {
079: if ((actionType != null) && (actionType.equals("OK"))) {
080: records = updateAccountDetails(request, query,
081: sessionID);
082: } else {
083: records = getCachedDetailsData(sessionID, query);
084: }
085:
086: if (records == null) {
087:
088: if (query != null) {
089: records = getAccountDetails(query, sessionID);
090: }
091: }
092: request.setAttribute("SiebelAccounts", records);
093: debug("handleDetailsRequest()", "RECORDS : " + records);
094: setDetailsRequestAttributes(actionType, request, query);
095:
096: reqDisp = ctx
097: .getRequestDispatcher("/jsps/SiebelAccountDetails.jsp");
098: reqDisp.include(request, response);
099: } catch (Exception ex) {
100: debug("handleDetailsRequest()", "dispatchRequest Exp : "
101: + ex);
102: }
103: }
104:
105: private static Vector getAccountDetails(String query,
106: String sessionID) {
107:
108: Vector records = null;
109: try {
110: String reqStr = SiebelAccountRequestUtils
111: .getSiebelCustomerAccountsDetailsQuery(query);
112: String xmlOutput = SiebelIwayUtils
113: .getResponseString(reqStr);
114: records = SiebelResponseUtils.getAccountDetails(xmlOutput);
115: putCachedDetailsData(sessionID, query, records);
116: debug("getAccountDetails()", "Got Response ");
117: } catch (Exception ex) {
118: debug("getAccountDetails()", ex.toString());
119: }
120: return records;
121: }
122:
123: private static void putCachedDetailsData(String sessionID,
124: String query, Vector records) {
125:
126: Hashtable sessionData = (Hashtable) detailsCache.get(sessionID);
127:
128: if (sessionData == null) {
129: sessionData = new Hashtable();
130: }
131: sessionData.put(query, records);
132: detailsCache.put(sessionID, sessionData);
133: }
134:
135: private static Vector getCachedDetailsData(String sessionID,
136: String query) {
137:
138: Hashtable sessionData = (Hashtable) detailsCache.get(sessionID);
139: Vector records = null;
140:
141: if (sessionData != null) {
142: records = (Vector) sessionData.get(query);
143: }
144: return records;
145: }
146:
147: private static void setDetailsRequestAttributes(String actionType,
148: RenderRequest request, String query) {
149:
150: if (actionType != null) {
151:
152: if (actionType.equals("Edit")) {
153: setEditableRequestAttributes(request);
154: } else if (actionType.equals("Cancel")) {
155: setEditRequestAttribute(request);
156: } else if (actionType.equals("OK")) {
157: setEditRequestAttribute(request);
158: }
159: } else {
160: setEditRequestAttribute(request);
161: }
162: }
163:
164: private static void setEditRequestAttribute(RenderRequest request) {
165: request
166: .setAttribute("CellTypePrefix",
167: "<div style=\"text-align:Left\"> <div class=\"TblTdLyt\"> ");
168: request.setAttribute("CellTypeSuffix", "</div> </div>");
169: }
170:
171: private static void setEditableRequestAttributes(
172: RenderRequest request) {
173: request
174: .setAttribute(
175: "CellTypePrefix1",
176: "<div style=\"text-align:Left\"> <div class=\"TblTdLyt\"> <input class=\"TxtFld\" name=\"");
177: request.setAttribute("CellTypePrefix2",
178: "\" type=\"text\" value=\"");
179: request.setAttribute("CellTypeSuffix", "\"> </div> </div>");
180: }
181:
182: private static Vector updateAccountDetails(RenderRequest request,
183: String query, String sessionID) {
184:
185: String accountID = request.getParameter("AccountID");
186: String address = request.getParameter("ADDRESS");
187: String site = request.getParameter("SITE");
188: String city = request.getParameter("CITY");
189: String state = request.getParameter("STATE");
190: String zip = request.getParameter("ZIP");
191: String territory = request.getParameter("TERRITORY");
192: String country = request.getParameter("COUNTRY");
193: String phone = request.getParameter("PHONE");
194: String fax = request.getParameter("FAX");
195: String url = request.getParameter("URL");
196: String industry = request.getParameter("INDUSTRY");
197:
198: Vector records = null;
199:
200: StringBuffer sb = new StringBuffer();
201:
202: sb.append("<Siebel location=\"S/BO/Account/Account/update\">");
203:
204: sb.append("<select>");
205: sb.append("<Id>" + accountID + "</Id>");
206: sb.append("</select>");
207:
208: sb.append("<update>");
209: sb.append("<Location>" + site.trim() + "</Location>");
210: sb.append("<Street_spcAddress>" + address.trim()
211: + "</Street_spcAddress>");
212: sb.append("<City>" + city.trim() + "</City>");
213: sb.append("<State>" + state.trim() + "</State>");
214: sb
215: .append("<Postal_spcCode>" + zip.trim()
216: + "</Postal_spcCode>");
217: sb.append("<Country>" + country.trim() + "</Country>");
218: sb.append("<Main_spcPhone_spcNumber>" + phone.trim()
219: + "</Main_spcPhone_spcNumber>");
220: sb.append("<Main_spcFax_spcNumber>" + fax.trim()
221: + "</Main_spcFax_spcNumber>");
222: sb.append("<Home_spcPage>" + url.trim() + "</Home_spcPage>");
223: sb.append("<Territory>" + territory.trim() + "</Territory>");
224: sb.append("<Industry>" + industry.trim() + "</Industry>");
225: sb.append("</update>");
226:
227: sb.append("</Siebel>");
228:
229: String updateQuery = sb.toString();
230:
231: debug("updateAccountDetails()", "Update Query : " + updateQuery);
232:
233: try {
234: String xmlOutput = SiebelIwayUtils
235: .getResponseString(updateQuery);
236: debug("updateAccountDetails()", "Response String : "
237: + xmlOutput);
238: records = getAccountDetails(query, sessionID);
239: debug("updateAccountDetails()", "Record After Update : "
240: + records);
241: } catch (Exception ex) {
242: debug("updateAccountDetails()", "Error in Updating : " + ex);
243: }
244: return records;
245: }
246:
247: public static void resetCache(String sessionID) {
248: detailsCache.remove(sessionID);
249: }
250:
251: /**
252: * This method will print the log the messages.
253: **/
254: private static void debug(String methodName, String msg) {
255: logger.log(Level.INFO,
256: "com.sun.portal.siebelportlet.util.SiebelCustomerAccountDetailsUtils:"
257: + methodName + ":" + msg);
258: }
259: }
|