Author Topic: Import native XML by automation and merge (update/insert)  (Read 249 times)

gregor139

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Import native XML by automation and merge (update/insert)
« on: June 16, 2022, 01:44:48 am »
Hi,

I'm looking for a way to import a native XML file via automation interface in a merge kind of way: For every existing object (same guid) an update should be executed (IDs remain unchanged) and only new objects will be inserted with newly generated IDs (deletes never occure). As far as I understand the project method ImportPackageXMI doesn't work this way.

Is there a solution for this?

Thx

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11819
  • Karma: +458/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Import native XML by automation and merge (update/insert)
« Reply #1 on: June 16, 2022, 04:03:26 am »
No, I don't think so.

I'm afraid you'll have to do that by writing your own logic.

Geert

Pawel Jasinski

  • EA User
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Re: Import native XML by automation and merge (update/insert)
« Reply #2 on: June 21, 2022, 05:57:21 pm »
Did you try anything using gui?
If yes, what didn't work?

Pawel Jasinski

  • EA User
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Re: Import native XML by automation and merge (update/insert)
« Reply #3 on: June 23, 2022, 10:22:58 pm »
I just tested it using native xml package import, gui and ImportPackageXMI.
In both cases sparx preserves object_id and guid of the updated elements, you have to make sure to deselect Strip GUID.
The exact sparx version is 16.0.1604
Code: [Select]

import win32com.client

try:
    repo = win32com.client.Dispatch("EA.Repository")
    print(repo.OpenFile(r"C:\must-be-absolute-path\for-gregor-target.qeax"))
    print(repo)

    project = repo.GetProjectInterface()
    print(project)
    error = project.ImportPackageXMI(
        PackageGUID="{7D0CD74B-DA8A-44b9-AB02-9D129B3071EC}",  # this is guid of the existing package to be updated
        Filename=r"C:\redacted-full-path\adim1-v1.1.xml", # this is native xml with package file where root Package element has matching guid attribute
        ImportDiagrams=True,
        StripGUID=False,  # translates to "update" existing
    )
    print(error)

finally:
    repo.CloseFile()
    repo.Exit()



Code: [Select]
<?xml version="1.0" encoding="windows-1252" standalone="no"?>
<Package name="adim1" guid="{7D0CD74B-DA8A-44b9-AB02-9D129B3071EC}">
  <Table name="t_package">
    <Row>
      <Column name="Package_ID" value="7"/>
      <Column name="Name" value="adim1"/>
...
« Last Edit: June 23, 2022, 10:26:37 pm by Pawel Jasinski »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11819
  • Karma: +458/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Import native XML by automation and merge (update/insert)
« Reply #4 on: June 24, 2022, 12:39:14 am »
Pawel,

I think the key point is the "no deletes".
When you import a package from xmi (or native xml) it will delete anything that isn't defined in the file.

@Gregor
I think there's also a merge function somewhere, but I've never really used that.
See https://sparxsystems.com/enterprise_architect_user_guide/16.0/model_exchange/merge_package_directly.html

Maybe that does what you are looking for?

Geert

gregor139

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Import native XML by automation and merge (update/insert)
« Reply #5 on: June 24, 2022, 02:07:55 am »
The merge now works. The first time t got a unspecified error when trying to import an already existing package. I think this error occured because of the full lock of the package. Now it makes sense, but the error message wasn't very helpful. When disabling the full lock for the package the import works fine and GUIDs as well as IDs remain.

Pawel Jasinski

  • EA User
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
Re: Import native XML by automation and merge (update/insert)
« Reply #6 on: June 24, 2022, 03:38:40 pm »
> I think the key point is the "no deletes".
> When you import a package from xmi (or native xml) it will delete anything that isn't defined in the file.

I can't comment on xmi, no experience.
However native xml package import (not project import) will not touch elements unless the elements are in the imported scope in model (package subtree) or have a guid match within the import file.
The experiments indicate that some of the connectors crossing the import boundary are removed and some are preserved. Somewhere in the documentation there is a rule based on a connector ownership.
For no deletes, agree, there are always sql deletes for things linked with elements (e.g. tagged values are always deleted and reinserted). But the actual elements are updated with sql update statements.
I also recall something about object sequence going one up because of extra placeholder element temporarily inserted into the model.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11819
  • Karma: +458/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Import native XML by automation and merge (update/insert)
« Reply #7 on: June 24, 2022, 05:49:03 pm »
xml and xmi package import is the same thing.

The main point was that importing a package from xmi/xml replaces the package in the model, with the contents of the file.
So if your package in the model contains element X, and the package in the xml file does not, element X will be deleted.

But apparently the merge option seems to work for Gregor.

Geert