Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
kousik
Explorer
0 Kudos

Applies to:

SAP MDM 7.1 SP04

MDM Java API

SAP NetWeaver 7.0

Summary

This article is about a JAVA EE framework for building an integrated application on SAP NetWeaver Java WebDynpro utilizing MDM Java API. The Enterprise level Java Framework customizes the MDM Java API framework written by Richard LeBlanc of SAP, and adds few more layers to it. This gives a road map for creating a Java WebDynpro application which can be used for providing SAP MDM CRUD functionalities in a large project in distributed environment.

Author(s):    Kousik Mukherjee

Company:    HCL AXON

Created on:  17 January 2012

Author Bio

Kousik Mukherjee is currently working as Technical Specialist with HCL AXON, India at SAP Service Division. He is having 5 years of experience in SAP NetWeaver platform and ECC integration in heterogeneous areas like MDM and EP.

 

Table of Contents

The MDM Picture. 3

The Need for Master Data Management through Enterprise Portal 3

The Framework Architecture. 4

The Understanding of the Flow. 4

Here, we will try to understand each layer by sighting examples of the codes. 4

The WD View. 4

WD Button Action: View.. 4

WD Custom Controller: CustomsController 5

The DTO.. 5

Custom DTO.. 5

The Business Delegate. 6

Business Delegate Factory. 6

Item Create Delegate. 6

Item Create Delegate Impl 6

Service Locator 7

The EJB. 8

Item Creation Stateless Session Bean Home. 8

Item Creation Stateless Session Bean. 8

Item Creation Stateless Session Bean Class. 8

The DAO.. 8

DAO Factory. 8

Item Create DAO.. 9

Item Create DAO Impl 9

The MDM Java API 10

MDM Connection Manager 10

Server 11

Server Impl 11

  1. Repository. 12

Repository Impl 12

  1. Session. 13

Session Impl 13

The End Result 14

Copyright 16

 

The MDM Picture

All businesses, no matter what their size, rely on data to record and analyze business activity. It is the lifeblood of any business operation. Data enters the enterprise during specific process activities, either through the keyboard, via electronic messages or via electronic files. It then flows throughout the enterprise to support every process activity from registering new customers and sales order taking to supplier procurement, product fulfillment, product delivery, invoicing and payment collection.  There are two broad categories of structured data that any business relies on.

  1. Master Data
  2. Transaction Data

    

Master data is simply the data associated with core business entities such as customer, employee, supplier, product, partner, asset, etc. This data can reside in many different systems.

Transaction data, on the other hand, is very simple and straight forward. This is the recording of business transactions such as purchase orders in manufacturing, leave applications in HR and credit card payments in banking.

There are many reasons why master data management is needed in business. New business challenges such as globalization, mergers and acquisitions, risk, compliance, customer loyalty, supply chain complexity and costcutting would all benefit from having master data management in place.

The Need for Master Data Management through Enterprise Portal

When subsets of master data exist in multiple operational systems, it is not uncommon to see that data being independently maintained by each of those systems. When this happens, it is obvious that multiple data entry applications can cause problems that affect business operations, business performance and customer satisfaction. These problems include:

  • Data conflicts
  • Confusion when duplicate master data does not agree
  • Process delays and process defects caused by data errors
  • Inability to respond when changes to master data require prompt business action
  • Additional operational costs to solve problems caused by data conflicts

In order to counter these problems the SAP MDM system should provide the capabilities of easy access through enterprise portal with respect to its management of data associated with specific master data entities like customer, product, employee, etc.

The Framework Architecture

A Java WebDynpro Application can be suited to integrate the CRUD operations in SAP MDM with SAP EP. The Java Framework on above the MDM Java API comprises of 6 layers as shown below.

Note: This 3 tier architecture caters to a large project, where EJB and DAO is used with a view that Business logic may reside in a separate system, and View (WD application) and Data (MDM system) may reside in different systems. The italics signify the interfaces.

The Understanding of the Flow

Here, we will try to understand each layer by sighting examples of the codes.

The WD View

WD Button Action: View

This is an example of a code in the ItemCreateView:

  //@@begin javadoc:onActionSave_Customs(ServerEvent)

  /** Declared validating event handler. */

  //@@end

  public void onActionSave_Customs(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

  {

    //@@begin onActionSave_Customs(ServerEvent)

    wdThis.wdGetCustomsControllerController().saveCustomsData();

    //@@end

  }

WD Custom Controller: CustomsController

This is an example of a code in the CustomsController class:

  //@@begin javadoc:saveCustomsData()

  /** Declared method. */

  //@@end

  public void saveCustomsData( )

  {

    //@@begin saveCustomsData()

   

   String portalUserName = wdContext.currentContextElement().getPortalUserName();

   String itemNumber = wdContext.currentContextElement().getItemNumber();

   String selectedSendToERP = wdContext.currentContextElement().getSelectedSendToERP();

  

   CustomsDTO customsDTO = new CustomsDTO();

         

   customsDTO.setL_CountryOfOrigin(wdContext.currentCustomsElement().getL_CountryOfOriginAndDesc());

   customsDTO.setL_CustomsRemark(wdContext.currentCustomsElement().getL_CustomsRemark());  

   customsDTO.setL_MilitaryCategoryNumber(wdContext.currentCustomsElement().getL_MilitaryCategoryNumber());

   try {

      BusinessDelegateFactory.getInstance().getItemCreationDelegate().updateCustomsData(portalUserName,itemNumber,customsDTO,selectedSendToERP);

   } catch (Exception e) {

          // TODO Auto-generated catch block

          wdComponentAPI.getMessageManager().raiseException(e.toString(),false);

          e.printStackTrace();

   }

    //@@end

  }

 

The DTO

Custom DTO

This is an example of a Data Transfer Object class:

public class CustomsDTO implements Serializable {

  

   private String l_CountryOfOrigin = "";

   private String l_CustomsRemark = "";

   private String l_MilitaryCategoryNumber = "";

      public String getL_CountryOfOrigin() {

            return l_CountryOfOrigin;

      }

   public String getL_CustomsRemark() {

          return l_CustomsRemark;

   }

   public String getL_MilitaryCategoryNumber() {

          return l_MilitaryCategoryNumber;

   }

   public void setL_CountryOfOrigin(String string) {

          l_CountryOfOrigin = string;

   }

   public void setL_CustomsRemark(String string) {

          l_CustomsRemark = string;

   }

   public void setL_MilitaryCategoryNumber(String string) {

          l_MilitaryCategoryNumber = string;

   }

  }

The Business Delegate

Business Delegate Factory

This is an example of a Business Delegate Factory for delegating the flow to Item Creation:

public final class BusinessDelegateFactory {

  

   private static BusinessDelegateFactory delegateFactory = null;

   private BusinessDelegateFactory() {

   }     

   public static BusinessDelegateFactory getInstance() {

          if (delegateFactory == null) {

                delegateFactory = new BusinessDelegateFactory();

          }

          return delegateFactory;

   }     

   public ItemCreationDelegate getItemCreationDelegate()

          throws Exception {

          return new ItemCreationDelegateImpl();

   }

Item Create Delegate

This is an example of an Item Create Delegate Interface:

public interface ItemCreationDelegate {

   public void updateCustomsData(String mdmUserName, String itemNumber, CustomsDTO customsDTO, String sendToERP)throws Exception;

}

Item Create Delegate Impl

This is an example of an Item Create Delegate Implementation class:

public class ItemCreationDelegateImpl implements ItemCreationDelegate {

   

   public void updateCustomsData(String mdmUserName, String itemNumber, CustomsDTO customsDTO, String sendToERP)throws Exception

    {

   ServiceLocator.getInstance().getItemCreationSLSB().updateCustomsData(mdmUserName, itemNumber, customsDTO,sendToERP);

    }

}

Service Locator

This is an example of a Service Locator class:

public final class ServiceLocator {

  

   private Context jndiContext;

   // Local home and remote home stubs are cached against their JNDI names.

   private Map localHomeCache;

   private Map remoteHomeCache;

   private boolean lookupRemoteStub = true;

   private static ServiceLocator serviceLocator;

   private static final String DEFAULT_JNDI_HOST = "xxxxxx";

   private static final String DEFAULT_JNDI_PORT = "99999";

   private static final String INITIAL_CONTEXT_FACTORY =

          "com.sap.engine.services.jndi.InitialContextFactoryImpl";

   private ServiceLocator() throws ServiceLocatorException {

         

          try { PropertyLoader loader = PropertyLoader.getInstance();

               

                //String jndiHost = DEFAULT_JNDI_HOST;

                String jndiHost =  loader.getProperty("JNDI_HOST",DEFAULT_JNDI_HOST);

                //String jndiPort = DEFAULT_JNDI_PORT;

                String jndiPort = loader.getProperty("JNDI_PORT", DEFAULT_JNDI_PORT);

                String jndiURL = jndiHost + ":" + jndiPort;                         

               

                String lookupRemote = loader.getProperty("LOOKUP_REMOTE", "false");

                lookupRemoteStub = Boolean.valueOf(lookupRemote).booleanValue();

                                    

                Properties props = new Properties();

                props.put(Context.PROVIDER_URL, jndiURL);

                props.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);

                if(lookupRemoteStub)

                       jndiContext = new InitialContext(props);

                else  

                       jndiContext = new InitialContext();

                                    

                localHomeCache = new HashMap();

                remoteHomeCache = new HashMap();

               

          } catch (Exception exp) {

               

                throw new ServiceLocatorException(

                       "Failed to perform JNDI lookup.", exp);

          }

   }

   public static ServiceLocator getInstance() throws ServiceLocatorException {

         

          if (serviceLocator == null) {

                serviceLocator = new ServiceLocator();

          }

          return serviceLocator;

   }

}

The EJB

Item Creation Stateless Session Bean Home

This is an example of an Item Creation Stateless Session Bean Home interface:

public interface ItemCreationSLSBHome extends EJBHome {

   /**

    * Create Method.

    */

   public ItemCreationSLSB create() throws CreateException, RemoteException;

}

Item Creation Stateless Session Bean

This is an example of an Item Creation Stateless Session Bean interface:

public interface ItemCreationSLSB extends EJBObject {

   /**

    * Business Method.

    */

public void updateCustomsData(String mdmUserName, String itemNumber, CustomsDTO customsDTO, String sendToERP)throws Exception;

  

}

Item Creation Stateless Session Bean Class

This is an example of an Item Creation Stateless Session Bean class:

public class ItemCreationSLSBBean implements SessionBean {     

  

   public void updateCustomsData(String mdmUserName, String itemNumber, CustomsDTO customsDTO, String sendToERP)throws Exception

   {

   DAOFactory.getInstance().getItemCreateDAO().updateCustomsData(mdmUserName, itemNumber,customsDTO,sendToERP);

   }     

}

The DAO

DAO Factory

This is an example of a DAO Factory for moving the control to Item Create DAO:

       public final class DAOFactory {

           private static DAOFactory instance;

           private DAOFactory() {

           }

           public static DAOFactory getInstance() {

              if (instance == null)

                     instance = new DAOFactory();

              return instance;

           }

           public ItemCreateDAO getItemCreateDAO() {

                 return new ItemCreateDAOImpl();

           }

       }

Item Create DAO

This is an example of an Item Create Data Access Object inteface:

public interface ItemCreateDAO {

  

   public void updateCustomsData(String mdmUserName, String itemNumber, CustomsDTO customsDTO, String sendToERP)throws Exception;  

}

Item Create DAO Impl

This is an example of an Item Create DAO Implementation class:

public class ItemCreateDAOImpl implements ItemCreateDAO {       

    private RepositorySchema repositorySchema = null;

    private UserSessionContext userSessionContext = null;

    private RepositorySessionContext repositorySessionContext = null;

    private String lookupFlatTableName = "";

    private String keyFieldName = "";

    private String valueFieldName = "";    

public void updateCustomsData(String mdmUserName, String itemNumber, CustomsDTO customsDTO, String sendToERP) throws Exception {

          // TODO Auto-generated method stub

               

          String mainTableName = MDMSchema.Items.TABLE;

          String searchFieldName = MDMSchema.Items.ITEM_NUMBER;

          String searchFieldValue = itemNumber;

          String searchFieldConstraint = "EQUALS";

          String[] selectedMainTableFieldNameArray = {

                                            MDMSchema.Items.LOCAL_DATA,

                                            MDMSchema.Items.INTRASTAT_ITEM,                                                      MDMSchema.Items.SUPPLIER_PRICE_LIST_DATA

                                               };

try{     

          SearchProgram searchProgram = FieldSearchProgram.TEXT;

          TableSchema tableSchema = repositorySchema.getTableSchema(mainTableName);

          Record[]  records = searchProgram.execute(repositorySchema, userSessionContext, tableSchema, mainTableName, searchMDMRecordDetails);

          FieldValuePair[] fieldValuePairs = new FieldValuePair[3];

          if(records!=null)

          {

                TableSchema mainTableSchema = repositorySchema.getTableSchema(mainTableName);

                TableSchema lookUpTableSchema = null;

                QualifiedLookupValue qlv = null;

                QualifiedLinkValue[] links = null;

                StringValue stringValue = null;                

                records[0] = dataProgram.getRecordByID(userSessionContext,mainTableSchema,records[0].getId());

                             

                fieldValuePair = new FieldValuePair(mainTableSchema.getFieldId(MDMSchema.Items.INTRASTAT_ITEM),new BooleanValue(customsDTO.isG_IntrastatItem()));

                fieldValuePairs[0] = fieldValuePair;

                             

                qlv = (QualifiedLookupValue)records[0].getFieldValue(mainTableSchema.getFieldId(MDMSchema.Items.LOCAL_DATA));

                links = qlv.getQualifiedLinks();

}

The MDM Java API

MDM Connection Manager

This is an example of a MDM Connection Manager class:

public class MDMConnectionManager {

               

   private static String MDM_SERVER_HOST = "xxxxxxxx";

   private static String MDM_REPOSITORY_NAME ="xxxxxxxx";

   private static String MDM_REGION_NAME = "English [US]";

   private static Repository[] repositories = null;

   private static Repository repository = null;

   private static RegionProperties regionProperties = null;

   private static RepositorySchema repositorySchema = null;

 

  

   public static Repository getRepository(String userName) throws Exception {

   Server server = Server.getInstance(MDM_SERVER_HOST);

   repositories = server.getRepository();

  

   for (int i = 0, j = repositories.length; i < j; i++) {

          if (repositories[i].getIdentifier().getName().equals(MDM_REPOSITORY_NAME)) {

          repository = repositories[i];

    }

    }

   RegionProperties[] regions = repository.getRegions();        

   RegionProperties region = null;

   for (int i = 0, j = regions.length; i < j; i++) {

          if (regions[i].getName().equals(MDM_REGION_NAME)) {

                region = regions[i];

          }

   }

   repository.login(region, userName);

   return repository;

   }

}

Server

This is an example of a Server Abstract class:

abstract public class Server {

   protected String hostName;

   /**

    * Gets a server using the specified host name.

    *

    * @param hostName - the host name of the MDM Server

    * @return a server for the given host name

    */

   static public Server getInstance(String hostName) {

         

          Server server = new ServerImpl(hostName);

          return server;            

   }

Server Impl

This is an example of a Server Implementation class:

class ServerImpl extends Server {

   private Repository[]  repositories;

   ServerImpl(String hostName) {

         

          this.hostName = hostName;

         

          loadRepository();         

   }

  

   /*

    * Loads all mounted repositories for this server.

    */   

   private void loadRepository() {                

         

          GetMountedRepositoryListCommand cmd = new GetMountedRepositoryListCommand(getConnection());

          try {

                cmd.execute();

          } catch (CommandException e) {

                e.printStackTrace();

          }

          RepositoryIdentifier[] repIdentifiers = cmd.getRepositories();

         

          repositories = new Repository[repIdentifiers.length];

         

          for(int i=0, j=repIdentifiers.length; i<j; i++) {

               

                repositories[i] = new RepositoryImpl(this, repIdentifiers[i]);

                      

          }                   

   }     

Repository

This is an example of a Repository interface:

public interface Repository {       

   public void login(RegionProperties region, String user);

   public void login(RegionProperties region, String user,String password );

  

   /**

    * Return the server this repository belongs to.

    */

   public Server getServer();

         

   /**

    * Returns the schema for this repository.

    *

    * @see com.sap.mdm.schema.RepositorySchema

    */

   public RepositorySchema getSchema();

  

   /**

    * Returns the session for this repository.

    *

    * @see com.sap.nw.mdm.rig.session.Session

    */

   public Session getSession();     

}

Repository Impl

This is an example of a Repository Implementation class:

class RepositoryImpl implements Repository{

  

   private Server server;

  

   private RepositoryIdentifier repositoryIdentifier;

         

   RepositoryImpl(Server server, RepositoryIdentifier repositoryIdentifier) {

         

          this.server = server;            

          this.repositoryIdentifier = repositoryIdentifier;            

   }

         

   public Server getServer() {      

          return server;            

   }

  

   private Session session;

   public void login(RegionProperties region, String user) {

         

          session = new SessionImpl(server.getConnection(), repositoryIdentifier,

                                                                region, user);                                                        

          this.region = region;            

   }

  

   public void login(RegionProperties region, String user,String password) {

         

          session = new SessionImpl(server.getConnection(), repositoryIdentifier,

                                                          region, user,password);

                                                         

                this.region = region;            

          }

   public Session getSession() {

         

          return session;           

   }     

}

Session

This is an example of a Session interface:

public interface Session {

   public String getUserSession();  

  

   public String getRepositorySession();   

  

   public void destroy();

}

Session Impl

This is an example of a Session Implementation class:

class SessionImpl implements Session{

   private String userSession;

   private String repositorySession;

   private ConnectionAccessor connection;

  

   SessionImpl(ConnectionAccessor connection, RepositoryIdentifier repository, RegionProperties region, String user) { 

         

          this.connection = connection;           

          repositorySession = getRepositorySession(connection, repository);

         

          authenticateRepositorySession(connection, repositorySession, user);       

          userSession = getUserSession(connection, repository, region);       

          authenticateUserSession(connection, userSession, user);                                    

   }

}

The End Result

Now, it is obvious that since we have spent so much of our effort in understanding and building an EP & MDM integrated application, it is important to see the end result. Using our framework, we can develop a WebDynpro Application which will Search, Modify, Add, Remove (CRUD) data from a SAP MDM 7.1 Repository.

Related Content

SAP NetWeaver MDM Java API

Java Development

WebDynpro Java

 

Copyright

© Copyright 2012 SAP AG. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice.

Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.

IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation.

Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.

Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries.

Oracle is a registered trademark of Oracle Corporation.

UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.

Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc.

HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology.

Java is a registered trademark of Oracle Corporation.

JavaScript is a registered trademark of Oracle Corporation, used under license for technology invented and implemented by Netscape.

SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries.

Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company.

All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.

These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.

Labels in this area