001: /**
002: * $Id: CustomerManager.java,v 1.7 2005/10/19 10:26:28 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.customer;
014:
015: import com.sun.portal.sapportlet.config.SAPUserConfig;
016: import com.sun.portal.sapportlet.SAPPortletConstants;
017: import com.sun.portal.sapportlet.stubs.customer.*;
018: import javax.xml.rpc.Stub;
019: import java.util.List;
020: import java.util.ArrayList;
021: import java.util.logging.Logger;
022: import java.rmi.RemoteException;
023:
024: /**
025: * This is the delegate class that handles all interactions with
026: * the Customer Web Service.
027: *
028: * @author nk137934
029: */
030:
031: public class CustomerManager implements SAPPortletConstants {
032:
033: private static Logger logger = Logger.getLogger(LOGGER_NAMESPACE);
034: private RFC_CUSTOMER_GETPortType portType = null;
035: private SAPUserConfig userConfig = null;
036:
037: /*
038: * This method read the sap configuration details and initializes the
039: * web service stub
040: */
041: public void init(SAPUserConfig userConfig, String endPointAddress) {
042:
043: logger.fine("Init of CustomerManager");
044:
045: this .userConfig = userConfig;
046: // String endPointAddress = SAPConfiguration.getEndpointAddress();
047:
048: String userName = userConfig.getUserName();
049: String userPass = userConfig.getUserPassword();
050:
051: Stub stub = createProxy();
052: stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,
053: endPointAddress);
054: stub._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY,
055: userName);
056: stub._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY,
057: userPass);
058:
059: portType = (RFC_CUSTOMER_GETPortType) stub;
060: logger.info("Customer Manager init success");
061: }
062:
063: /*
064: * This method searches for customers with names beginning
065: * with the given pattern. It return empty list when there
066: * are no results
067: */
068: public List findCustomerByName(String pattern)
069: throws RemoteException {
070:
071: ArrayList results = new ArrayList();
072: logger.fine("Finding Customer By Name");
073: logger.fine("Search Pattern:" + pattern);
074:
075: //Create input parameters
076: RFC_CUSTOMER_GET parameters = new RFC_CUSTOMER_GET();
077: parameters.setKUNNR("*");
078: parameters.setNAME1(pattern);
079:
080: RFC_CUSTOMER_GETCUSTOMER_T temp = new RFC_CUSTOMER_GETCUSTOMER_T();
081: parameters.setCUSTOMER_T(temp);
082: RFC_CUSTOMER_GETResponseCUSTOMER_T response = null;
083:
084: //Invoke the Web Service
085: response = portType.RFC_CUSTOMER_GET(parameters)
086: .getCUSTOMER_T();
087:
088: //get the response data
089: BRFCKNA1[] data = response.getItem();
090:
091: for (int k = 0; k < data.length; k++) {
092: results.add(new Customer((BRFCKNA1) data[k]));
093: }
094:
095: return results;
096:
097: }
098:
099: /*
100: * This method searches for the customer with the
101: * given customer number. It return empty list when there
102: * are no results
103: */
104: public List findCustomerByNumber(String customerNumber)
105: throws RemoteException {
106:
107: ArrayList results = new ArrayList();
108: logger.fine("Finding Customer By Number");
109: logger.fine("Customer Number:" + customerNumber);
110:
111: //Create input parameters
112: RFC_CUSTOMER_GET parameters = new RFC_CUSTOMER_GET();
113: parameters.setKUNNR(customerNumber);
114: parameters.setNAME1("*");
115:
116: RFC_CUSTOMER_GETCUSTOMER_T temp = new RFC_CUSTOMER_GETCUSTOMER_T();
117: parameters.setCUSTOMER_T(temp);
118: RFC_CUSTOMER_GETResponseCUSTOMER_T response = null;
119:
120: //invoke the Web Service
121: response = portType.RFC_CUSTOMER_GET(parameters)
122: .getCUSTOMER_T();
123:
124: //get the response data
125: BRFCKNA1[] data = response.getItem();
126:
127: for (int k = 0; k < data.length; k++) {
128: results.add(new Customer((BRFCKNA1) data[k]));
129: }
130:
131: return results;
132:
133: }
134:
135: private static Stub createProxy() {
136: return (Stub) (new RFC_CUSTOMER_GETService_Impl()
137: .getRFC_CUSTOMER_GETPortType());
138: }
139:
140: public SAPUserConfig getUserConfig() {
141: return userConfig;
142: }
143: }
|