Author Topic: MDG Migration  (Read 1040 times)

Sunshine

  • EA User
  • **
  • Posts: 500
  • Karma: +33/-1
  • Amicorum omnia communia
    • View Profile
MDG Migration
« on: June 22, 2016, 01:19:27 pm »
I need to migrate packages, elements and diagrams of an existing model created using one MDG technology to another MDG. Worked out all the mappings etc and managed to convert element and package stereotypes using JScript but having difficulty with diagram types.

The MDG Technology diagram type seems to be stored in t_diagram.StyleEx ="... MDGDgm=MDG Diagrams::DiagramType;..."
So initially I tried reading diagram.StyleEx in Jscript then converting to string, doing a replace the storing back into diagram.StyleEx followed by diagram.Update(). The styleEx was changed but after the update() call it reverts back. The update method returns True indicating success so no errors reported.
The code looks something like this
Code: [Select]
...
        var currentDiagram as EA.Diagram;
        currentDiagram = diagramEnumerator.item();
var style = String(currentDiagram.StyleEx);
style= style.replace("MDGDgm=Old MDG Diagrams::Old Diagram;","MDGDgm=New MDG Diagrams::New Diagram;");
currentDiagram.StyleEx=style; //Updates StyleEx ok to "MDGDgm=New MDG Diagrams::New Diagram;"
currentDiagram.Update(); // Reverts back to "MDGDgm=Old MDG Diagrams::Old Diagram;"
...

Any help or tips would be greatly appreciated coz I'm stumped. :(

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 7730
  • Karma: +165/-21
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: MDG Migration
« Reply #1 on: June 22, 2016, 02:39:11 pm »
In the past I've done similar tranformations using SQL updates.

As a bonus they perform 100 times better then using the API.


Geert

Sunshine

  • EA User
  • **
  • Posts: 500
  • Karma: +33/-1
  • Amicorum omnia communia
    • View Profile
Re: MDG Migration
« Reply #2 on: June 22, 2016, 04:09:59 pm »
Thanks Geert, I was hoping I could avoid SQL but keep having to get down there aye? I managed to get this code pattern to work on SQL Server should anyone else have the same problem

Code: [Select]
UPDATE  t_diagram
SET StyleEx = REPLACE (CONVERT(NVARCHAR(MAX), StyleEx), 'MDGDgm=Old MDG Diagrams::Old Diagram;', 'MDGDgm=NewMDG Diagrams::NewDiagram')
WHERE StyleEx Like '%MDGDgm=Old MDG Diagrams::Old Diagram;%';

And boy was it fast compared to JScript.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 7730
  • Karma: +165/-21
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: MDG Migration
« Reply #3 on: June 22, 2016, 04:32:49 pm »
Yes, sometimes SQL is the best tool for the job, especially for mass-updates. I can imagine that the SQL statement took a few seconds at most, where the script might need (tens of) minutes to finish.

In case you don't have direct access to the database you can always use Repository.Execute(sqlString) to execute such statements.

Geert

Uffe

  • EA Practitioner
  • ***
  • Posts: 1068
  • Karma: +81/-5
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: MDG Migration
« Reply #4 on: June 22, 2016, 04:36:05 pm »
According to the API documentation, Diagram.MetaType is read-only. This might be the reason the original code wasn't working.
It does say .StyleEx is reserved for the use of Sparx Systems.

/U
My theories are always correct, just apply them to the right reality.

Sunshine

  • EA User
  • **
  • Posts: 500
  • Karma: +33/-1
  • Amicorum omnia communia
    • View Profile
Re: MDG Migration
« Reply #5 on: June 22, 2016, 06:19:19 pm »
According to the API documentation, Diagram.MetaType is read-only. This might be the reason the original code wasn't working.
It does say .StyleEx is reserved for the use of Sparx Systems.

/U
Thanks Uffe.
I did try with MetaType originally then found it was read-only. Then tried StyleEx as that was read-write but that didn't seem to work when invoking Diagram.Update().

If at first you don't succeed go down another layer. That SQL worked a treat.