Code to Get List of Validation in a Table

Following code snippet finds out the list of Validation from a Table.

package com.sap.infosys.mdm.validationcheck;

import com.sap.mdm.commands.AuthenticateUserSessionCommand;
import com.sap.mdm.commands.CommandException;
import com.sap.mdm.commands.CreateUserSessionCommand;
import com.sap.mdm.commands.DestroySessionCommand;
import com.sap.mdm.commands.GetRepositoryRegionListCommand;
import com.sap.mdm.data.RegionProperties;
import com.sap.mdm.ids.TableId;
import com.sap.mdm.net.ConnectionException;
import com.sap.mdm.net.ConnectionPool;
import com.sap.mdm.net.ConnectionPoolFactory;
import com.sap.mdm.server.DBMSType;
import com.sap.mdm.server.RepositoryIdentifier;
import com.sap.mdm.validation.ValidationProperties;
import com.sap.mdm.validation.ValidationPropertiesResult;
import com.sap.mdm.validation.commands.RetrieveValidationsCommand;


public class GetListOfValidations {     public static void main(String[] args) {         // create connection pool to a MDM server         String serverName = " ";         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 = "Vendor1";         String dbmsName = " ";         RepositoryIdentifier reposId =             new RepositoryIdentifier(repositoryName, dbmsName, DBMSType.MS_SQL);         // 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 = "mdm";         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());         }     }

}

SAP Developer Network Latest Updates