ORM validate method

Hi,

I was just digging through the code and see that there is a validate
method in the BaseORMService which uses HyRule. I use ValidateThis for
my validations and wondered if it would be possible to be able to
choose which validation framework to use, like you can which Lightwire
and ColdSpring.

If you think this is a good idea, then I think it would also be nice
if ColdBox returned a standard Result object with hasErrors():boolean,
getErrors():Array methods as a starting point. I'd also propose an
optional "context" argument to the current validate method. Contexts
are great if you say have a user object which you want the username
and password fields to be required for the "login" context, and all
fields required for the "register" context. I don't think you can do
that with HyRule.

Anyway, I'd be happy to help out if I can if you want to explore this
further.

Thanks,

- John

As a follow up, looking at the ValidatorMessage.cfc it looks like there are some unscoped variables.

public string function getMessageByType(String type,Struct prop){
var messages = getMessages();
var errorMessage = “”;
var i = “”;

for(i=1; i <= arrayLen(messages); ++i){
if(messages[i].type == arguments.type){
if(!structKeyExists(arguments.prop,“display”)){
prop.display = humanize(prop.name);
}
errorMessage = replaceTemplateText(messages[i].message,prop);

}
}

return errorMessage;
}

and

private string function replaceTemplateText(String message,Struct prop){
var templates = reMatchNoCase("({)([\w])+?(})",arguments.message);
var m = arguments.message;
var i = “”;
var key = “”;

if( arrayLen(templates) ) {
// looop over the array, in each
for(var i=1; i<=arrayLen(templates); ++i){
var placeHolder = templates[i];
var property = reReplaceNoCase(placeHolder,"({)([\w]+)(})","\2");
// now we know the key we are looking for
for(key in prop) {
if(uCase(key) == ucase(property)){
m = replaceNoCase(m,placeHolder,prop[key],“all”);
}
}
}
}

return m;
}

I hope this is useful, Dan has done a great job with HyRule so I hope this isn’t taken as me being anti HyRule.

Thanks,

  • John

I’d also like to see this. :slight_smile:

Jason Durham

me too!!

I, for three, would love to see an official CB+VT integration!

Luis, what do you think about some kind of cb ValidationProvider here where we could configure and use on demand any available ValidationService that a client or I needs in a CB3 application… pretty please…

-Adam

Yea that’s what we discussed before. To create a spec for validation and then include one with coldbox. Then anybody can build an adapter for it or we could include some ourselves.

Community hlelp on this is welcomed :slight_smile:

OK, sounds cool and I'm happy to contribute if you can point me in the
right direction.

So, would this be just for ORM via the validate() method, or are you
thinking of making it available across ColdBox as ValidateThis can do
validation on standard CFCs, structs, ORM Entities and I think even
groovy objects.

- John

Well, I think as of now, this is wide open for 3.1 integration. So we can create a doc and plan it out. I want it super flexible and transparent. Also, maybe NOT including a validation at all, and making them download one and adapt it. Not sure.

But at least the adapters have them in play? Anyways, anybody want to take point on this one and we all contribute?

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Hi Luis, I like the idea of not including the validation frameworks (same as you do with Transfer / Reactor etc). To kick things off here’s a first draft of what the providers should implement.

<>
IValidationProvider

+validate( obj [, context] )
+setConfiguration( struct )
+configure()
+getValidator( classname )

although I haven’t really thought it through :slight_smile:

  • John

Mind, creating a google doc we can share so we can develop it

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Hi Luis,

I’ve started a basic doc:
https://docs.google.com/document/d/1xQdlcS3BvXTaqznJIP1BvEVC8xnN_i8Ruy7IjiX_KhI/edit?hl=en&authkey=CMr22-wF

If anyone else wants to contribute please let me know and I’ll make you an editor.

  • John

I would love to be involved in this. One of my objectives for the new year is to get Hyrule up to par but it has been hard because I have not had many people using it. Now that I have some projects coming up in ColdBox I would like to contribute to this.

For what its worth I also I think this should be pulled from the core and abstracted out. There should be a single service that we call and the validation framework can be configured from there. I also I have something pretty cool that I am working for the next version of Hyrule and I hope to share all of that here shortly.

Excellent!! John Wish is leading the cavalry here. But yes, the idea is to plug and play validation frameworks into the ORM services so it can be abstracted out. So we will be removing hyrule from the core for the 3.0 release, but we need to brainstorm on this for 3.1
Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Hey Dan / Luis,

Now that Scotch on the Rocks is out of the way, I've got some time to
look at this now. I know that 3.0.0. is pretty close to release so
might be best to start thinking about this once the release is out.
I'm happy to work on this, but I would like some input on what the
best way to integrate is with ColdBox.

Thanks.

- John

Yes, I Agree John,

I think we can target this for 3.1 as there are already over 50 tickets now for the next release.

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com