Author Topic: Create parent class from children  (Read 88 times)

Squeegee

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Create parent class from children
« on: October 12, 2018, 07:32:18 pm »
Hi,
we have the following challenge (using EA 12):

A lot of classes with ports which are used in several diagrams (as links or as instances). Now we want to create abstract parent classes out of them. So basically the other direction than provided automatically when dragging a class into a diagram and choose option "Child (Generalization)" from the menu.

For sure it is possible to simply copy the whole class with all ports and create the generalize connector manually.  Unfortunatelly then we get all the ports from the parent via "structural elements "Show Owned/inherited" from the parent so we have all ports twice in the child class - the real generalized ports and the already existing one in the child. But exactly the already existing ones are connected to all the other elements, so we have to update each and every diagram in the whole model.

Therefore my question is:
Is there a possibility to create a parent for an existing class with ports, where the existing ports are also automatically child ports?
We also tried using the automation via VBscript but so far we failed as we did not find how  the port of the children "knows" that he is a generalized port.

Any suggestions are welcome :-)

Thanks
Uwe

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 8463
  • Karma: +207/-26
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Create parent class from children
« Reply #1 on: October 12, 2018, 07:41:31 pm »
Hi Uwe,

I don't know if there is a standard, out of the box, solution, but there is no reason why it shouldn't work with scripting.
It's just a matter of figuring out exactly how EA stores all these elements and relations.

Geert

PS. Hooking up a profiler that records all SQL traffic to the model often helps in figuring out things like that.

Squeegee

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Create parent class from children
« Reply #2 on: October 12, 2018, 08:06:45 pm »
Hi Geert,
thanks for the fast reply, I've never done something like that :-)

Will try and come back later.

Uwe

Squeegee

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Create parent class from children
« Reply #3 on: October 12, 2018, 09:16:15 pm »
We're a little bit later than before :-)

there is a reference from the child port to the GUID of the parent port like follows:
<UML:TaggedValue tag="reusesProperty" value="{F719F346-C297-4b6b-A4CA-CA4D783FE0C1}"/>

Unfortunately, this values is stored in EA.Element.MiscData which is ReadOnly and the EA help tells me that it is not possible to access it via automation.
Now I am running out of ideas...

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 8463
  • Karma: +207/-26
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Create parent class from children
« Reply #4 on: October 12, 2018, 10:23:11 pm »
If all else fails there's still the undocumented/unsupported backdoor Repository.Execute(SQL)

Geert

Squeegee

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Create parent class from children
« Reply #5 on: October 15, 2018, 11:06:53 pm »
Finally it worked, if anyone has the same use case, we solved it like follows:

Pre-Condition: A class with ports in a package (this is the "child")
The we do the following manual steps:

1) Copy and paste the whole package (the copy is then the "parent")
2) Create an generalization between child and the newly created parent
3) Run the diagram script on the child class..

The script loops through all embedded elements of type port in  the child, follows the generalization and looks up, if there is a port with the same name on the parent.
If yes, it add's the GUID of the parents port at the child port using the following sql command:

UPDATE t_object
SET pdata3 = parentGuid
WHERE ea_guid = childGuid;
using the Repository.Execute() API.

Thanks to Geert for his really helpful hints!