001: /**
002: * $Id: TimeManager.java,v 1.4 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.time;
014:
015: import com.sun.portal.sapportlet.config.SAPUserConfig;
016: import javax.xml.rpc.Stub;
017: import java.util.ArrayList;
018: import java.util.List;
019: import java.util.logging.Logger;
020: import com.sun.portal.sapportlet.SAPPortletConstants;
021: import com.sun.portal.sapportlet.stubs.time.*;
022:
023: /**
024: * This is the delegate class that handles all interactions with
025: * the Employee related web services.
026: *
027: * @author nk137934
028: */
029: public class TimeManager implements SAPPortletConstants {
030:
031: private static Logger logger = Logger.getLogger(LOGGER_NAMESPACE);
032: private BAPI_ABSENCE_GETDETAILEDLISTPortType portType = null;
033: private SAPUserConfig userConfig = null;
034:
035: /*
036: * This method read the sap configuration details and initializes the
037: * web service stub
038: */
039: public void init(SAPUserConfig userConfig, String endPointAddress) {
040:
041: //logger.fine("Init of TimeManager");
042:
043: this .userConfig = userConfig;
044: //String endPointAddress = SAPConfiguration.getEndpointAddress();
045:
046: String userName = userConfig.getUserName();
047: String userPass = userConfig.getUserPassword();
048:
049: Stub stub = createProxy();
050: stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,
051: endPointAddress);
052: stub._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY,
053: userName);
054: stub._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY,
055: userPass);
056:
057: portType = (BAPI_ABSENCE_GETDETAILEDLISTPortType) stub;
058: //logger.info("TimeManager init success");
059: }
060:
061: /*
062: * Finds the sales order given a customer number
063: */
064: public List getAbsenceDetails(String employeeNumber) {
065:
066: ArrayList results = new ArrayList();
067: BAPI_ABSENCE_GETDETAILEDLIST parameters = new BAPI_ABSENCE_GETDETAILEDLIST();
068: parameters.setEMPLOYEENUMBER(employeeNumber);
069: parameters.setTIMEINTERVALHIGH(TIME_INTERVAL_HIGH);
070: parameters.setTIMEINTERVALLOW(TIME_INTERVAL_LOW);
071:
072: BAPI_ABSENCE_GETDETAILEDLISTABSENCE temp = new BAPI_ABSENCE_GETDETAILEDLISTABSENCE();
073: parameters.setABSENCE(temp);
074:
075: BAPI_ABSENCE_GETDETAILEDLISTResponseABSENCE response = null;
076:
077: //invoke the Web Service
078: try {
079: response = portType
080: .BAPI_ABSENCE_GETDETAILEDLIST(parameters)
081: .getABSENCE();
082: } catch (Exception excp) {
083: logger.severe("Failed to execute search");
084: logger.severe(excp.getMessage());
085: return null;
086: }
087: BAPIP2001L[] data = response.getItem();
088: for (int k = 0; k < data.length; k++) {
089: results.add(new AbsenceRecord((BAPIP2001L) data[k]));
090: }
091:
092: return results;
093:
094: }
095:
096: private static Stub createProxy() {
097: return (Stub) (new BAPI_ABSENCE_GETDETAILEDLISTService_Impl()
098: .getBAPI_ABSENCE_GETDETAILEDLISTPortType());
099: }
100:
101: public SAPUserConfig getUserConfig() {
102: return userConfig;
103: }
104: }
|