001: /**
002: * $Id: PSFTEPIPortlet.java,v 1.7 2006/07/28 18:49:18 portalbld Exp $
003: * Copyright 2004 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.psftportlet.epiportlet;
014:
015: import com.sun.portal.psftportlet.common.IUserMapping;
016: import com.sun.portal.psftportlet.common.FileUserMapping;
017: import com.sun.portal.psftportlet.common.IWAYResponseParser;
018: import com.sun.portal.psftportlet.common.StreetAddress;
019: import com.sun.portal.psftportlet.common.PSFTPortletConstants;
020: import com.sun.portal.psftportlet.common.PSFTUserConfig;
021: import com.sun.portal.psftportlet.common.PSFTAuthUtils;
022:
023: import com.sun.portal.iwayutil.connection.IWAYConnection;
024: import com.sun.portal.iwayutil.connection.IWAYConnectionFactory;
025: import com.sun.portal.iwayutil.connection.IWAYRequest;
026: import com.sun.portal.iwayutil.connection.IWAYResponse;
027: import com.sun.portal.iwayutil.connection.IWAYConnectionException;
028:
029: import com.sun.portal.log.common.PortalLogger;
030:
031: import javax.portlet.GenericPortlet;
032: import javax.portlet.PortletContext;
033: import javax.portlet.PortletConfig;
034: import javax.portlet.PortletException;
035: import javax.portlet.RenderResponse;
036: import javax.portlet.RenderRequest;
037: import javax.portlet.PortletSession;
038: import javax.portlet.PortletRequestDispatcher;
039: import javax.portlet.ActionResponse;
040: import javax.portlet.ActionRequest;
041:
042: import java.io.IOException;
043:
044: import java.util.ResourceBundle;
045: import java.util.logging.Logger;
046:
047: /**
048: * This is the Employee Personal Information Portlet for PeopleSoft.
049: *
050: * @author Pradeep Gond
051: */
052:
053: public class PSFTEPIPortlet extends GenericPortlet {
054: private PortletContext pContext;
055: private IUserMapping userMapping;
056: private IWAYConnection conn;
057: private ResourceBundle epiObjectResource;
058: private PSFTEPIUtils epiUtils;
059:
060: private static Logger logger = PortalLogger
061: .getLogger(PSFTEPIPortlet.class);
062:
063: public void init(PortletConfig config) throws PortletException {
064: super .init(config);
065: pContext = config.getPortletContext();
066:
067: // initialize User mapping
068: userMapping = new FileUserMapping(
069: PSFTPortletConstants.mappingResourceName);
070:
071: // initialize the rule resource bundle
072: try {
073: epiObjectResource = ResourceBundle
074: .getBundle(PSFTEPIConstants.epiObjectResourceName);
075: } catch (Exception ex) {
076: logger.severe("Failed to initialize rule resourse => "
077: + ex.getMessage());
078: }
079:
080: epiUtils = new PSFTEPIUtils(epiObjectResource);
081: }
082:
083: public void doView(RenderRequest request, RenderResponse response)
084: throws PortletException, IOException {
085: response.setContentType(request.getResponseContentType());
086: PortletSession session = request.getPortletSession();
087: PSFTUserConfig userConfig = (PSFTUserConfig) session
088: .getAttribute(PSFTPortletConstants.SESSION_USERCONFIG,
089: PortletSession.APPLICATION_SCOPE);
090: if (userConfig == null) {
091: PSFTAuthUtils.checkForUserAuthentication(request);
092: userConfig = (PSFTUserConfig) session.getAttribute(
093: PSFTPortletConstants.SESSION_USERCONFIG,
094: PortletSession.APPLICATION_SCOPE);
095: }
096: String pageName = "";
097:
098: if (userConfig == null) {
099: pageName = PSFTPortletConstants.NO_USER_CONFIG_PAGE;
100: } else {
101: if (conn == null) {
102: try {
103: conn = IWAYConnectionFactory
104: .getIWAYConnection(userConfig
105: .getiWayProperties());
106: } catch (Exception ex) {
107: logger
108: .severe("Exception in getting iWay connection => "
109: + ex.getMessage());
110: }
111: }
112:
113: String userID = userMapping.getERPUser(request
114: .getRemoteUser());
115: if (userID
116: .equalsIgnoreCase(IUserMapping.NO_MAPPING_AVAILABLE)) {
117: pageName = PSFTPortletConstants.NO_USER_MAPPING_PAGE;
118: } else {
119: String nextPage = request
120: .getParameter(PSFTEPIConstants.NEXT_PAGE);
121: pageName = PSFTEPIConstants.VIEW_PAGE;
122:
123: if (nextPage != null
124: && nextPage
125: .equalsIgnoreCase(PSFTEPIConstants.NEXT_PAGE_EDIT)) {
126: pageName = PSFTEPIConstants.EDIT_PAGE;
127: request.setAttribute(
128: PSFTEPIConstants.MARITAL_STATUS_VALUES,
129: epiUtils.getMaritalStatusValues());
130: request.setAttribute(
131: PSFTEPIConstants.RELATIONSHIP_VALUES,
132: epiUtils.getRelationshipValues());
133: } else {
134: PSFTEPIObject obj = getDetails(userID);
135: // put the object in session
136: session.setAttribute(PSFTEPIConstants.EPI_OBJECT,
137: obj, PortletSession.APPLICATION_SCOPE);
138: }
139: }
140: }
141:
142: PortletRequestDispatcher dispatcher = pContext
143: .getRequestDispatcher(pageName);
144: dispatcher.include(request, response);
145: }
146:
147: public void processAction(ActionRequest request,
148: ActionResponse response) throws PortletException {
149: String operation = request
150: .getParameter(PSFTEPIConstants.INPUT_PERFORM);
151: String nextPage = "";
152:
153: if (operation != null
154: && operation
155: .equalsIgnoreCase(PSFTEPIConstants.PERFORM_EDIT)) {
156: nextPage = PSFTEPIConstants.NEXT_PAGE_EDIT;
157: } else if (operation != null
158: && operation
159: .equalsIgnoreCase(PSFTEPIConstants.PERFORM_UPDATE)) {
160: performUpdate(request);
161: nextPage = PSFTEPIConstants.NEXT_PAGE_VIEW;
162: }
163: response.setRenderParameter(PSFTEPIConstants.NEXT_PAGE,
164: nextPage);
165: }
166:
167: public void doHelp(RenderRequest request, RenderResponse response)
168: throws IOException, PortletException {
169: response.setContentType(request.getResponseContentType());
170: PortletRequestDispatcher dispatcher = pContext
171: .getRequestDispatcher(PSFTEPIConstants.HELP_PAGE);
172: dispatcher.include(request, response);
173: }
174:
175: private PSFTEPIObject getDetails(String userID) {
176: PSFTEPIObject obj = new PSFTEPIObject();
177:
178: // Personal Data
179: IWAYRequest ireq = epiUtils
180: .getPersonalDataBrowseRequest(userID);
181: IWAYResponse ires = null;
182:
183: try {
184: ires = conn.getResponse(ireq);
185: } catch (IWAYConnectionException e) {
186: logger.severe("Exception in getting iWay response => "
187: + e.getMessage());
188: }
189: String xmlOutput = ires.getResponseString();
190: IWAYResponseParser parser = new IWAYResponseParser(xmlOutput,
191: epiObjectResource);
192: if (parser.isValid()) {
193: epiUtils.parsePersonalData(parser, obj);
194: } else {
195: obj.setErrorMessage(parser.getErrorMessage());
196: }
197:
198: // Emergency Contact
199: ireq = epiUtils.getEmergencyContactBrowseRequest(userID);
200:
201: try {
202: ires = conn.getResponse(ireq);
203: } catch (IWAYConnectionException e) {
204: logger.severe("Exception in getting iWay response => "
205: + e.getMessage());
206: }
207: xmlOutput = ires.getResponseString();
208: parser = new IWAYResponseParser(xmlOutput, epiObjectResource);
209: if (parser.isValid()) {
210: epiUtils.parseEmergencyContact(parser, obj);
211: } else {
212: obj.setErrorMessage(parser.getErrorMessage());
213: }
214:
215: return obj;
216: }
217:
218: private void performUpdate(ActionRequest request) {
219: PortletSession session = request.getPortletSession();
220: PSFTEPIObject origObj = (PSFTEPIObject) session.getAttribute(
221: PSFTEPIConstants.EPI_OBJECT,
222: PortletSession.APPLICATION_SCOPE);
223: PSFTEPIObject newObj = new PSFTEPIObject();
224: String param = "";
225:
226: // read the parameters and pupulate the newObj
227: // last name
228: param = request
229: .getParameter(PSFTEPIConstants.EMPLOYEE_LAST_NAME);
230: if (param != null) {
231: newObj.setEmployeeLastName(param);
232: }
233:
234: //first name
235: param = request
236: .getParameter(PSFTEPIConstants.EMPLOYEE_FIRST_NAME);
237: if (param != null) {
238: newObj.setEmployeeFirstName(param);
239: }
240:
241: // home address
242: String[] array = {
243: request.getParameter(PSFTEPIConstants.HOME_ADDR_LINE_1),
244: request.getParameter(PSFTEPIConstants.HOME_ADDR_LINE_2),
245: request.getParameter(PSFTEPIConstants.HOME_ADDR_CITY),
246: request.getParameter(PSFTEPIConstants.HOME_ADDR_STATE),
247: request.getParameter(PSFTEPIConstants.HOME_ADDR_PIN) };
248: newObj.setHomeAddress(new StreetAddress(array));
249:
250: // mail address
251: array = new String[] {
252: request.getParameter(PSFTEPIConstants.MAIL_ADDR_LINE_1),
253: request.getParameter(PSFTEPIConstants.MAIL_ADDR_LINE_2),
254: request.getParameter(PSFTEPIConstants.MAIL_ADDR_CITY),
255: request.getParameter(PSFTEPIConstants.MAIL_ADDR_STATE),
256: request.getParameter(PSFTEPIConstants.MAIL_ADDR_PIN) };
257: newObj.setMailAddress(new StreetAddress(array));
258:
259: // home phone number
260: param = request.getParameter(PSFTEPIConstants.HOME_PHONE);
261: if (param != null) {
262: newObj.setPhoneNumber(param);
263: }
264:
265: // home email address
266: param = request.getParameter(PSFTEPIConstants.HOME_EMAIL);
267: if (param != null) {
268: newObj.setEmailID(param);
269: }
270:
271: // marital status
272: param = request.getParameter(PSFTEPIConstants.MARITAL_STATUS);
273: if (param != null) {
274: newObj.setMaritalStatus(param);
275: }
276:
277: // emergency contact name
278: param = request
279: .getParameter(PSFTEPIConstants.EMERGENCY_CONTACT);
280: if (param != null) {
281: newObj.setEmergencyContact(param);
282: }
283:
284: // emergency contact relationship
285: param = request.getParameter(PSFTEPIConstants.CONTACT_RELATION);
286: if (param != null) {
287: newObj.setContactRelation(param);
288: }
289:
290: // emergency contact address
291: array = new String[] {
292: request
293: .getParameter(PSFTEPIConstants.CONTACT_ADDR_LINE_1),
294: request
295: .getParameter(PSFTEPIConstants.CONTACT_ADDR_LINE_2),
296: request
297: .getParameter(PSFTEPIConstants.CONTACT_ADDR_CITY),
298: request
299: .getParameter(PSFTEPIConstants.CONTACT_ADDR_STATE),
300: request.getParameter(PSFTEPIConstants.CONTACT_ADDR_PIN) };
301: newObj.setContactAddress(new StreetAddress(array));
302:
303: // emergency contact phone
304: param = request.getParameter(PSFTEPIConstants.CONTACT_PHONE);
305: if (param != null) {
306: newObj.setContactPhone(param);
307: }
308:
309: // start updation now
310: String userID = userMapping.getERPUser(request.getRemoteUser());
311: // Personal Data
312: IWAYRequest ireq = epiUtils.getPersonalDataUpdateRequest(
313: userID, origObj, newObj);
314: IWAYResponse ires = null;
315:
316: try {
317: ires = conn.getResponse(ireq);
318: } catch (IWAYConnectionException e) {
319: logger.severe("Exception in getting iWay response => "
320: + e.getMessage());
321: }
322: String xmlOutput = ires.getResponseString();
323: if (xmlOutput.indexOf("done") == -1) {
324: IWAYResponseParser parser = new IWAYResponseParser(
325: xmlOutput, epiObjectResource);
326: logger.info("Error updating personal data => "
327: + parser.getErrorMessage());
328: }
329:
330: // emergency contact
331: ireq = epiUtils.getEmergencyContactUpdateRequest(userID,
332: origObj, newObj);
333:
334: try {
335: ires = conn.getResponse(ireq);
336: } catch (IWAYConnectionException e) {
337: logger.severe("Exception in getting iWay response => "
338: + e.getMessage());
339: }
340: xmlOutput = ires.getResponseString();
341: if (xmlOutput.indexOf(PSFTPortletConstants.DONE) == -1) {
342: IWAYResponseParser parser = new IWAYResponseParser(
343: xmlOutput, epiObjectResource);
344: logger.info("Error updating emergency contact => "
345: + parser.getErrorMessage());
346: }
347: }
348:
349: }
|