Author Topic: How to get the name of business object attribute  (Read 6620 times)

DAHLing

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
How to get the name of business object attribute
« on: November 22, 2012, 01:24:46 am »
Hi,

We use the interface with java and have now the problem that we don't know how we can get the name or alias from the endpoint of an association. We use the function "Link to element feature."
For example: We have a mask (first name, last name, save button) and for this a business object with first name, last name. The input field from the mask has the association to first name from business object and last name from mask has also an association to last name attribute from business object. Now we want  write a script that automatically looks for the business attribute for an input field from a mask. But we have no idea how we have to do it. We tried it with some methods from Connector, but without any successful results....

I hope my description is understandable... ;)

thanks

Markus

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to get the name of business object attribu
« Reply #1 on: November 22, 2012, 05:38:56 am »
Each connector has the object id of the connected elements (ClientID and SupplierID). Use these to get according elements via Repository.GetElementByID. There you can retrieve the Attributes collections.

Further I'd recommend my book Scripting EA.

q.

DAHLing

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: How to get the name of business object attribu
« Reply #2 on: November 22, 2012, 09:46:56 pm »
Hi qwerty,

thanks for your fast answer.
Unfortunately I don't have much experience in java programming, so I hope you can help me one more time please.

When I try the code below, it seems that "connector" is empty, because there is no output of "Endtarget:".
Is the code not correct or could it be there is something wrong in the model?

Code: [Select]
void writeTestScript(Repository repository, String gUID)
{
Package eaPackage = null;
eaPackage = repository.GetPackageByGuid(gUID);
Iterator <Connector> connector = eaPackage.GetConnectors().iterator();
while (connector.hasNext()){
Connector conn = connector.next();
String endTarget = repository.GetElementByID(conn.GetSupplierID()).GetName();
System.out.println("Endtarget: "+endTarget);
}      
}

Thanks,
Markus

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to get the name of business object attribu
« Reply #3 on: November 22, 2012, 10:29:49 pm »
Sorry Markus, but my java knowledge is very little. To me the code looks okay. I'd try to put more trace into it. E.g.: Name the connectors of the package in EA and print the names of the connectors. Somethig like
Code: [Select]
System.out.println("Conn name: "+conn.GetName());
So you see you have the right connectors at all.

q.

DAHLing

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: How to get the name of business object attribu
« Reply #4 on: November 22, 2012, 10:59:10 pm »
The problem is that connector seems to be empty and the program will not go into the while-loop.

Should it work for an association and "Link to Element Feature"?

Wir können auch über PM deutsch schreiben, wenn es für Sie okay ist ;)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to get the name of business object attribu
« Reply #5 on: November 23, 2012, 12:10:38 am »
Ah, I see, you are asking for the connector of the package.

You should be iterating the connectors of the elements in the package.

The "link to element feature" associations are also regular associations. There's somewhere one or more topics in this forum that explain how to get the details for the linked feature. (Use the top left search button, and check the search options)

Geert

DAHLing

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: How to get the name of business object attribu
« Reply #6 on: November 23, 2012, 12:15:21 am »
Yes, you are right. Thanks so much!

DAHLing

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: How to get the name of business object attribu
« Reply #7 on: November 23, 2012, 01:06:11 am »
I can not find a topic about how to get the details for the linked feature.
Can you help again please? Sorry... :-/

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to get the name of business object attribu
« Reply #8 on: November 23, 2012, 01:09:46 am »
I'd guess this information is deep in EA's guts. Likely it's in the table t_xref. I can't remember having searched for this yet.

q.

[edit] No. It's in the Note's PDATA. PDATA1="ElementNote" (or whatever you used); PDATA2=element-id of object. Its more complicated for linked attributes. For that I did not find the referring element-id.
« Last Edit: November 23, 2012, 01:17:15 am by qwerty »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to get the name of business object attribu
« Reply #9 on: November 23, 2012, 01:22:39 am »
Nope, can't find it either.
I don't really have time now to investigate it myself.

Here's what I would do to figure it out:

Start an empty model, make only two classes, one attribute and one connector and link to that attribute.
The open the database and search each table.
Pay special attention to pdata, style, styleEx columns and the t_xref table.

Then, if you have figured out how things are connected, use Repository.SQLQuery() to execute a query to get the id of the attribute, and use Repository.GetAttributeByID() to get the attribute object.


Geert

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Re: How to get the name of business object attribu
« Reply #10 on: November 23, 2012, 09:18:44 am »
It's in the connector's StyleEx field. It might contain something like "LFEP=<TargetGUID>R;LFSP=<SourceGUID>L;". Use the GUIDs to look up the linked features in either the attributes table or the operations table.
« Last Edit: November 23, 2012, 09:19:01 am by KP »
The Sparx Team
[email protected]

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to get the name of business object attribu
« Reply #11 on: November 24, 2012, 12:26:55 am »
Quote
It's in the connector's StyleEx field. It might contain something like "LFEP=<TargetGUID>R;LFSP=<SourceGUID>L;". Use the GUIDs to look up the linked features in either the attributes table or the operations table.
I should have read my own book  (page 40) :-X

q.

DAHLing

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: How to get the name of business object attribu
« Reply #12 on: November 26, 2012, 05:17:28 pm »
Thanks, I'll check it today.

DAHLing

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: How to get the name of business object attribu
« Reply #13 on: November 26, 2012, 11:48:12 pm »
Hi,
thank you all, it works:

Code: [Select]
void getConnector(Element pElement, Repository repository){
      Iterator <Connector> connector = pElement.GetConnectors().iterator();
      System.out.println("Element: "+pElement.GetName());
            while (connector.hasNext()){
            Connector conn = connector.next();
            String endTarget = conn.GetStyleEx();
            System.out.println("Endtarget: "+repository.GetAttributeByGuid(endTarget.substring(5,43)).GetName());
            }
      }