Author Topic: Model validation from an add-in  (Read 16521 times)

MeryemAdb

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
Model validation from an add-in
« 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.

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Model validation from an add-in
« Reply #1 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
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

Sorno

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
Re: Model validation from an add-in
« Reply #2 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
« Last Edit: September 04, 2014, 08:00:50 pm by Sorno »

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: Model validation from an add-in
« Reply #3 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.

Sorno

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
Re: Model validation from an add-in
« Reply #4 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'";
« Last Edit: September 04, 2014, 08:50:45 pm by Sorno »

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: Model validation from an add-in
« Reply #5 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();

Sorno

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
Re: Model validation from an add-in
« Reply #6 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


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Model validation from an add-in
« Reply #7 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.

Sorno

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
Re: Model validation from an add-in
« Reply #8 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:


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.
« Last Edit: September 04, 2014, 11:21:33 pm by Sorno »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Model validation from an add-in
« Reply #9 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>
« Last Edit: September 05, 2014, 03:51:51 am by qwerty »

Sorno

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
Re: Model validation from an add-in
« Reply #10 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

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Model validation from an add-in
« Reply #11 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>
« Last Edit: September 05, 2014, 07:42:20 pm by qwerty »

Sorno

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
Re: Model validation from an add-in
« Reply #12 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);

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Model validation from an add-in
« Reply #13 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.

Sorno

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
Re: Model validation from an add-in
« Reply #14 on: September 05, 2014, 08:22:35 pm »
C#