Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: MeryemAdb on July 22, 2014, 10:45:26 pm

Title: Model validation from an add-in
Post by: MeryemAdb on July 22, 2014, 10:45:26 pm
Hello,

I am trying to add my own validation rules from my add-in. However, I would also like to be able to select the rules to use individually and not on a category basis, and I have my own window to display the errors.

So I intend to catch the events EA_OnStartValidation and EA_OnEndValidation and only fire my code if my own category (I only define one category at EA level) is in the parameter array.  The thing is, no matter what categories I select in the model validation configuration, the parameter array contains my custom category, and my category only.

Is it the expected behaviour? In that case, how can I know that my category has been selected?

By the way, is there a way to configure the validation from an add-in? I mean that if the user clicks in one of my custom menus, the validation will be launched only on my category of rules.
Title: Re: Model validation from an add-in
Post by: Helmut Ortmann on July 23, 2014, 04:43:39 am
Hi,

in the Online Help you find an example if you search for:
Model Validation Example

Some years ago I developed a complex and configurable validation. I just started with the above example. If I remember correct configuration of categories works find.

For (de)selecting and parameterizing rules I used a little Access DB with default values.

It's no rocket science but it's some work of course.

Helmut
Title: Re: Model validation from an add-in
Post by: Sorno on September 04, 2014, 07:50:52 pm
When writing these rules do you use the API or SQL-queries?

I was wondering about the efficiency of validation if you need to do alot of looping through elements? I tried to do a check with Repository.SQLQuery but if used during validation it throws this error in EA:

Error:
Code = 0x0
Source = Line : 0; Char: 0
Error description = (null)

I get a reply from the SQL query so it works. It seems that the mere present of Repository.SQLQuery throws an error.

Using EA 10.0.1010
Title: Re: Model validation from an add-in
Post by: Tehila1 on September 04, 2014, 08:33:01 pm
Quote
When writing these rules do you use the API or SQL-queries?

I was wondering about the efficiency of validation if you need to do alot of looping through elements? I tried to do a check with Repository.SQLQuery but if used during validation it throws this error in EA:

Error:
Code = 0x0
Source = Line : 0; Char: 0
Error description = (null)

I get a reply from the SQL query so it works. It seems that the mere present of Repository.SQLQuery throws an error.

Using EA 10.0.1010

Please post the SQL query that fails.
Title: Re: Model validation from an add-in
Post by: Sorno on September 04, 2014, 08:47:58 pm
Ah.. the error was in the SQL query. I tried to use SELECT COUNT (*) - I guess the API doesn't like that.

The Repository.SQLQuery still returned an answer so I thought it was OK:

<?xml version="1.0"?>
<EADATA version="1.0" exporter="Enterprise Architect">
      <Dataset_0><Data><Row/></Data></Dataset_0></EADATA>

But I see now that its empty, which it should not be.
 

The query:
"SELECT COUNT(*) " +
                        "FROM t_connector " +
                        "WHERE t_connector.End_Object_ID=\'" + Element.ElementID + "\' " +
                        "AND t_connector.Stereotype = 'Architecture'";
Title: Re: Model validation from an add-in
Post by: Tehila1 on September 04, 2014, 09:06:04 pm
The COUNT(*) is not problematic.
The query throws error since something else is wrong.
I tried to run it in the built-in builder and it fails.

Why do you add '/' before the End Object ID?

I tried the following query and it works:  
Code: [Select]
string query = "SELECT COUNT(*) FROM  t_connector
WHERE  t_connector.Stereotype LIKE 'Architecture'  
AND t_connector.End_Object_ID =" +  Element.ElementID.ToString();
Title: Re: Model validation from an add-in
Post by: Sorno on September 04, 2014, 09:28:21 pm
Did you run it as part of a model validation ? My query is executed as part of a model validation rule.

Why I ask is that I get the same error with your query as with mine, when executed this way. The /' before the Object ID is to add ' before and after the ID. I reckon objectID.tostring() works equally, or better. :)

The exact query during runtime is:
SELECT COUNT(*) FROM  t_connector WHERE  t_connector.Stereotype LIKE 'Architecture' AND t_connector.End_Object_ID =19

And it throws the same strange error dialog as before. It only throws this if I use count (*),  the following query works:
SELECT * FROM  t_connector WHERE  t_connector.Stereotype LIKE 'Architecture' AND t_connector.End_Object_ID =19

Title: Re: Model validation from an add-in
Post by: qwerty on September 04, 2014, 10:57:39 pm
Quote
The query:
"SELECT COUNT(*) " +
                        "FROM t_connector " +
                        "WHERE t_connector.End_Object_ID=\'" + Element.ElementID + "\' " +
                        "AND t_connector.Stereotype = 'Architecture'";
Your above query compares End_Object_ID as being a string. But it is an integer. So the query will fail with a type mismatch.

q.
Title: Re: Model validation from an add-in
Post by: Sorno on September 04, 2014, 11:19:19 pm
I appreciate the help you're giving, but I don't think the problem is the SQL query per se.

The query works fine when it's "SELECT *", but it does not work when it's "SELECT Count(*)". EA usually throws an nice error explaining that there is an error with a SQL query if this is the case. One way or the other the problem is not in regards to the ObjectID. I get the same results with Element.ElementID.ToString() or even if I hardcode an ID.

The error I'm getting is this:
(http:// http://i57.tinypic.com/14ipjmf.png )

Are you sure it's possible to do a SELECT COUNT(*) with repository.SQLQuery? By the way, I tried to do a Count outside validation with the same error as result.
Title: Re: Model validation from an add-in
Post by: qwerty on September 05, 2014, 03:47:03 am
Those errors are connected to XMI processing.

q.

P.S. The SQLQuery returned the following in my test:
Quote
<?xml version="1.0"?>

<EADATA version="1.0" exporter="Enterprise Architect">

      <Dataset_0><Data><Row><Expr1000>1</Expr1000></Row></Data></Dataset_0></EADATA>
Title: Re: Model validation from an add-in
Post by: Sorno on September 05, 2014, 06:16:16 pm
Ah, now we're talking.

Thanks for the info. Yes, that would be the output I would expect. But for some reason my EA don't return that, but:
Code: [Select]
<?xml version="1.0"?>
<EADATA version="1.0" exporter="Enterprise Architect">
      <Dataset_0><Data><Row/></Data></Dataset_0></EADATA>

Using EA 10.0.1010
Title: Re: Model validation from an add-in
Post by: qwerty on September 05, 2014, 07:40:27 pm
That's maybe because the query is failing for some reason. Please try to supply a "handmade" query and see what that returns.

q.

P.S. I tried with a bad SQL and got this:
Quote
<?xml version="1.0"?>

<EADATA version="1.0" exporter="Enterprise Architect">

</EADATA>
Title: Re: Model validation from an add-in
Post by: Sorno on September 05, 2014, 07:49:07 pm
Still the same error  :-/

Code: [Select]
                 string myQuery = "SELECT COUNT(*) FROM t_object";
                  string queryResult = Repository.SQLQuery(myQuery);
Title: Re: Model validation from an add-in
Post by: qwerty on September 05, 2014, 07:57:34 pm
Strange indeed. I just ran the same query (but with Perl) and it returned the right result. Which language is it you're using?

q.
Title: Re: Model validation from an add-in
Post by: Sorno on September 05, 2014, 08:22:35 pm
C#
Title: Re: Model validation from an add-in
Post by: Geert Bellekens on September 05, 2014, 08:43:04 pm
"Count(*)" is not standard SQL and doesn't work on all database types.
First make sure your query works in a real SQL Client and only then try it using Repository.SQLQuery()

Geert
Title: Re: Model validation from an add-in
Post by: qwerty on September 05, 2014, 09:36:46 pm
Oh. Is there any standard? I thought each vendor just invented its own flavor. iiRC IBM invented SQL in some of their labs. So I guess that there is some IBM standard for DB2. But there is no ISO standard or something like OMG?

q.
Title: Re: Model validation from an add-in
Post by: Geert Bellekens on September 05, 2014, 09:47:16 pm
Yes, there is ANSI SQL.
The most widely supported version is ANSI SQL:92, but according to wikipidia it goes up to ANSI SQL:20011

Geert
Title: Re: Model validation from an add-in
Post by: Sorno on September 05, 2014, 11:08:09 pm
I have tried the query directly towards the database, and it works.
The same error occurs both when using mySQL and MS SQL.

Have sent a question to Sparx regarding this.  I thank you for the help, it feels like we're shooting blind now. :) I hope Sparx have any ideas..
Title: Re: Model validation from an add-in
Post by: qwerty on September 05, 2014, 11:45:29 pm
Let us know the outcome.

q.
Title: Re: Model validation from an add-in
Post by: Sorno on September 11, 2014, 04:49:16 pm
Sparx have responded: Alias ...

The error is circumvented by explicit naming the COUNT-column with an alias.

Thank you again for the help.

Update: This is confirmed as a bug, present when not using a EAP-repository.

Title: Re: Model validation from an add-in
Post by: Sorno on September 13, 2014, 12:42:29 am
I have a new issue with model validation - the time it takes.

When I got SQL working I rewrote some code to optimize the time it would take to run the validation. Alas, it still took a rather long time, so I clocked it (manually).

I had created 6 rules (based on the example from Sparx) and it took over 240 sec to run the validation. I disabled all logic, so that the rules was activated but didn't do anything. The validation then took around 240 sec. Thus, the actual testing hardly affected the total time.

Next I tried to only use one rule, but running the same amount of logic as above (instead of relying on EAs built in ruleIDs I ran the tests depending stereotype). That took about 80 sec.

Last, I ran the validation without any rules at all, which took 75 sec.

It seems that EA's built-in functionality for validation is really, really slow. Is there any point in using the built-in functionality, or is it just better to do it yourself (since your already need an add-in to write the logic)?

I wonder if i'm doing it wrong and anyone else have another experience of it?
Title: Re: Model validation from an add-in
Post by: qwerty on September 13, 2014, 03:53:57 am
I guess the rules EA applies are rather complex (just have a look into Superstructures and you believe). Sparx is sticking quite strictly to what is written in Superstructures. So that might be the simple explanation. If you just want to verify your own ruleset you should skip the rest by implementing just those test via direct model inspection.

q.
Title: Re: Model validation from an add-in
Post by: KP on September 15, 2014, 09:29:51 am
You can switch off all rules except your own. I think it's Project > Model Validation > Configure Validation Rules. I would be interested to hear your timings with everything else switched off.
Title: Re: Model validation from an add-in
Post by: Geert Bellekens on September 15, 2014, 03:54:44 pm
I wrote my own modelvalidator, partly because the model validation objects weren't available at the time.

But I think I would make the same decision now as well.
I don't like the output the EA validation has, and it doesn't have enough flexibility in selecting what exactly you want to validate.

We have a HUGE model and validating it completely would probably take hours (or days). So I created a mechanism that allows to only validate the part that you touched for a certain request.

Geert
Title: Re: Model validation from an add-in
Post by: Sorno on September 15, 2014, 05:17:53 pm
My timing's are with everything else switch off.

So unless I missunderstand, the time is just for EA to check each element, diagram, and connection, and for each one see that there is no rule to run.

Title: Re: Model validation from an add-in
Post by: Geert Bellekens on September 15, 2014, 06:59:23 pm
Quote
My timing's are with everything else switch off.

So unless I missunderstand, the time is just for EA to check each element, diagram, and connection, and for each one see that there is no rule to run.

I can think of ways to make that more efficient ;D

Geert
Title: Re: Model validation from an add-in
Post by: qwerty on September 15, 2014, 07:55:24 pm
I just made a test with the example help model. With all turned off it takes 1:40 minutes and it spits out a hand full of warnings (why? didn't I tell him to check nothing?). With all turned on it takes 1:48 minutes.

That#s speaking for itself.

q.