001: /**
002: * $Id: EmployeeManager.java,v 1.6 2005/10/19 10:26:29 ks161616 Exp $
003: * Copyright 2005 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.sapportlet.employee;
014:
015: import com.sun.portal.sapportlet.config.SAPUserConfig;
016: import com.sun.portal.sapportlet.stubs.employee.*;
017: import com.sun.portal.sapportlet.stubs.employee.photo.*;
018: import com.sun.portal.sapportlet.stubs.employee.data.*; //import com.sun.portal.sapportlet.stubs.employee.edit.*;
019: import com.sun.portal.sapportlet.SAPPortletConstants;
020: import javax.xml.rpc.Stub;
021: import java.util.logging.Logger;
022: import java.rmi.RemoteException;
023: import java.net.URL;
024:
025: /**
026: * This is the delegate class that handles all interactions with
027: * the Employee related web services.
028: *
029: * @author nk137934
030: */
031: public class EmployeeManager implements SAPPortletConstants {
032:
033: private static Logger logger = Logger.getLogger(LOGGER_NAMESPACE);
034:
035: private BAPI_PERSDATA_GETDETAILEDLISTPortType viewPortType = null;
036: private HRWPC_RFC_EP_READ_PHOTO_URIPortType photoPortType = null;
037: private HR_GETEMPLOYEEDATA_FROMUSERPortType dataPortType = null;
038:
039: private SAPUserConfig userConfig = null;
040: private String employeeNumber;
041:
042: /*
043: * This method read the sap configuration details and initializes the
044: * web service stub
045: */
046: public void init(SAPUserConfig userConfig, String endPointAddress) {
047:
048: //logger.fine("Init of EmployeeManager");
049:
050: this .userConfig = userConfig;
051: //String endPointAddress = SAPConfiguration.getEndpointAddress();
052:
053: String userName = userConfig.getUserName();
054: String userPass = userConfig.getUserPassword();
055:
056: Stub stub = createViewProxy();
057: stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,
058: endPointAddress);
059: stub._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY,
060: userName);
061: stub._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY,
062: userPass);
063: viewPortType = (BAPI_PERSDATA_GETDETAILEDLISTPortType) stub;
064:
065: Stub photoStub = createPhotoProxy();
066: photoStub._setProperty(
067: javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,
068: endPointAddress);
069: photoStub._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY,
070: userName);
071: photoStub._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY,
072: userPass);
073: photoPortType = (HRWPC_RFC_EP_READ_PHOTO_URIPortType) photoStub;
074:
075: Stub dataStub = createDataProxy();
076: dataStub._setProperty(
077: javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,
078: endPointAddress);
079: dataStub._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY,
080: userName);
081: dataStub._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY,
082: userPass);
083: dataPortType = (HR_GETEMPLOYEEDATA_FROMUSERPortType) dataStub;
084:
085: }
086:
087: public Employee getEmployee(String employeeName, String endPointHost)
088: throws RemoteException {
089:
090: // Get employee number given the employee name
091: HR_GETEMPLOYEEDATA_FROMUSER dataParams = new HR_GETEMPLOYEEDATA_FROMUSER();
092: dataParams.setUSERNAME(employeeName);
093: dataParams.setVALIDBEGIN(TIME_INTERVAL_HIGH);
094: HR_GETEMPLOYEEDATA_FROMUSERResponse dataResp = dataPortType
095: .HR_GETEMPLOYEEDATA_FROMUSER(dataParams);
096: String employeeNumber = dataResp.getEMPLOYEENUMBER();
097:
098: BAPI_PERSDATA_GETDETAILEDLIST parameters = new BAPI_PERSDATA_GETDETAILEDLIST();
099: parameters.setEMPLOYEENUMBER(employeeNumber);
100: parameters.setTIMEINTERVALHIGH(TIME_INTERVAL_HIGH);
101: parameters.setTIMEINTERVALLOW(TIME_INTERVAL_LOW);
102: BAPI_PERSDATA_GETDETAILEDLISTPERSONALDATA persdata = new BAPI_PERSDATA_GETDETAILEDLISTPERSONALDATA();
103: parameters.setPERSONALDATA(persdata);
104: BAPI_PERSDATA_GETDETAILEDLISTResponsePERSONALDATA response = null;
105:
106: // Invoke the Web Service
107: response = viewPortType.BAPI_PERSDATA_GETDETAILEDLIST(
108: parameters).getPERSONALDATA();
109:
110: BAPIP0002L[] items = response.getItem();
111: Employee emp = null;
112: if (items.length >= 1) {
113: emp = new Employee(items[0]);
114:
115: } else {
116: return emp;
117: }
118: HRWPC_RFC_EP_READ_PHOTO_URI photoParams = new HRWPC_RFC_EP_READ_PHOTO_URI();
119: photoParams.setPERNR(emp.getEmployeeNumber());
120: HRWPC_RFC_EP_READ_PHOTO_URIResponse resp = photoPortType
121: .HRWPC_RFC_EP_READ_PHOTO_URI(photoParams);
122:
123: // The URL does not contain the FQDN
124: URL photoURL = getFullyQualifiedURL(resp.getURI(), endPointHost);
125: emp.setPhotoURL(photoURL.toString());
126: return emp;
127: }
128:
129: private URL getFullyQualifiedURL(String givenURLString,
130: String endPointHost) {
131:
132: URL newURL = null;
133: try {
134:
135: URL givenURL = new URL(givenURLString);
136: String protocol = givenURL.getProtocol();
137: int port = givenURL.getPort();
138: String file = givenURL.getFile();
139: newURL = new URL(protocol, endPointHost, port, file);
140: } catch (Exception excp) {
141: }
142: return newURL;
143:
144: }
145:
146: private static Stub createViewProxy() {
147: return (Stub) (new BAPI_PERSDATA_GETDETAILEDLISTService_Impl()
148: .getBAPI_PERSDATA_GETDETAILEDLISTPortType());
149: }
150:
151: private static Stub createPhotoProxy() {
152: return (Stub) (new HRWPC_RFC_EP_READ_PHOTO_URIService_Impl()
153: .getHRWPC_RFC_EP_READ_PHOTO_URIPortType());
154: }
155:
156: private static Stub createDataProxy() {
157: return (Stub) (new HR_GETEMPLOYEEDATA_FROMUSERService_Impl()
158: .getHR_GETEMPLOYEEDATA_FROMUSERPortType());
159: }
160:
161: public SAPUserConfig getUserConfig() {
162: return userConfig;
163: }
164:
165: }
|