Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: MarkG86 on August 17, 2011, 04:59:18 am

Title: Last Modification Date
Post by: MarkG86 on August 17, 2011, 04:59:18 am
Hello,

I'm trying to find out when was the last change made to a model (or the entire repository). I'm using Java Automation API. There is a method GetModified that can be called on a Package object, but it doesn't seem to work (that is, it returns some odd values from the distant past like: Sat Dec 30 00:00:00 CST 1899).

I tried recursively traversing the entire tree and getting GetModified on all models (Package objects), packages and elements, but the values simply don't match what I expect to get.

And my expectation is that if I make a change to an element (add a note, add a method or field to a class in the diagram, change the stereotype etc.) the Date returned by GetModifed will be set to my current Date. This is not the case though. Any thoughts and hints?

All I really need to do is to be able to say if the any part of the model has been modified after a given Date. (I know I could just check the time stamp on the EAP file, but sadly this approach doesn't work for EAP files that link to a Database).

Thanks!
Title: Re: Last Modification Date
Post by: Geert Bellekens on August 17, 2011, 05:09:32 pm
Mark,

I believe EA only keeps the "last modification date" on Elements.
That is to say, it only updates that date if the actual element object has been updated, and it doesn't look an any of the owned elements/features of that element.
So changing something to an attribute will not change anything on the element and thus will not update the modification date.

Although it isn't really precise, I think it still can be used to get a rough idea of when this model was last changed.

BUT, traversing the whole model using the API will be a nightmare performance wise. (it will take hours and hours for even a moderately large model).

So the only feasible option I can think of is to use an SQL query.
You can use the Repository.SQLQuery() operation to execute your own random query to the database without worrying about database connectors and stuff like that.

I just noticed diagrams have a modified date as well, so you might want to use that as well.
So launching something like
Code: [Select]
select MAX(o.ModifiedDate) from t_object o
and
Code: [Select]
select MAX(d.modifiedDate) from t_diagram dand selecting the largest data from those two will probably work a lot better (and in a fraction of the time)

If you really need an exact date I guess the only option is to turn auditing on.

Geert

PS. the date in 1899 is the equivalent of "0" or in other words "empty"
Title: Re: Last Modification Date
Post by: MarkG86 on August 24, 2011, 12:55:29 am
Geert,

thank you very much, this has been a huge help!

The result I get looks like that:

Quote
<?xml version="1.0"?>
<EADATA version="1.0" exporter="Enterprise Architect">
        <Dataset_0><Data><Row><Expr1000>8/23/2011</Expr1000></Row></Data></Dataset_0>
</EADATA>

Do you know if there is a way to get a time in addition to the date? This would be perfect!
I looked up the actual database (one of my models is stored in SQL DB) and the type used to store ModifiedDate is datetime, in the following format: '2011-08-23 09:53:20.000'. Any ideas why the SQLQuery method returns only '8/23/2011'?

Again, thanks a lot for your suggestions!

Mark

UPDATE:
The suggested solution doesn't seem to work with repositories stored in Database, I somehow missed that when I posted my original message.
Running the above listed SQL queries on a project that has been transferred to a database gives the following result:
Quote
<?xml version="1.0"?>
<EADATA version="1.0" exporter="Enterprise Architect">
        <Dataset_0><Data><Row/></Data></Dataset_0>
</EADATA>
Running the SQL against the same repo, only stored in an EAP file gives the following:
Quote
<?xml version="1.0"?>
<EADATA version="1.0" exporter="Enterprise Architect">
        <Dataset_0><Data><Row><Expr1000>8/21/2011</Expr1000></Row></Data></Dataset_0>
</EADATA>
Any hints? Why is there a difference in how EA Automation treats projects stored in file vs a database?
Title: Re: Last Modification Date
Post by: Eve on August 24, 2011, 08:32:20 am
The difference is in how the database that the EA repository is running on handles your sql query.

EA doesn't provide an abstracted sql layer to remove the database inconsistencies.
Title: Re: Last Modification Date
Post by: MarkG86 on August 24, 2011, 09:55:54 am
Simon,

I don't understand why would the following query cause any inconsistencies:

Quote
select MAX(d.modifiedDate) from t_diagram d

I'm running SQL Server 2008. Executing the query through MS SQL Server Management Studio returns a legitimate result.

At the same time running this query:

Quote
select TOP(1) ModifiedDate from t_object order by modifiedDate desc

returns a valid result for models stored in SQL Database, but NOT for models stored in EAP file. It's probably much slower than using MAX, but I guess I can leave with that. Sigh... :)

With some try-catch magic I managed to get this to work across all models (stored in EAP and Database) but it's not pretty. If somebody has a better solution, please share it.

Thanks Geert and Simon for your hints.

Marek

UPDATE:
Oh, and I forgot, I still would love to be able to get the time, not only the date. Anybody?  8-)
Title: Re: Last Modification Date
Post by: Geert Bellekens on August 24, 2011, 04:38:01 pm
Have you tried to explicitly get the different dateparts from the modified date?
(I know, that will be even more vendor specific)

Geert

PS. There is an indicator in the connectionstring that you can use to figure out wich kind of database you are working on.