001: /**
002: * $Id: SalesOrderManager.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.salesorder;
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.salesorder.*;
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 SalesOrderManager implements SAPPortletConstants {
030:
031: private static Logger logger = Logger.getLogger(LOGGER_NAMESPACE);
032: private BAPI_SALESORDER_GETLISTPortType 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 SalesOrderManager");
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_SALESORDER_GETLISTPortType) stub;
058: logger.info("SalesOrderManager init success");
059: }
060:
061: /*
062: * Finds the sales order given a customer number
063: */
064: public List findSalesOrdersForCustomer(String customerNumber) {
065:
066: List results = new ArrayList();
067:
068: BAPI_SALESORDER_GETLIST parameters = new BAPI_SALESORDER_GETLIST();
069: parameters.setCUSTOMER_NUMBER(customerNumber);
070: parameters.setSALES_ORGANIZATION("");
071: BAPI_SALESORDER_GETLISTSALES_ORDERS temp = new BAPI_SALESORDER_GETLISTSALES_ORDERS();
072: parameters.setSALES_ORDERS(temp);
073:
074: BAPI_SALESORDER_GETLISTResponseSALES_ORDERS response = null;
075:
076: //invoke the Web Service
077: try {
078: response = portType.BAPI_SALESORDER_GETLIST(parameters)
079: .getSALES_ORDERS();
080: } catch (Exception excp) {
081: logger
082: .severe("SAPSalesOrderPortlet failed to execute search");
083: logger.severe(excp.getMessage());
084: return null;
085: }
086:
087: //get the response data
088: BAPIORDERS[] data = response.getItem();
089: for (int k = 0; k < data.length; k++) {
090: results.add(new SalesOrder((BAPIORDERS) data[k]));
091: }
092:
093: return results;
094: }
095:
096: private static Stub createProxy() {
097: return (Stub) (new BAPI_SALESORDER_GETLISTService_Impl()
098: .getBAPI_SALESORDER_GETLISTPortType());
099: }
100:
101: public SAPUserConfig getUserConfig() {
102: return userConfig;
103: }
104: }
|