001: /**
002: * $Id: PSFTTimeEntryPortlet.java,v 1.3 2005/10/19 12:38:58 pg133018 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.timeentryportlet;
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.PSFTPortletConstants;
019: import com.sun.portal.psftportlet.common.PSFTUserConfig;
020: import com.sun.portal.psftportlet.common.PSFTAuthUtils;
021:
022: import com.sun.portal.iwayutil.connection.IWAYConnection;
023: import com.sun.portal.iwayutil.connection.IWAYConnectionFactory;
024: import com.sun.portal.iwayutil.connection.IWAYRequest;
025: import com.sun.portal.iwayutil.connection.IWAYResponse;
026: import com.sun.portal.iwayutil.connection.IWAYConnectionException;
027:
028: import com.sun.portal.log.common.PortalLogger;
029:
030: import javax.portlet.GenericPortlet;
031: import javax.portlet.PortletContext;
032: import javax.portlet.PortletConfig;
033: import javax.portlet.PortletException;
034: import javax.portlet.RenderResponse;
035: import javax.portlet.RenderRequest;
036: import javax.portlet.PortletSession;
037: import javax.portlet.PortletRequestDispatcher;
038:
039: import java.io.IOException;
040:
041: import java.util.ResourceBundle;
042: import java.util.logging.Logger;
043:
044: /**
045: * This is the Employee Time Entry Portlet for PeopleSoft.
046: *
047: * @author Pradeep Gond
048: */
049:
050: public class PSFTTimeEntryPortlet extends GenericPortlet {
051: private PortletContext pContext;
052: private IUserMapping userMapping;
053: private IWAYConnection conn;
054: private ResourceBundle objectResource;
055: private PSFTTimeEntryUtils timeEntryUtils;
056:
057: private static Logger logger = PortalLogger
058: .getLogger(PSFTTimeEntryPortlet.class);
059:
060: public void init(PortletConfig config) throws PortletException {
061: super .init(config);
062: pContext = config.getPortletContext();
063:
064: // initialize User mapping
065: userMapping = new FileUserMapping(
066: PSFTPortletConstants.mappingResourceName);
067:
068: // initialize the rule resource bundle
069: try {
070: objectResource = ResourceBundle
071: .getBundle(PSFTTimeEntryConstants.objectResourceName);
072: } catch (Exception ex) {
073: logger.severe("Failed to initialize rule resourse => "
074: + ex.getMessage());
075: }
076:
077: timeEntryUtils = new PSFTTimeEntryUtils(objectResource);
078: }
079:
080: public void doView(RenderRequest request, RenderResponse response)
081: throws PortletException, IOException {
082: response.setContentType(request.getResponseContentType());
083: PortletSession session = request.getPortletSession();
084: PSFTUserConfig userConfig = (PSFTUserConfig) session
085: .getAttribute(PSFTPortletConstants.SESSION_USERCONFIG,
086: PortletSession.APPLICATION_SCOPE);
087: if (userConfig == null) {
088: PSFTAuthUtils.checkForUserAuthentication(request);
089: userConfig = (PSFTUserConfig) session.getAttribute(
090: PSFTPortletConstants.SESSION_USERCONFIG,
091: PortletSession.APPLICATION_SCOPE);
092: }
093: String pageName = "";
094:
095: if (userConfig == null) {
096: pageName = PSFTPortletConstants.NO_USER_CONFIG_PAGE;
097: } else {
098: if (conn == null) {
099: try {
100: conn = IWAYConnectionFactory
101: .getIWAYConnection(userConfig
102: .getiWayProperties());
103: } catch (Exception ex) {
104: logger
105: .severe("Exception in getting iWay connection => "
106: + ex.getMessage());
107: }
108: }
109:
110: String userID = userMapping.getERPUser(request
111: .getRemoteUser());
112: if (userID
113: .equalsIgnoreCase(IUserMapping.NO_MAPPING_AVAILABLE)) {
114: pageName = PSFTPortletConstants.NO_USER_MAPPING_PAGE;
115: } else {
116: PSFTTimeEntryObject obj = getDetails(userID);
117: session.setAttribute(
118: PSFTTimeEntryConstants.TIME_ENTRY_OBJECT, obj,
119: PortletSession.APPLICATION_SCOPE);
120: pageName = PSFTTimeEntryConstants.VIEW_PAGE;
121: }
122: }
123:
124: PortletRequestDispatcher dispatcher = pContext
125: .getRequestDispatcher(pageName);
126: dispatcher.include(request, response);
127: }
128:
129: public void doHelp(RenderRequest request, RenderResponse response)
130: throws IOException, PortletException {
131: response.setContentType(request.getResponseContentType());
132: PortletRequestDispatcher dispatcher = pContext
133: .getRequestDispatcher(PSFTTimeEntryConstants.HELP_PAGE);
134: dispatcher.include(request, response);
135: }
136:
137: private PSFTTimeEntryObject getDetails(String userID) {
138: PSFTTimeEntryObject result = new PSFTTimeEntryObject();
139:
140: IWAYRequest ireq = timeEntryUtils.getBrowseRequest(userID);
141: IWAYResponse ires = null;
142:
143: try {
144: ires = conn.getResponse(ireq);
145: } catch (IWAYConnectionException e) {
146: logger.severe("Exception in getting iWay response => "
147: + e.getMessage());
148: }
149: String xmlOutput = ires.getResponseString();
150: IWAYResponseParser parser = new IWAYResponseParser(xmlOutput,
151: objectResource);
152: timeEntryUtils.parseData(parser, result);
153:
154: return result;
155: }
156: }
|