cancel
Showing results for 
Search instead for 
Did you mean: 

MDM JAVA API: which is way for reads parend id

former_member207329
Participant
0 Kudos

Hi MDM guru,

I work with Hierarchy table and use MDM Java Api.

Question:

For each node Which is the way for reads parent id???

Accepted Solutions (1)

Accepted Solutions (1)

Greg_Austin
Active Participant
0 Kudos

In the RetrieveLimitedHierTreeCommand when you execute the getTree() method you get a HierNode object. This object is the entire tree returned. You can use the getParent() method to get the HierNode object of the parent, then you can use the getId() method.

-Greg

former_member207329
Participant
0 Kudos

Hi Greg,

thanks for you help.

The problem is:

I use RetrieveLimitedHierTreeCommand in follow mode:

RetrieveLimitedHierTreeCommand cmd = new RetrieveLimitedHierTreeCommand(cntrl.getConnection());

cmd.setSession(cntrl.getUserSession());

cmd.setSearch(search);

cmd.setResultDefinition(resultDefinition);

if(rootNodeRecordID != null) {

cmd.setRootNode(rootNodeRecordID);

}

try {

cmd.execute();

} catch (CommandException e) {

throw new IllegalArgumentException(e.getMessage());

}

return cmd.getTree().getParent();

I have a node (cmd.getTree) but getParent is NULL.

Greg_Austin
Active Participant
0 Kudos

If the parentId is null you are probably on a node that is on the top level. If you do cmd.getTree().getChildren() you will have a HierNode[], doing getParent on one of the HierNodes in the array will give a parentId.

-Greg

former_member207329
Participant
0 Kudos

This for me is clear.

But if i have this tree:

root

|-----A

| __ |---A1

| __ |---A2

| _____ |---A21

|-----B

| __ |---B1

| __ |---B2

|_____ |---B21

If I use RetrieveLimitedHierTreeCommand for search B2 I have this result:

cmd.getTree()= B2 [HierNode object]

cmd.getTree().getParent() = [NULL]

I think about the correct result is B or no?

This is a API error or no? I

Greg_Austin
Active Participant
0 Kudos

I think the parent isn't in the HierNode because you searched for only a Record below it and the API is limiting what it returns to you. Try using the RetrieveHierAncestorsCommand to get the parent.

-Greg

former_member207329
Participant
0 Kudos

Thanks Greg,

I resolve with this class:

static public MdmObjectKey getParentMdmKey(MdmPlugIntf plug, RepositorySchema schema, Search search, ResultDefinition resultDefinition, RecordId child) {

MdmPlug plugInst = (MdmPlug)plug;

ControlIntf cntrl = plugInst.getControl();

TableProperties table = schema.getTable(resultDefinition.getTable());

switch(table.getType()) {

case TableProperties.HIERARCHY:

case TableProperties.TAXONOMY:

RetrieveHierAncestorsCommand cmd = new RetrieveHierAncestorsCommand(cntrl.getConnection());

cmd.setSession(cntrl.getUserSession());

cmd.setChildNode(child);

cmd.setResultDefinition(resultDefinition);

try {

cmd.execute();

} catch (CommandException e) {

throw new IllegalArgumentException(e.getMessage());

}

Record[] item=cmd.getAncestors().getRecords();

MdmObjectKey mdmKey = new MdmObjectKey();

if (item!=null && item.length>0){

RecordId resultValue=new RecordId(item[0].getId());

for (int j=0;j<item.length-1;j++){

resultValue=item[j].getId();

}

mdmKey.setRecordId(new Integer(resultValue.getIdValue()));

}

return mdmKey;

default:

throw new IllegalArgumentException("This method only works with Taxonomy and Hierarchy tables.");

}

}

Answers (0)