General data record validation

Has anyone made anything approximating a general data record property validator?

It's easy enough to create one-off components to do validation of a few specific properties, but as the property list gets longer and the rules get a little more convoluted, it's a bit of a hassle. So, I was trying to come up with a good model so I could specify property names and associated validation rules. I'd like to at least be able to answer these kinds of questions of a property:


  • It is defined and has a non-zero string length
  • It is numeric
  • It has a numeric value between X and Y
  • It is required only if another property is present
  • Its value matches a regular expression


Does anyone have any ideas for modeling these rules in a component parameter?

I was thinking of something like this, in a TextType parameter:


PropertyA;required PropertyB;requiredif;PropertyA is defined and isnumber(PropertyA) PropertyC;regex;^[A-P]\\d{2}\\\$



It's not pretty, but it's relatively concise, and I'd have some backing script in a custom manipulator to do the dirty work. I'm open to better suggestions! I just think I need a better way to enforce that all properties are in a valid state in my protocols.
Answers 5
MK
MK 2010-04-14
Looks like you want one component that checks everything based on a single TextType Parameter value.

From experience, that makes code maintenance a little harder as someone (in the future, maybe even yourself) actually has to go back, hope you wrote a manual for it, and read it to figure out 'how to encode the string'.

Another idea is to have a generic component that checks an individual property with all the 'options' setup as different Parameters.

(see attached protocol)
it is not fully implemented, but you should get the idea.

PS - a third idea is to have yours be a wrapper for mine.
comment imagecomment image
HP
HP 2010-04-14
Well, yeah, I think I do want a single component and a single parameter, because I have a very wide property list, and I ultimately want another component to be able to write these rules, though that's not a requirement right now.

I agree with you that it might be simpler from a user's perspective to have a nice interface like this, and that might be what I end up doing, especially since the UI now simplifies copying grouped parameters. Pre-7.0 that would have been impossible. Since I'm the main audience for this component, I guess I'm valuing functionality and quick authoring of rules over general usability. This is for me! My users be damned!
DH
DH 2010-04-16
Chris,

Interesting problem.

Essentially, it seems you're creating your own constraint definition language here. I googled to see if there are any already-defined languages you could leverage, and the closest thing I found is Object Constraint Language, but this looks pretty heavy for your purposes. Also, it doesn't leverage knowledge of PilotScript, nor did I see a reference implementation thet you could just grab and use.

As long as you keep the syntax simple and document it in the parameter help, I don't think maintenance should be too big a problem. For increased usability (if needed), you could create an interactive report that takes some number of data records as input, displays all the properties found on the records, and lets you choose your constraints for each property. It could then output either a string you could paste into your constraint-checker component, or (if you want to get fancy) use the Component Reader/Writer to create a tailored version of the constraint-checker that you could then drag in wherever you need it.

Would anyone else find this sort of component useful? Specifically, should we at Accelrys devote some thought to providing something like this? Or is it sufficient for you to just encode your constraints in PilotScript within a Custom Filter?
LB
LB 2010-04-16
Yes, I would vote for that.

One bit of scope creep: consider application to array properties.
Number of values in a range
All values of same data type

Thanks!
Leo
HP
HP 2010-04-17
Count my vote, please!

I rolled my own and it was about 50 lines of pilotscript and some run-to-completion silliness. It surely could be made more efficient, but it's not even close to the rate limiting step for me, so I'm happy with it.

I didn't intentionally address anything in Leo's list, but those could be handled with some pilotscript expressions if needed. The ones I need now are all really short one-liners, so it's not a big deal. I agree with Leo, though, that it'd be nice to have simpler ways to validate arrays... I just don't really need them all that often.

I have rules for verifying required fields, verifying that a value is in an enumerated list, verifying that a field is required if an expression evaluates to true, verifying a property is NOT present, verifying a property is numeric, and verifying a property matches a regular expression.