Book a Demo

Author Topic: Replacing stereotypes in script  (Read 7224 times)

ken.norcross

  • EA User
  • **
  • Posts: 63
  • Karma: +0/-0
    • View Profile
Replacing stereotypes in script
« on: August 15, 2013, 04:17:40 am »
Hi all,

I am in the process of finalizing a profile delivered in MDG, and unfortunately I have realized a little late in the game that I should make sure the profile stereotype names are unique, due to the flat stereotype namespace in sparx. For example I had stereotypes like "Report" "Interface"  "Screen" etc., and these are just too generic and likely to clash with other stereotypes and cause subtle problems in the future, so I have changed the profile stereotype names to be more unique.

I already have model elements using the previous stereotypes, and now I need to migrate them in place using a script. I have performed some tests and I am achieving partial success in replacing the stereotypes with a script, but not complete success. In the end I have to invoke "synchronize stereotype" from a toolbox to get the last change. I was hoping to completely automate this migration. Running a script, and invoking the synchronize once is not too bad, but I am wondering if I am missing something in my script.

Here is the relevant jscript code:

//copy tagged values
var myTag as EA.TaggedValue;
myTag = GetTaggedValue (theElement, "TagName");
      
//remove all old stereotypes
theElement.Stereotype = "";
theElement.StereotypeEx = "";
theElement.Update();
theElement.Refresh();

//add new stereotype
theElement.Stereotype = "ExScreen";
theElement.Metatype = "ExScreen";
theElement.Update;
theElement.Refresh();
      
//restore tagged values
TVSetElementTaggedValue( theElement ,"TagName",myTag.Value ,true);
      
//final update
theElement.Update();
theElement.Refresh();

This seems to do everything, except when I look for my profile defined tags, they do not show up grouped under the profile name, like they do when creating a new element. If I run a script I can see the tags are not associated with the profile with fully qualified names. If I invoke "synchronize stereotype" from the toolbox, then the profile name grouping appears with my values intact and everything looks fine.

Am I doing some thing wrong or missing a step?

(I am sure I may be going overboard with the Update() and Refresh() also)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Replacing stereotypes in script
« Reply #1 on: August 15, 2013, 05:26:25 am »
You won't need the first part to remove the stereotype since you immediately replace it with content. The Refresh is also superfluous (while Update isn't). Then you invoke TVSetElementTaggedValue. What is it?

The problem with grouping is likely that EA create wizardry in t_xref to correlate TV and elements. Somehow I thought they solved that since in the latest EA build you simply need to assign a stereotype and EA is doing the rest. That was not the case in pre V10 builds. Also when removing the stereotype the TVs vanish too.

q.

ken.norcross

  • EA User
  • **
  • Posts: 63
  • Karma: +0/-0
    • View Profile
Re: Replacing stereotypes in script
« Reply #2 on: August 15, 2013, 05:57:33 am »
Quote
... you invoke TVSetElementTaggedValue. What is it?

A function in EAScriptLib JScript-TaggedValue

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Replacing stereotypes in script
« Reply #3 on: August 15, 2013, 06:32:10 am »
I see. Wasn't obvious.

What happens when you assign the stereotype manually with the GUI (without calling synch). Do the TVs appear automatically? And if so, are they grouped?

q.

ken.norcross

  • EA User
  • **
  • Posts: 63
  • Karma: +0/-0
    • View Profile
Re: Replacing stereotypes in script
« Reply #4 on: August 20, 2013, 02:30:18 am »
Just got back to this over the weekend.

Discovered that you can call Repository.SynchProfile() so that would eliminate the manual step I thought I would have to do.

The magic sequence of calls that worked for me was:

- copy tagged values
- set stereotype and stereotypeEx to ""
- update element

- set to new stereotype
- update element
- restore tagged values
- update element
- call Repository.SynchProfile()

If I did not first set stereotype to "" and call Update I did not get the desired results.