Skip to content

Commit

Permalink
Merge pull request #791 from darkv/validation_patch
Browse files Browse the repository at this point in the history
Makes NSValidation-related methods consistent, and improves documentation.
  • Loading branch information
paulhoadley authored Aug 7, 2016
2 parents aedd949 + 7eeb408 commit 97803f0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@
* }
* );
* }</code></pre>
* If you have validation methods in your EO classes (e.g. <code>validateName(String name)</code> for attribute <i>name</i>)
* be aware that those are executed first and that they possibly coerce the value to validate (e.g. making a string uppercase).
* The validations done by this class will be executed on those potentially coerced values.
* <p>
* This code is mainly a quick-and-dirty rewrite from PRValidation by Proteon.
* <p>
* Additionally, this class adds a concept of "Default" values that get pushed into the object at creation time.
Expand Down Expand Up @@ -185,7 +189,6 @@
* If you wish to provide your own class description subclass
* see the documentation associated with the Factory inner class.
*/

public class ERXEntityClassDescription extends EOEntityClassDescription {
/**
* Do I need to update serialVersionUID?
Expand Down Expand Up @@ -919,6 +922,16 @@ protected boolean validateObjectValueDictWithInfo(ValidationObjectValue values,
return true;
}

/**
* Validates a specific property of an EO by applying the rules found in the userInfo
* of the entity i.e. model driven validations. See class description for more info
* on it.
*
* @param object the EO validation is done for
* @param value the value to validate
* @param validationTypeString the key for the validation info from userInfo
* @param property the property key to validate
*/
public void validateObjectWithUserInfo(EOEnterpriseObject object, Object value, String validationTypeString, String property) {
if(_validationInfo != null) {
NSArray qualifiers = (NSArray)_validationInfo.valueForKeyPath(validationTypeString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1102,8 +1102,15 @@ public Object handleQueryWithUnboundKey(String key) {
* validateValueForKey on the object's class description. The class
* description for this object should be an
* {@link ERXEntityClassDescription} or subclass. It is that class that
* provides the hooks to convert model throw validation exceptions into
* provides the hooks to convert model thrown validation exceptions into
* {@link ERXValidationException} objects.
* <p>
* The order of validation processed is, if applicable:
* <ol>
* <li>EO class validation methods (e.g. <code>User.validateName()</code>)</li>
* <li>model driven validation (see {@link ERXEntityClassDescription})</li>
* <li>Partial's class validation methods</li>
* </ol>
*
* @param value
* to be validated for a given attribute or relationship
Expand All @@ -1124,7 +1131,7 @@ public Object validateValueForKey(Object value, String key) throws NSValidation.
result = super.validateValueForKey(value, key);
EOClassDescription cd = classDescription();
if (cd instanceof ERXEntityClassDescription) {
((ERXEntityClassDescription) cd).validateObjectWithUserInfo(this, value, "validateForKey." + key, key);
((ERXEntityClassDescription) cd).validateObjectWithUserInfo(this, result, "validateForKey." + key, key);
}
result = _validateValueForKey(result, key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@
import er.extensions.eof.ERXGenericRecord;

/**
* <p>
* For overview information on partials, read the {@code package.html} in
* {@code er.extensions.partials}.
* </p>
*
* <p>
* {@code ERXPartialGenericRecord} is the base class of any entity that allows
* itself to be extended with partials.
* </p>
*
* @author mschrag
*/
Expand Down Expand Up @@ -201,7 +197,7 @@ public void awakeFromFetch(EOEditingContext editingContext) {
protected Object _validateValueForKey(Object value, String key) throws ValidationException {
Object result = value;
for (ERXPartial partial : _partials()) {
result = partial.validateValueForKey(value, key);
result = partial.validateValueForKey(result, key);
}
return result;
}
Expand All @@ -211,7 +207,7 @@ public Object validateTakeValueForKeyPath(Object value, String keyPath) throws V
Object result = super.validateTakeValueForKeyPath(value, keyPath);
for (ERXPartial partial : _partials()) {
if (partial.isPartialKeypath(keyPath)) {
result = partial.validateTakeValueForKeyPath(value, keyPath);
result = partial.validateTakeValueForKeyPath(result, keyPath);
}
}
return result;
Expand Down

0 comments on commit 97803f0

Please sign in to comment.