1
votes

I would like to delete some packages from the Enterprise Architect data model with the Enterprise Architect Java API.

What is the behavior of the Enterprise Architect when I delete a package in the package collection?

Will I produce orphans, because I won´t delete the underlying packages (and other elements) explicitly?

My code to delete a specific package:

    org.sparx.Package delPackage = repo.GetPackageByGuid(delPackageGUID);
    org.sparx.Package supraPackage = repo.GetPackageByID(delPackage.GetParentID());

    org.sparx.Collection<org.sparx.Package> packages = supraPackage.GetPackages();
    Iterator<org.sparx.Package> packageIter = packages.iterator();
    org.sparx.Package tempPackage;

    short index = 0;
    short foundIndex = -1;

    packageLoop:
    while (packageIter.hasNext())
    {
        tempPackage = packageIter.next();

        if (tempPackage.GetPackageGUID().equals(delPackageGUID) == true)
        {
            foundIndex = index;
            break packageLoop;
        }

        index++;
    }

    if (foundIndex < 0)
    {
        throw new Exception("some error message");
    }

    if (packages.GetAt(foundIndex).GetPackageGUID().equals(delPackageGUID) == false)
    {
        throw new Exception("some error message");
    }
    else
    {
        delPackage.ApplyUserLock();
        delPackage.GetLastError();

        packages.DeleteAt(foundIndex, false);
        packages.GetLastError();

        //Update
        packages.Refresh();
    }
2

2 Answers

2
votes

Simply speaking: the package and the whole contents it holds will be removed. Actually it does the same as when deleting it manually.

The EA help, of course, does not tell you anything. However, I have checked the above behavior.

If you want to keep sub-packages, you need to move them to another (parent) package of the delete one.

2
votes

It should delete all the contents from the package if you do it like this, but if you're not sure why don't you try it out?

You can query t_package and t_object to verify the expected number of elements and packages, and you can run the project integrity check to verify orphaned objects.