001: /**
002: * $Id: NamefinderManager.java,v 1.2 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.namefinder;
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.namefinder.*;
022:
023: public class NamefinderManager implements SAPPortletConstants {
024:
025: private static Logger logger = Logger.getLogger(LOGGER_NAMESPACE);
026: private BAPI_EMPLOYEE_GETDATAPortType portType = null;
027: private SAPUserConfig userConfig = null;
028:
029: /** Creates a new instance of DirectReportManager */
030: public NamefinderManager() {
031: }
032:
033: /*
034: * This method read the sap configuration details and initializes the
035: * web service stub
036: */
037: public void init(SAPUserConfig userConfig, String endPointAddress) {
038:
039: //logger.fine("Init of SalesOrderManager");
040:
041: this .userConfig = userConfig;
042: //String endPointAddress = SAPConfiguration.getEndpointAddress();
043:
044: String userName = userConfig.getUserName();
045: String userPass = userConfig.getUserPassword();
046:
047: Stub stub = createProxy();
048: stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,
049: endPointAddress);
050: stub._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY,
051: userName);
052: stub._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY,
053: userPass);
054: portType = (BAPI_EMPLOYEE_GETDATAPortType) stub;
055: }
056:
057: // List of NameFinderDetail
058: public List getDetails(NamefinderDetail detail) {
059:
060: BAPI_EMPLOYEE_GETDATA parameters = new BAPI_EMPLOYEE_GETDATA();
061: parameters.setFSTNAME_M(detail.getFirstName());
062: parameters.setLASTNAME_M(detail.getLastName());
063: parameters.setEMPLOYEE_ID(detail.getEmployeeNumber());
064: parameters.setBLDING_NO(detail.getBuildingNumber());
065: parameters.setROOM_NO(detail.getRoomNumber());
066: parameters.setEXTENSION(detail.getExtension());
067:
068: BAPI_EMPLOYEE_GETDATAARCHIVELINK temp1 = new BAPI_EMPLOYEE_GETDATAARCHIVELINK();
069: BAPI_EMPLOYEE_GETDATACOMMUNICATION temp2 = new BAPI_EMPLOYEE_GETDATACOMMUNICATION();
070: BAPI_EMPLOYEE_GETDATAINTERNAL_CONTROL temp3 = new BAPI_EMPLOYEE_GETDATAINTERNAL_CONTROL();
071: BAPI_EMPLOYEE_GETDATAORG_ASSIGNMENT temp4 = new BAPI_EMPLOYEE_GETDATAORG_ASSIGNMENT();
072: BAPI_EMPLOYEE_GETDATAPERSONAL_DATA temp5 = new BAPI_EMPLOYEE_GETDATAPERSONAL_DATA();
073:
074: parameters.setARCHIVELINK(temp1);
075: parameters.setCOMMUNICATION(temp2);
076: parameters.setINTERNAL_CONTROL(temp3);
077: parameters.setORG_ASSIGNMENT(temp4);
078: parameters.setPERSONAL_DATA(temp5);
079:
080: BAPI_EMPLOYEE_GETDATAResponse response = null;
081:
082: //invoke the Web Service
083: try {
084:
085: response = portType.BAPI_EMPLOYEE_GETDATA(parameters);
086:
087: } catch (Exception excp) {
088: logger
089: .severe("SAPManagerViewPortlet failed to execute search");
090: logger.severe(excp.getMessage());
091: return null;
092: }
093:
094: ArrayList list = new ArrayList();
095: BAPIP0001B[] orgArray = response.getORG_ASSIGNMENT().getItem();
096: BAPIP0002B[] personalDataArray = response.getPERSONAL_DATA()
097: .getItem();
098: BAPIP0032B[] internalControlData = response
099: .getINTERNAL_CONTROL().getItem();
100: BAPIP0105B[] communicationData = response.getCOMMUNICATION()
101: .getItem();
102:
103: for (int i = 0; i < orgArray.length; i++) {
104: NamefinderDetail newDetailRecord = new NamefinderDetail();
105: newDetailRecord.setEmployeeNumber(orgArray[i].getPERNO());
106: newDetailRecord.setOrgUnitText(orgArray[i].getORGTXT());
107: newDetailRecord.setRoleText(orgArray[i].getPOSTXT());
108: // Iterate through all personal Data to get records
109: for (int j = 0; j < personalDataArray.length; j++) {
110: if (personalDataArray[j].getPERNO().equals(
111: orgArray[i].getPERNO())) {
112: newDetailRecord.setFirstName(personalDataArray[j]
113: .getFIRSTNAME());
114: newDetailRecord.setLastName(personalDataArray[j]
115: .getLAST_NAME());
116: break;
117: }
118: }
119: for (int j = 0; j < internalControlData.length; j++) {
120: if (internalControlData[j].getPERNO().equals(
121: orgArray[i].getPERNO())) {
122: newDetailRecord
123: .setBuildingNumber(internalControlData[j]
124: .getBLDING_NO());
125: newDetailRecord
126: .setRoomNumber(internalControlData[j]
127: .getROOM_NO());
128: newDetailRecord.setExtension(internalControlData[j]
129: .getPHONENO1());
130: break;
131: }
132: }
133:
134: for (int j = 0; j < internalControlData.length; j++) {
135: if (communicationData[j].getPERNO().equals(
136: orgArray[i].getPERNO())) {
137: String email = communicationData[j].getUSRID_LONG();
138: if (email != null && !email.trim().equals("")) {
139: newDetailRecord.setEmailAddress(email);
140: }
141: }
142: }
143: for (int j = 0; j < internalControlData.length; j++) {
144:
145: }
146: list.add(newDetailRecord);
147: }
148:
149: return list;
150: }
151:
152: private static Stub createProxy() {
153: return (Stub) (new BAPI_EMPLOYEE_GETDATAService_Impl()
154: .getBAPI_EMPLOYEE_GETDATAPortType());
155: }
156:
157: public SAPUserConfig getUserConfig() {
158: return userConfig;
159: }
160: }
|