0

How can I use the DXL OLE mechanism to fetch a diagram's modification time from Enterprise Architect 12?

Details:

I want to retrieve diagrams from EA and integrate them as OLE object into IBM Rational DOORS 9.5. This is already working. I intend to compare the modification dates of the EA diagram and the DOORS object before retrieving the diagram to decide if this operation is really needed.

Problem is, EA provides a diagram attribute EA.Diagram.ModifiedDate which returns the diagram's modification date as data type Variant. How can I handle this within DXL? The result parameter for oleGet() can be one of the types string|int|bool|char|OleAutoObj. No structured type (which would probably be DxlObject). Neither string nor int parameters contain any useful data after the call -- just null values.

Test code:

OleAutoObj  eaRepository, eaProject, eaDiagram
OleAutoObj  eaApp    = oleGetAutoObject("EA.App")
OleAutoArgs autoArgs = create
string      guid     = "{729F140F-9DA4-4ff6-A9B2-75622AD1C22D}"

// connect to an existing EA instance
oleGet (eaApp, "Repository", eaRepository)
oleMethod (eaRepository, "GetProjectInterface", autoArgs, eaProject)

// call EA to a diagram which has this GUID
put(autoArgs, guid)
oleMethod(eaRepository, "GetDiagramByGuid", autoArgs, eaDiagram)
delete autoArgs

// access diagram attributes
string eaModifiedDate // DXL accepts [string|int|bool|char|OleAutoObj] only
oleGet(eaDiagram, "ModifiedDate", eaModifiedDate)
print "ModifiedDate = '" eaModifiedDate"'\n"

IBM's Support Team (commercial, available for paying customers) couldn't help and suggested to forward this question to the Service Team (for extra $s). Rather disappointing.

Twonky
  • 796
  • 13
  • 31

2 Answers2

1

Try this one (just guessing :-)

OleAutoObj eaModifiedDate
oleGet(diagram, "ModifiedDate", eaModifiedDate)
if (null eaModifiedDate)
    print "no eaModifiedDate\n"
else {
    string diaDate
    oleGet(eaModifiedDate, "Value", diaDate)
    print "ModifiedDate = '" diaDate"'\n"
}

If that does not work then here comes the ultimate work around:

string err
string result

put(autoArgs, "SELECT ModifiedDate FROM t_diagram WHERE ea_guid = '"  guid  "'")
err = oleMethod (eaRepository, "SQLQuery", autoArgs, result)
if (!null err)
    print "ERROR: " err "\n"
delete autoArgs

print "result= '" result"'\n"

This will return a XML formatted string (!) which contains the date in the format you like.

Edit 1: Turns out that EA's SQLQuery is buggy and returns just the date. Since Perl deals with OLE Variants in a similar way I found this code snippet:

my $dia = $rep->getdiagrambyguid("{63EFF3FA-0D5C-4986-AC0A-C723D2F755E3}");
my $value = $dia->ModifiedDate->Value;
print $value->Date( 'yyyy/MM/dd' );
print $value->Time( 'hh:mm:ss' );

So the ModifiedDate is an ole-object and has a Date and a Time method. This should work with DXL too.

Edit 2:Now here's the ulti-ultimate work around even shipping around the cliffs of EA's bug ocean:

my $dia = $rep->SQLQuery("SELECT Format (ModifiedDate, \"Short Time\") AS T FROM t_diagram");

This will format the date as time string. Works for EAP (aka Mickeysoft Access) according to this page. Other RDBMS likely have similar functions.

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • Problem solved! Using the ulti-ultimate workaround helps. Using `Format (ModifiedDate, \"dd/mm/yyyy hh:mm:ss\")` for the query helps DXL to parse the date&time string when converting to `Date` type. Extracting the date&time from the XML result string works using `Regexp fetchDate = regexp2 "(.*)<\\/t>"; if (fetchDate result) result = result [match 1]; delete fetchDate;`. Many many thanks! – Twonky Sep 23 '15 at 12:17
0

An update with a few corrections of my statements in comments.

I was wrong. It is indeed possible to receive structured data types using the OLE automation interface. As Thomas mentioned, the OleAutoObject is the proper DXL return type, oleGet() is the proper function. To access the returned object's attributes, it is required to be aware of the "real" data type and to have a look at the SDK documentation in order to know which class attributes are available since DXL is not aware of the data type.

However, in DXL, retrieving the attribute of a structured data type is a bit cumbersone. Example (intended to be appended to the inital post's code):

OleAutoObj  diaLinksCollection
int         count    = -1
string      buffer   = ""

// access simple diagram attributes
err = oleGet(eaDiagram, "Version", buffer)      
if (!null err) print "ERROR in Diagram.Version: " err "\n"
print "diagram version = " buffer "\n"

// access structured diagram attribute
err = oleGet(eaDiagram, "DiagramLinks", diaLinksCollection)
if (!null err) print "ERROR in Diagram.DiagramLinks: " err "\n"

err = oleGet(diaLinksCollection, "Count", count)
if (!null err) print "ERROR in Collection.Count: " err "\n"

print "count = " count "\n"

Thus, it is indeed possible to execute an SQL query, even if the repository is residing in a plain *.eap file, see Thomas' workaround.

As mentioned, the Variant data type can not be retrieved using oleGet() since this approach returns a NULL result.

Twonky
  • 796
  • 13
  • 31