Skip to Content

 I am new to the MDM Java API. For one of the existing project I was asked to explore the new MDM Java API. I do not have any experience with the earlier MDM4J but still I was able to understand and explore the new MDM Java API. I think this API is excellent and I am almost fallen in love with it. The best part I like about this API is the Commands. Initially it took me time to understand the concept but very soon it was all clear. With this blog I would like to share my knowledge about how to work with Commands.  Also in this blog you will see an example of Validation Command.

 

 

Why you need a Command? What is a Command?

 

I command the MDM Java API to get me the list of Validations …..  /<br />package demo.validation;</p><p style=”margin: 0cm 0cm 0pt” class=”MsoNormal”>import com.sap.mdm.commands.AuthenticateUserSessionCommand;<br />import com.sap.mdm.commands.CommandException;<br />import com.sap.mdm.commands.CreateUserSessionCommand;<br />import com.sap.mdm.commands.GetRepositoryRegionListCommand;<br />import com.sap.mdm.data.RegionProperties;<br />import com.sap.mdm.ids.TableId;<br />import com.sap.mdm.net.ConnectionException;<br />import com.sap.mdm.net.ConnectionPool;<br />import com.sap.mdm.net.ConnectionPoolFactory;<br />import com.sap.mdm.server.DBMSType;<br />import com.sap.mdm.server.RepositoryIdentifier;<br />import com.sap.mdm.validation.ValidationProperties;<br />import com.sap.mdm.validation.ValidationPropertiesResult;<br />import com.sap.mdm.validation.commands.RetrieveValidationsCommand;</p><p style=”margin: 0cm 0cm 0pt” class=”MsoNormal”>/*
 *
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class GetListOfValidations {

 public static void main(String[] args) {
  // create connection pool to a MDM server
  String serverName = “LOCALHOST”;
  ConnectionPool connections = null;
  try {
   connections = ConnectionPoolFactory.getInstance(serverName);
  } catch (ConnectionException e) {
   e.printStackTrace();
   return;
  }

  // specify the repository to use
  // alternatively, a repository identifier can be obtain from the GetMountedRepositoryListCommand
  String repositoryName = “INQDemo”;
  String dbmsName = “localhost”;
  RepositoryIdentifier reposId =
   new RepositoryIdentifier(repositoryName, dbmsName, DBMSType.ORACLE);

  // get list of available regions for the repository
  GetRepositoryRegionListCommand regionListCommand =
   new GetRepositoryRegionListCommand(connections);
  regionListCommand.setRepositoryIdentifier(reposId);
  try {
   regionListCommand.execute();
  } catch (CommandException e) {
   e.printStackTrace();
   return;
  }
  RegionProperties[] regions = regionListCommand.getRegions();

  // create a user session
  CreateUserSessionCommand sessionCommand =
   new CreateUserSessionCommand(connections);
  sessionCommand.setRepositoryIdentifier(reposId);
  sessionCommand.setDataRegion(regions[0]); // use the first region
  try {
   sessionCommand.execute();
  } catch (CommandException e) {
   e.printStackTrace();
   return;
  }
  String sessionId = sessionCommand.getUserSession();

  // authenticate the user session
  String userName = “admin”;
  String userPassword = “admin”;
  AuthenticateUserSessionCommand authCommand =
   new AuthenticateUserSessionCommand(connections);
  authCommand.setSession(sessionId);
  authCommand.setUserName(userName);
  authCommand.setUserPassword(userPassword);
  try {
   authCommand.execute();
  } catch (CommandException e) {
   e.printStackTrace();
   return;
  }

  // the main table, hard-coded
  TableId mainTableId = new TableId(1);

  // Get the list of validations

  RetrieveValidationsCommand objRtvVldCmd =
   new RetrieveValidationsCommand(connections);
  // set the user session
  objRtvVldCmd.setSession(sessionId);
  // get validation for the following tables.
  objRtvVldCmd.setTableId(mainTableId);

  try {
   objRtvVldCmd.execute();

  } catch (CommandException e) {
   e.printStackTrace();
   return;
  }

  ValidationPropertiesResult objVldPropRslt =
   objRtvVldCmd.getValidationPropertiesResult();

  ValidationProperties[] validations = objVldPropRslt.getValidations();

  
  //disply –> Validation ID | error/warning message | Validation Name
  for (int i = 0; i < validations.length; i++) {
   
   System.out.println(
    validations[i].getId()
     + ” | “
     + validations[i].getMessage()
     + ” | “
     + validations[i].getName());
  }

 }
}

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. G. Jansen
    Finally some straight forward information on how to use the new MDM API without having to try, test and restart the whole thing again. Thanks!
    (0) 
  2. Shruti Shah
    Hi Vijendra,
    Thanks a lot for such a nice blog.

    But I am having a problem in finding this “RetrieveValidationsCommand” class. I am not able to find this package “com.sap.mdm.validation ” which contains this class.

    I am using MDM 5.5 SP04 version.
    I have added following Jars in my project MDM4J.jar
    mdm-admin.jar
    mdm-common.jar
    mdm-core.jar
    mdm-data.jar
    mdm-protocol.jar

    Can u just tell me in which jar i will be able to find out the these packages?

    Thanks in Advance.
    Shruti.

    (0) 
    1. Vijendra Singh Bhanot Post author
      Hi Shruti

      The Jar’s that you have included in your project is right. Only thing is that I have worked on MDM 5.5 SP6 Patch 0.

      This class is present in mdm-data.jar

      Good Luck
      Vijendra S Bhanot

      (0) 
  3. Anilkumar Vippagunta
    Hi,

    I am getting the following exception while establing the connection ti the server .

    com.sap.mdm.net.ConnectionException: Could not open minimum connections.

    What could be the reason.

    As my server is not LocalHost ,I am giving the server name as ….serverName = “Host:Port”;

    Am I missing something here ?

    THanks,Anil

    (0) 

Leave a Reply