on 06-02-2009 2:00 PM
Hi,
I am trying to create Records in MDM using Java API.
There are two methods setFieldValue and setAttribute.
To use setFieldValue(), I need to know the FildId fotr the field.
Now, what is FieldId and how could I retrive it?
Is it justiciable to use FieldId fdid = repositorySchema.getFieldId(String, String);?
What to give as the two String parameters?
Regards
Kaushik Banerjee
Hi Kaushik,
After setting the fields value, you need to execute the CreateRecordCommand. Check the below link
Regards,
Jitesh Talreja
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
MDM Java API Record Creation Successfully done
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I am reopening same question.
Please look at the code below.
Record rd = RecordFactory.createEmptyRecord(tableId);
FieldId fdid1 = repositorySchema.getFieldId("MDM_BUSINESS_PARTNERS","MDM_MDM_PARTNER_ID");
FieldId fdid2 = repositorySchema.getFieldId("MDM_BUSINESS_PARTNERS","MDM_PARTNER_NUMBER");
rd.setFieldValue(fdid1,new IntegerValue(86783));
rd.setFieldValue(fdid2,new IntegerValue(86783));
rd.setFieldValue(fdid2,new IntegerValue(86783))};
CreateRecordCommand cd = new CreateRecordCommand(connections);
cd.execute();
Just look at the last two lines.
Are they positioned at right locations.
Also, is it advisable to use rd.setFieldValue() or to use MdmValues[]{} ?
Even if the code is ruuning but there is no record creation in MDM.
Regards
Kaushik Banerjee
+91-9836855466
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kaushik,
You have placed the code at right location, but it seems to be incomplete. You need to add the below lines after creating the CreateRecordsCommand object and before execution.
cd.setRecord(rd); // attach the new record that you created
cd.setSession(USER_SESSION_ID); // Set the user session ID
Let me know if this esolves the issue.
Cheers,
Arafat
Hi Kaushik,
You can use the below constructor as well
public CreateRecordCommand(UserSessionContext ctx)
Just pass the user session object and then execute the command.
Always put the execute command in Try-Catch block so that you can check the exact error if any exception has occured.
Regards,
Jitesh Talreja
Hi,
There is no exception.
But the below code is not giving the desired result.
No record being created in kaushikb repository.
Record rd = RecordFactory.createEmptyRecord(tableId);
FieldId fdid1 = repositorySchema.getFieldId("MDM_BUSINESS_PARTNERS","MDM_MDM_PARTNER_ID");
FieldId fdid2 = repositorySchema.getFieldId("MDM_BUSINESS_PARTNERS","MDM_PARTNER_NUMBER");
//MdmValue mv = MdmValueFactory.createIntegerValue("200000");
//Record.setFieldValue(FieldId, MdmValue);
rd.setFieldValue(fdid1,new IntegerValue(86783));
rd.setFieldValue(fdid2,new IntegerValue(86783));
//MdmValue[]={ rd.setFieldValue(fdid1,new IntegerValue(86783)), rd.setFieldValue(fdid2,new IntegerValue(86783))};
UserSessionContext ctx= new UserSessionContext(serverName,reposId,userName);
CreateRecordCommand cd = new CreateRecordCommand(ctx);
cd.setRecord(rd);
cd.setSession(sessionId);
try{
cd.execute();
}
catch(Exception e)
{
e.printStackTrace();
wdComponentAPI.getMessageManager().reportWarning("Failure");
}
Regards
Kaushik Banerjee
Kaushik, follow a logical approach to it, which is pretty simple.
1. Create an instance of record.
2. Get all the field Ids and field types(you should know the field types)
3. Set the field values as respective MDM Values. you will have to convert all the values to MDM Values to be able to set to the fields. I see this is where you might be doing wrong.
4. Set all the fields to Record using the respective Field Ids.
5. Create an instance of CreateRecordCommand using the connection pool / connection accessor command.
6. Create and Authenticate Your user session and set it to the command. If it is already available, use it and set it to the command.
7. set the record to the command.
8. Execute the command and get the record Id from the command.
If you want the complete code, i can send you that but you should try it yourself.
Regards,
Nitin
Hi Jitesh,
Yes you are right,.
Now, the code have changed.
Record rd = RecordFactory.createEmptyRecord(tableId);
//FieldId fdid1 = repositorySchema.getFieldId("MDM_BUSINESS_PARTNERS","MDM_MDM_PARTNER_ID");
FieldId fdid2 = repositorySchema.getFieldId("MDM_BUSINESS_PARTNERS","MDM_PARTNER_NUMBER");
//MdmValue mv = MdmValueFactory.createIntegerValue("200000");
//Record.setFieldValue(FieldId, MdmValue);
//rd.setFieldValue(fdid1,new IntegerValue(86783));
rd.setFieldValue(fdid2,new StringValue("86783"));
//MdmValue[]={ rd.setFieldValue(fdid1,new IntegerValue(86783)), rd.setFieldValue(fdid2,new IntegerValue(86783))};
UserSessionContext ctx= new UserSessionContext(serverName,reposId,userName);
CreateRecordCommand cd = new CreateRecordCommand(ctx);
cd.setRecord(rd);
cd.setSession(sessionId);
try{
cd.execute();
}
catch(Exception e)
{
e.printStackTrace();
wdComponentAPI.getMessageManager().reportWarning("Failure");
}
Regards
Kaushik Banerjee
Hi,
Authentication is done alreafy.
This type of problem happens when you leave the code for several months andf again
start coding.
I am pasting the full code.
I have to check what is going wrong.
It is not creating any record but I am able to login to my repository using below code.
public void getRepositoryConnection( )
{
//@@begin getRepositoryConnection()
//create connection pool to a MDM server
String serverName = "kolapon.HCLT.CORP.HCL.IN";
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 = "KaushikRepo";
String dbmsName ="MDM";
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 ="kaushikb";
String userPassword ="taton";
AuthenticateUserSessionCommand authCommand =
new AuthenticateUserSessionCommand(connections);
if(authCommand!=null)
{
wdComponentAPI.getMessageManager().reportSuccess("Success");
}
else{
wdComponentAPI.getMessageManager().reportWarning("Failure");
}
authCommand.setSession(sessionId);
authCommand.setUserName(userName);
authCommand.setUserPassword(userPassword);
try {
authCommand.execute();
} catch (CommandException e) {
e.printStackTrace();
return;
}
// the main table, hard-coded
try{
GetRepositorySchemaCommand getRepositorySchemaCommand = new GetRepositorySchemaCommand(connections);
getRepositorySchemaCommand.setSession(sessionId);
getRepositorySchemaCommand.execute();
RepositorySchema repositorySchema;
repositorySchema = getRepositorySchemaCommand.getRepositorySchema();
TableId tableId= repositorySchema.getTable("MDM_BUSINESS_PARTNERS").getId();
if(tableId!=null)
{
wdComponentAPI.getMessageManager().reportSuccess("It is success");
}
else{
wdComponentAPI.getMessageManager().reportWarning("Failure");
}
Record rd = RecordFactory.createEmptyRecord(tableId);
//FieldId fdid1 = repositorySchema.getFieldId("MDM_BUSINESS_PARTNERS","MDM_MDM_PARTNER_ID");
FieldId fdid2 = repositorySchema.getFieldId("MDM_BUSINESS_PARTNERS","MDM_PARTNER_NUMBER");
//MdmValue mv = MdmValueFactory.createIntegerValue("200000");
//Record.setFieldValue(FieldId, MdmValue);
//rd.setFieldValue(fdid1,new IntegerValue(86783));
rd.setFieldValue(fdid2,new StringValue("Jinga La "));
//MdmValue[]={ rd.setFieldValue(fdid1,new IntegerValue(86783)), rd.setFieldValue(fdid2,new IntegerValue(86783))};
UserSessionContext ctx= new UserSessionContext(serverName,reposId,userName);
CreateRecordCommand cd = new CreateRecordCommand(ctx);
cd.setRecord(rd);
cd.setSession(sessionId);
try{
cd.execute();
}
catch(Exception e)
{
e.printStackTrace();
wdComponentAPI.getMessageManager().reportWarning("Failure");
}
}
catch(Exception ce)
{
ce.printStackTrace();
}
// catch(SessionException se)
//{
//se.printStackTrace();
//}
//wdComponentAPI.getMessageManager().reportSuccess("Hi I entered here");
//@@end
}
/*
* The following code section can be used for any Java code that is
* not to be visible to other controllers/views or that contains constructs
* currently not supported directly by Web Dynpro (such as inner classes or
* member variables etc.). </p>
*
* Note: The content of this section is in no way managed/controlled
* by the Web Dynpro Designtime or the Web Dynpro Runtime.
*/
//@@begin others
//@@end
}
Regards
Kaushik Banerjee
Edited by: Kaushik Banerjee on Jun 4, 2009 3:33 PM
Hi Kaushik,
Just modify the lines as shown
UserSessionContext ctx= new UserSessionContext(serverName,reposId,userName);
CreateRecordCommand cd = new CreateRecordCommand(ctx);
CreateRecordCommand cd = new CreateRecordCommand(sessionId);
cd.setRecord(rd);
cd.setSession(sessionId);
Comment the lines in Italics and add the line in Bold and try to execute again it should work
Regards,
Jitesh Talreja
Hi,
The variable sessionId is of the type String.
There is no method as such
CreateRecordCommand cd = new CreateRecordCommand(sessionId);
Constructor Summary
CreateRecordCommand(ConnectionAccessor connection)
Constructor
CreateRecordCommand(UserSessionContext ctx)
Creates a new instance of this command by context.
Regards
Kaushik Banerjee
Edited by: Kaushik Banerjee on Jun 4, 2009 4:14 PM
Hi Jitesh,
I commented the authentication as it is running twice.
Record rd = RecordFactory.createEmptyRecord(tableId);
//FieldId fdid1 = repositorySchema.getFieldId("MDM_BUSINESS_PARTNERS","MDM_MDM_PARTNER_ID");
FieldId fdid2 = repositorySchema.getFieldId("MDM_BUSINESS_PARTNERS","MDM_PARTNER_NUMBER");
//MdmValue mv = MdmValueFactory.createIntegerValue("200000");
//Record.setFieldValue(FieldId, MdmValue);
//rd.setFieldValue(fdid1,new IntegerValue(86783));
rd.setFieldValue(fdid2,new StringValue("86783"));
//MdmValue[]={ rd.setFieldValue(fdid1,new IntegerValue(86783)), rd.setFieldValue(fdid2,new IntegerValue(86783))};
//UserSessionContext ctx= new UserSessionContext(serverName,reposId,userName);
//CreateRecordCommand cd = new CreateRecordCommand(ctx);
CreateRecordCommand cd = new CreateRecordCommand(connections);
cd.setSession(sessionId);
rd.getFieldValue(fdid2);
try{
cd.setRecord(rd);
}
catch(Exception e)
{
e.printStackTrace();
}
Record rd2=cd.getRecord();
if(rd2!=null)
{
wdComponentAPI.getMessageManager().reportWarning("No Record created");
}
else{
wdComponentAPI.getMessageManager().reportSuccess("Record created");
}
// authCommand.setSession(sessionId);
// authCommand.setUserName(userName);
// authCommand.setUserPassword(userPassword);
// try {
// authCommand.execute();
// } catch (CommandException e) {
// e.printStackTrace();
// return;
// }
try{
cd.execute();
}
catch(Exception e)
{
e.printStackTrace();
wdComponentAPI.getMessageManager().reportWarning("Failure");
}
The wdComponentAPI.getMessageManager.reportSucess("");
is not working.
I have to check why the record is not getting created.
Regards
Kaushik Banerjee
Hi Jitesh,
I have found out the root cause of the problem.
wdComponentAPI.getMessageManager.reportSuccess("String");
The output is:
Before function call
Success
Success
Field Id created
CreateRecord Object created
Record created
After the call
The Record is getting created.
Problem is resolved.
Regards
Kaushik Banerjee
Edited by: Kaushik Banerjee on Jun 5, 2009 7:59 AM
Hi Kaushik,
You are correct using the getFieldId method from a RepositorySchema object. The two Strings in the method are table code and field code. The table and field codes can be seen in the MDM Console, note it is the field code, not the field name.
-Greg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Greg,
you are correct.
FieldId fdid = repositorySchema.getFieldId("MDM_BUSINESS_PARTNERS","MDM_PARTNER_NUMBER");
MdmValue mv = MdmValueFactory.createIntegerValue("200000");
//Record.setFieldValue(FieldId, MdmValue);
rd.setFieldValue(fdid,mv);
Code above is conceptually correct but it is not creating any MDM_PARTNER_NUMBER by 20000
or am I doing any silly mistake?
Regards
Kaushik Banerjee
Edited by: Kaushik Banerjee on Jun 2, 2009 3:37 PM
User | Count |
---|---|
87 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.