cancel
Showing results for 
Search instead for 
Did you mean: 

MDM Java API - Record.GetCheckoutStatus

Former Member
0 Kudos

Hi all, the code in this thread is used to CheckIn records that the user passes to the java app. The code checks if the records are checked out first by using the function getCheckoutStatus. The issue is that altough the record is checkedOut, the function is returning 0, meaning the record is not checked out.

I am using the Inquera sample repository for this test...

I think this is a bug, but want to check with all you first.


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.Record;
import com.sap.mdm.data.RecordResultSet;
import com.sap.mdm.data.RegionProperties;
import com.sap.mdm.data.ResultDefinition;
import com.sap.mdm.data.commands.CheckinRecordsCommand;
import com.sap.mdm.data.commands.RetrieveRecordsByValueCommand;
import com.sap.mdm.ids.RecordId;
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.schema.FieldProperties;
import com.sap.mdm.schema.TableProperties;
import com.sap.mdm.schema.commands.GetFieldListCommand;
import com.sap.mdm.schema.commands.GetTableListCommand;
import com.sap.mdm.server.DBMSType;
import com.sap.mdm.server.RepositoryIdentifier;
import com.sap.mdm.valuetypes.StringValue;

/**
 * 
 */

/**
 * @author I041263
 *
 */
public class mdm_check_in {

	/**
	 * @param args
	 */
    static ConnectionPool connections = null;
    static RepositoryIdentifier reposId = null;
	static CreateUserSessionCommand sessionCommand =  null;
	static String sessionId = null;
	static AuthenticateUserSessionCommand authCommand = null;
	static GetRepositoryRegionListCommand regionListCommand;
	static Boolean execute = false;
	
	public static void connect() {
		// create connection pool to a MDM server
	    String serverName = "LOCALHOST";

	    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 = "Inquera";
	    String dbmsName = "LOCALHOST";
	    reposId = new RepositoryIdentifier(repositoryName, dbmsName, DBMSType.MS_SQL);
	    
	    regionListCommand = new GetRepositoryRegionListCommand(connections);
        regionListCommand.setRepositoryIdentifier(reposId);
        try {
            regionListCommand.execute();
        } catch (CommandException e) {
            e.printStackTrace();
            return;
        }
        RegionProperties[] regions = regionListCommand.getRegions();

	    
	    // create a repository session
	    sessionCommand = new CreateUserSessionCommand(connections);
	    sessionCommand.setRepositoryIdentifier(reposId );
        sessionCommand.setDataRegion(regions[0]); // use the first region
	    
	    try {
	        sessionCommand.execute();
	    } catch (CommandException e) {
	        e.printStackTrace();
	        return;
	    }        
	    sessionId = sessionCommand.getUserSession();
	    
	    // authenticate the repository session
	    String userName = "admin";
	    String userPassword = "";
	    
	    authCommand = new AuthenticateUserSessionCommand(connections); 
	    authCommand.setSession(sessionId);
	    authCommand.setUserName(userName);
	    authCommand.setUserPassword(userPassword);
	    try {
	        authCommand.execute();
	    } catch (CommandException e) {
	        e.printStackTrace();
	        return;
	    }  

	}
	
	public static void disconnect() {
        // finally destroy the session
        DestroySessionCommand destroySessionCommand = new DestroySessionCommand(connections);
        destroySessionCommand.setSession(sessionId);
        try {
            destroySessionCommand.execute();
        } catch (CommandException e) {
            e.printStackTrace();
            return;
        }
		
		
		
		authCommand = null;
		sessionCommand = null;
		reposId = null;
		connections.freeUnused();
		connections = null;
	}
	

	
	public static void main(String[] args) {
		connect();
		
        GetTableListCommand tableListCommand = new GetTableListCommand(connections);
        tableListCommand.setSession(sessionId);
        try {
            tableListCommand.execute();
        } catch (CommandException e) {
            e.printStackTrace();
            return;
        }                

        TableId mainTable = null;
        TableProperties[] tables = tableListCommand.getTables();
        for (int i = 0; i < tables.length; i++) {
            if (tables<i>.getType() == TableProperties.MAIN)
                mainTable = tables<i>.getId();
        }
		
        // retrieve the list of fields from the main table
        // this is useful for resolving conflicting field names the new field might create
        GetFieldListCommand getFieldListCommand = new GetFieldListCommand(connections);
        getFieldListCommand.setSession(sessionId);
        getFieldListCommand.setTableId(mainTable);
        try {
            getFieldListCommand.execute();
        } catch (CommandException e) {
            e.printStackTrace();
            return;
        }
        
        // set up the field to create
        FieldProperties pnField = null;
        FieldProperties[] fields = getFieldListCommand.getFields(); 
        
        for (int i = 0; i < fields.length; i++) {
        	if (fields<i>.getCode().contentEquals("Part_Number")) {
        		pnField = fields<i>;
        	}        		
        }
        
        RetrieveRecordsByValueCommand rrbv = new RetrieveRecordsByValueCommand(connections);
		rrbv.setSession(sessionId);


		StringValue[] strVals = new StringValue[args.length];
		
		for (int i = 0; i < args.length; i++) {
			strVals<i> = new StringValue(args<i>.toString()); 
		}
		
        ResultDefinition rd = new ResultDefinition(mainTable);
        
		rrbv.setFieldId(pnField.getId());
		rrbv.setFieldValues(strVals);
		rrbv.setResultDefinition(rd);
		try {
			rrbv.execute();
		} catch (CommandException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		RecordResultSet recordResults = rrbv.getRecords();
		Record[] records = recordResults.getRecords();
		RecordId[] recID = new RecordId[records.length];
		
		for (int i = 0; i < records.length; i++) {
			if (records<i>.getCheckoutStatus() != Record.CheckoutStatus.NONE && records<i>.getCheckoutStatus() != Record.CheckoutStatus.UNDEFINED) {
				recID<i> = new RecordId(records<i>.getId());
				execute = true;
			}
				
		}
		
		if (execute) {
			CheckinRecordsCommand checkIn = new CheckinRecordsCommand(connections);
			checkIn.setSession(sessionId);
			checkIn.setTableId(mainTable);

			checkIn.setRecordIds(recID);
		
			try {
				checkIn.execute();
			} catch (CommandException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		disconnect();
		

	}

}

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Charles,

The reason could be it is returning the status of Original records instead of Checked out records. In addtion use the class RetrieveCheckoutRecordsByOriginalCommand which ask for the Original RecordId as the input and returns the Checkedout RecordIDs. You need to make changes in the for loop where you are checking the Checkedout status.

Try the above class and kindly update us...

Regards,

Jitesh Talreja

Answers (4)

Answers (4)

Former Member
0 Kudos

You read my mind. I am going to try that first yes.

Regards

Former Member
0 Kudos

I will investigate and comment back

Former Member
0 Kudos

Hi Charles,

I will suggest one thing, insteading of incorporating the above mentioned class directly in your class, try to see the output of it in separate program by printing the status of all the records. Before executing the program dont forget to check out few records.

Regards,

Jitesh Talreja

Former Member
0 Kudos

I am on MDM 5.563.90 which is the latest release on the portal.

Regards

Former Member
0 Kudos

Which version of MDM are you using? Because the bug is fixed in the latest version of MDM.