My favorites | Sign in
Project Logo
             
New issue | Search
for
| Advanced search | Search tips
Issue 37: Adding validation rules at service layer
7 people starred this issue and may be notified of changes. Back to list
Status:  AwaitingInfo
Owner:  ----
Type-Enhancement
Priority-Low
Platform-SQL


Sign in to add a comment
 
Reported by shanon.mulley, May 31, 2008
I have modified NetTiers scripts in order to minimise my work. It would be
handy if these could be incorporated into standard NetTiers, so I thought
I'd put it up here to see if anyone thinks it is worthwhile.

Firstly, the issue I wanted to deal with:
Basically, my database has lots of validation rules. Most of these are
written at the service layer, as they involve checking details in other
records (so they cant go into the entity layer). This creates one minor
problem - these rules are not loaded by default when I retrieve records
from the database.  This means I am forever writting get overrides to
ensure data is retrieved with the rules in tact.

My solution:
I modified the nettiers scripts so they generate the following code.
In the ServiceBaseCore.generated.cs file, two new methods were created -
both called AddCustomRules (one for single entities, one for a list of
entities)

In all of the Service files (for each entity), all of the Get, Find, etc
methods have been modified so that they call AddCustomRules to everything
before returning it:
list = AddCustomRules(list);

By itself, this code does nothing (The generated AddCustomRules dont do
much on their own). But if I create an override for the AddCustomRules in a
service file (adding validation rules), these validation rules are
automatically added to all retreivals of the records/entities.

Now I look at this, and I'm thinking a few things:
1) The problem I'm trying to overcome cant be that unique - most databases
have complicated rules at the service layer.
2) My solution was not particularly difficult - before this I had zero
knowledge of CodeSmith script writing, and I wrote this in an afternoon.

This leads me to suspect that there could be another, more elegant way of
acheiving what I'm after.

So, my questions are:
1) Would my changes be appreciated within NetTiers?
2) If there is a more elegant solution for what I'm trying to do already in
NetTiers, what is it?


What version of .netTiers and CodeSmith are you using? - 2.2 711

Thanks.

Comment 1 by diegogravi, Aug 20, 2008
Hello Shannon,
What I did for my convenience is to add on the constructor of the entity a new method
where you can add the validation rules for each entity. This way, by modifying the
template of the entities.generated.cs, you can create the validation rules for string
required, regex, minlenght, maxlenght, etc according to the column involved. You can
iterate through the property AllowDBNull for each column to verify if it is a
required field or if you have to assign a minimum or maximum lenght to the specific
field (same process as in the entity.aspx template for the maxlength on textboxes).
Then, once you create an instance of an entity, all of the validation rules will be
added to the new entity and just by checking Entity.Validate() you will have every
broken rule (if broken) at a blink of an eye.
Hope this few lines helped you develop a suitable solution for your needs, I did it
this way and now it is working as expected. I am now working on extending the
properties for the columns to add custom validation from the very begining (like
regex for specific fields), when you select the properties for nettiers.cst.  :)

Regards,
DiegoGravi
Comment 3 by s...@pcug.org.au, Nov 04, 2008
Shanon - I would be keen to see what yoe have done to the templates. I am needign to 
do something similar, and it would be very handy to see how you did it. Would it be 
possible to get a copy of your changes?

Cheers

Paul Smith
psmith@pcug.org.au

Comment 4 by shanon.mulley, Nov 04, 2008
Paul,

I'm happy to share my changes, but I'm unsure of the best way to do this. My changes 
are based on what I think is v2.2.0.711 ( a tad old now).
Comment 5 by bniemyjski, Dec 07, 2008
Shanon,

Create a patch.
Upgrade to rev 715 and then reapply your patch as the folder was moved. 
From there all you have to do is hit the update button and update to the latest revision.
Owner: bniemyjski
Comment 6 by bniemyjski, Feb 02, 2009
Shanon,

If you submit your patch, I will upgrade it to the latest version.
Comment 7 by shanon.mulley, Feb 02, 2009
OK then. What is the best tool to use to make a patch? I usually use araxis for my 
comparing/merging needs, but it doesnt seem to have any kind of make patch option...
Comment 8 by bniemyjski, Feb 03, 2009
I would pull down the same revision via svn and then drag your files over. From here
right click in the root directory and make a patch via svn.

-Blake
Comment 9 by bniemyjski, May 25, 2009
(No comment was entered for this change.)
Status: AwaitingInfo
Owner: ---
Labels: -Type-Defect -Priority-Medium Type-Enhancement Priority-Low
Comment 10 by bniemyjski, May 25, 2009
(No comment was entered for this change.)
Labels: Platform-SQL
Sign in to add a comment

Hosted by Google Code