C. Connar
C. Connar

Reputation: 21

Accessing PowerDesigner Repository Models via COM

I have been trying to get live models directly from the PowerDesigner repository using the COM API without success. Here's what I've been trying in VBA:

Set pd = CreateObject("PowerDesigner.Application")
Set conn = pd.RepositoryConnection
conn.Open "", "", "ShhMahPW"

Set model = conn.FindChildByPath("Program/Project/Logical Models/MahLOM", PdOOM_Classes.cls_Model)

MsgBox model.ShortDescription 'This fails because model is null!

Similarly, I've been trying the same thing in Eclipse with the Java COM bridge:

Application pd = this.getApplicationHook();

//Make live connection to proxy repository
RepositoryConnection conn = new RepositoryConnection( pd.GetRepositoryConnection() );
conn.Open( "", "", ConnectionParams.PASSWORD );


BaseObject model = conn.FindChildByPath( "Program/Project/Logical Models/MahLOM", 
                   PdOOM_Classes.cls_Model );

//Null model, COMException: "Action can not be performed. result = -2147467259"
System.out.println( model.GetShortDescription() ) 

Can someone please suggest a good way of diving into the repository? I have been able to confirm that I have a connection to the repo and then list the children at that top level. I am struggling to dig into folders beyond the root level. Thanks!

Upvotes: 1

Views: 1384

Answers (2)

pascal
pascal

Reputation: 3365

Your main problem is that the search ChildKind should be Cls_RepositoryModel, instead of PdOOM_Class.cls_Model.

   option explicit
   ' assuming we're already connected
   if RepositoryConnection.Connected then
      Descent RepositoryConnection,""
   end if
   dim c
   set c = RepositoryConnection.FindChildByPath("Folder_7/ConceptualDataModel_1", Cls_RepositoryModel)
   if not c is nothing then
      output "*** found object " & c.classname
   end if

sub Descent(obj,ofs)
   output ofs & obj.name & " - " & obj.ObjectType & " - " & obj.ClassName
   if obj.ObjectType = "RepositoryModel" then exit sub
   if obj.PermanentID = 3 then exit sub ' to save time, don't enter Library
   if not obj.HasCollection("ChildObjects") then exit sub
   dim c
   for each c in obj.ChildObjects
      Descent c,ofs & "   "
   next
end sub

Upvotes: 0

C. Connar
C. Connar

Reputation: 21

I knew that the model I was looking to pull down from the repo already existed in my local workspace. Really this was a refresh of the local workspaces models. To perform this, the method UpdateFromRepository() can be used!

So what I can do then is get a handle to the local PowerDesigner model and then call for an update before retrieving children. Note the casting from BaseObject to BaseModel for the sake of the refresh...

private BaseObject getModel(){

    Application pd = this.getApplicationHook();

    model = pd.OpenModel(this.basePath + this.modelName);
    System.out.println( "Retrieving model updates from repository...  ");

    RepositoryConnection conn = new RepositoryConnection( pd.GetRepositoryConnection() );
    conn.Open( "", "", ConnectionParams.PASSWORD);

    boolean success = new BaseModel(model).UpdateFromRepository();

    if( success )
        System.out.println( "Update successful!" );
    else
        System.out.println( "Update failed. Check PowerDesigner settings." );

    return this.model;
}

Upvotes: 1

Related Questions