Class AttributeValidatingTypeServiceBase
An abstract base class for type service implementations which provides default validation of attributes from the Data
Dictionary. It attempts to remain module independent by requiring the translation of the attribute definitions to a
generic format that includes the required RemotableAttributeFields as an unimplemented template method,
seegetTypeAttributeDefinitions(String).
Note that any RemotableAttributeErrors returned from here should be fully resolved to the messages to be
displayed to the user (in other words, they should not contain error keys). The same approach should be taken by
subclasses since the message resources may not be present on the remote server that is invoking this service.
There is a createErrorString(String, String...) utility method that can be used to resolve
errorKeys and format them appropriately.
- Author:
- Kuali Rice Team (rice.collab@kuali.org)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classA module-independent representation of a type attribute containing all the information that we need in order to validate data dictionary-based attributes.protected static class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringcreateErrorString(String errorKey, String... params) creates an error String from the given errorKey and parameters.extractErrorsFromGlobalVariablesErrorMap(String attributeName) Removes all errors for the given attributeName from the global error map, transforms them as appropriate and returns them as a List of Strings.protected static StringgetAttributeErrorLabel(org.kuali.rice.core.api.uif.RemotableAttributeField definition) Returns a String suitable for use in error messages to represent the given attribute.protected org.kuali.rice.core.web.format.FormattergetAttributeFormatter(org.kuali.rice.core.api.uif.RemotableAttributeField field) Gets aFormatterappropriate for the data type of the given field.protected PatterngetAttributeValidatingExpression(org.kuali.rice.core.api.uif.RemotableAttributeField field) Gets the validationPatternfor the givenRemotableAttributeField.protected org.kuali.rice.core.api.config.property.ConfigurationServiceprotected DataDictionaryRemoteFieldServiceprotected DataDictionaryServiceprotected DictionaryValidationServiceprotected abstract List<AttributeValidatingTypeServiceBase.TypeAttributeDefinition> getTypeAttributeDefinitions(String typeId) Retrieves active type attribute definitions and translates them into a module-independent representation.protected List<org.kuali.rice.core.api.uif.RemotableAttributeError> validateAttributeFormat(org.kuali.rice.core.api.uif.RemotableAttributeField field, String objectClassName, String attributeName, String attributeValue, String errorKey) Validates the format of the value for the given attribute field.protected List<org.kuali.rice.core.api.uif.RemotableAttributeError> validateAttributeRequired(org.kuali.rice.core.api.uif.RemotableAttributeField field, String objectClassName, String attributeName, Object attributeValue, String errorKey) Validates required-ness of an attribute against its corresponding valueList<org.kuali.rice.core.api.uif.RemotableAttributeError> validateAttributes(String typeId, Map<String, String> attributes) This is the default implementation.protected List<org.kuali.rice.core.api.uif.RemotableAttributeError> validateDataDictionaryAttribute(AttributeValidatingTypeServiceBase.TypeAttributeDefinition typeAttributeDefinition, String attributeName, String value) Validates the attribute value for the givenAttributeValidatingTypeServiceBase.TypeAttributeDefinitionhaving a componentName.protected abstract List<org.kuali.rice.core.api.uif.RemotableAttributeError> validateNonDataDictionaryAttribute(org.kuali.rice.core.api.uif.RemotableAttributeField attr, String key, String value) Validates an attribute that is *not* mapped to a data dictionary component viaAttributeValidatingTypeServiceBase.TypeAttributeDefinition.componentNameandAttributeValidatingTypeServiceBase.TypeAttributeDefinition.name.protected List<org.kuali.rice.core.api.uif.RemotableAttributeError> validatePrimitiveAttributeFromDescriptor(AttributeValidatingTypeServiceBase.TypeAttributeDefinition typeAttributeDefinition, String componentName, Object object, PropertyDescriptor propertyDescriptor) Validates a data dictionary mapped attribute for a primitive property.protected List<org.kuali.rice.core.api.uif.RemotableAttributeError> validateReferencesExistAndActive(Map<String, AttributeValidatingTypeServiceBase.TypeAttributeDefinition> typeAttributeDefinitionMap, Map<String, String> attributes, List<org.kuali.rice.core.api.uif.RemotableAttributeError> previousValidationErrors) Cross-validates referenced components amongst attributes to ensure they refer to existing and active business objects.
-
Constructor Details
-
AttributeValidatingTypeServiceBase
public AttributeValidatingTypeServiceBase()
-
-
Method Details
-
getTypeAttributeDefinitions
protected abstract List<AttributeValidatingTypeServiceBase.TypeAttributeDefinition> getTypeAttributeDefinitions(String typeId) Retrieves active type attribute definitions and translates them into a module-independent representation. Note that they should be returned in the order desired for display.- Parameters:
typeId- the identifier for the type- Returns:
- a correctly ordered List of active, module-independent type attribute definitions
-
validateNonDataDictionaryAttribute
protected abstract List<org.kuali.rice.core.api.uif.RemotableAttributeError> validateNonDataDictionaryAttribute(org.kuali.rice.core.api.uif.RemotableAttributeField attr, String key, String value) Validates an attribute that is *not* mapped to a data dictionary component viaAttributeValidatingTypeServiceBase.TypeAttributeDefinition.componentNameandAttributeValidatingTypeServiceBase.TypeAttributeDefinition.name.- Parameters:
attr- the RemotableAttributeField for which to validate.key- the attribute namevalue- the attribute value- Returns:
- a List of
RemotableAttributeErrors with fully resolved error messages (not error keys). May return null or an empty List if no errors are encountered.
-
validateAttributes
public List<org.kuali.rice.core.api.uif.RemotableAttributeError> validateAttributes(String typeId, Map<String, String> attributes) This is the default implementation. It calls into the service for each attribute to validate it there. No combination validation is done. That should be done by overriding this method.
This implementation calls
getTypeAttributeDefinitions(String)to retrieve module-agnostic representations. It then iterates through the entry set of attributes, and callsvalidateNonDataDictionaryAttribute(org.kuali.rice.core.api.uif.RemotableAttributeField, String, String)orvalidateDataDictionaryAttribute(AttributeValidatingTypeServiceBase.TypeAttributeDefinition, String, String)as appropriate. Lastly it callsvalidateReferencesExistAndActive(java.util.Map, java.util.Map, java.util.List).- Parameters:
typeId- the identifier for the typeattributes- the Map of attribute names to values- Returns:
- the List of errors (
RemotableAttributeErrors) encountered during validation.
-
validateReferencesExistAndActive
protected List<org.kuali.rice.core.api.uif.RemotableAttributeError> validateReferencesExistAndActive(Map<String, AttributeValidatingTypeServiceBase.TypeAttributeDefinition> typeAttributeDefinitionMap, Map<String, String> attributes, List<org.kuali.rice.core.api.uif.RemotableAttributeError> previousValidationErrors) Cross-validates referenced components amongst attributes to ensure they refer to existing and active business objects.
This implementation instantiates any components mapped by attributes, populates them as best it can, and then uses the
DataDictionaryServiceto get relationship information. Then, through theDictionaryValidationServiceit attempts to ensure that any referenced business objects mapped by other attributes exist and are active. It pulls any errors encountered out of the global error map via calls toextractErrorsFromGlobalVariablesErrorMap(String)TODO: who can explain this? :-)
- Parameters:
typeAttributeDefinitionMap- a Map from attribute name toAttributeValidatingTypeServiceBase.TypeAttributeDefinitioncontaining all of the attribute definitions for this type.attributes- the Map of attribute names to valuespreviousValidationErrors- a List of previously encountered errors used to short circuit testing on attributes that are already known to have errors.- Returns:
- the List of errors encountered. Cannot return null.
-
getAttributeErrorLabel
protected static String getAttributeErrorLabel(org.kuali.rice.core.api.uif.RemotableAttributeField definition) Returns a String suitable for use in error messages to represent the given attribute.
This implementation returns a String of the format "longLabel (shortLabel)" where those fields are pulled from the passed in definition.
- Parameters:
definition- the definition for which to create an error label.- Returns:
- the error label String.
-
createErrorString
creates an error String from the given errorKey and parameters.
This implementation will attempt to resolve the errorKey using the
ConfigurationService, and format it with the provided params usingMessageFormat.format(String, Object...). If the errorKey can't be resolved, it will return a string like the following: errorKey:param1;param2;param3;- Parameters:
errorKey- the errorKeyparams- the error params- Returns:
- error string
-
validatePrimitiveAttributeFromDescriptor
protected List<org.kuali.rice.core.api.uif.RemotableAttributeError> validatePrimitiveAttributeFromDescriptor(AttributeValidatingTypeServiceBase.TypeAttributeDefinition typeAttributeDefinition, String componentName, Object object, PropertyDescriptor propertyDescriptor) Validates a data dictionary mapped attribute for a primitive property.
This implementation checks that the attribute is defined using the
DataDictionaryServiceif it is from a specific set of types defined in TypeUtils. Then, if the value is not blank, it checks for errors by callingvalidateAttributeFormat(org.kuali.rice.core.api.uif.RemotableAttributeField, String, String, String, String). If it is blank, it checks for errors by callingvalidateAttributeRequired(org.kuali.rice.core.api.uif.RemotableAttributeField, String, String, Object, String).- Parameters:
typeAttributeDefinition- the definition for the attributecomponentName- the data dictionary component nameobject- the instance of the componentpropertyDescriptor- the descriptor for the property that the attribute maps to- Returns:
- a List of errors (
RemotableAttributeErrors) encountered during validation. Cannot return null.
-
validateAttributeRequired
protected List<org.kuali.rice.core.api.uif.RemotableAttributeError> validateAttributeRequired(org.kuali.rice.core.api.uif.RemotableAttributeField field, String objectClassName, String attributeName, Object attributeValue, String errorKey) Validates required-ness of an attribute against its corresponding value
This implementation checks if an attribute value is null or blank, and if so checks if the
RemotableAttributeFieldis required. If it is, aRemotableAttributeErroris created with the message populated by a call tocreateErrorString(String, String...).- Parameters:
field- the field for the attribute being testedobjectClassName- the class name for the componentattributeName- the name of the attributeattributeValue- the value of the attributeerrorKey- the errorKey used to identify the field- Returns:
- the List of errors (
RemotableAttributeErrors) encountered during validation. Cannot return null.
-
getAttributeValidatingExpression
protected Pattern getAttributeValidatingExpression(org.kuali.rice.core.api.uif.RemotableAttributeField field) Gets the validation
Patternfor the givenRemotableAttributeField.This implementation checks if there is a regexConstraint set on the field, and if so it compiles a Pattern (with no special flags) using it. Otherwise, it returns a pattern that always matches.
-
getAttributeFormatter
protected org.kuali.rice.core.web.format.Formatter getAttributeFormatter(org.kuali.rice.core.api.uif.RemotableAttributeField field) Gets a
Formatterappropriate for the data type of the given field.This implementation returns null if
RemotableAttributeField.getDataType()returns null. Otherwise, it returns the result of callingFormatter.getFormatter(Class)on theDataType's type- Parameters:
field- the field for which to provide aFormatter.- Returns:
- an applicable
Formatter, or null if one can't be found.
-
validateAttributeFormat
protected List<org.kuali.rice.core.api.uif.RemotableAttributeError> validateAttributeFormat(org.kuali.rice.core.api.uif.RemotableAttributeField field, String objectClassName, String attributeName, String attributeValue, String errorKey) Validates the format of the value for the given attribute field.
This implementation checks if the attribute value is not blank, in which case it checks (as applicable) the max length, min length, min value, max value, and format (using the
Patternreturned bygetAttributeValidatingExpression(org.kuali.rice.core.api.uif.RemotableAttributeField)). If that doesn't match, it will use the Formatter returned bygetAttributeFormatter(org.kuali.rice.core.api.uif.RemotableAttributeField)to format the value and try matching against it again. For each format error that is found,createErrorString(String, String...)is called to prepare the text for theRemotableAttributeErrorthat is generated.- Parameters:
field- the field for the attribute whose value we are validatingobjectClassName- the name of the class to which the attribute belongsattributeName- the name of the attributeattributeValue- the String value whose format we are validatingerrorKey- the name of the property on the object class that this attribute maps to- Returns:
- a List containing any errors (
RemotableAttributeErrors) that are detected.
-
extractErrorsFromGlobalVariablesErrorMap
Removes all errors for the given attributeName from the global error map, transforms them as appropriate and returns them as a List of Strings.
This implementation iterates through any errors found in the error map, transforms them by calling
createErrorString(String, String...)and adds them to the List that is then returned- Parameters:
attributeName- the attribute name for which to extract errors from the global error map.- Returns:
- a List of error Strings
-
validateDataDictionaryAttribute
protected List<org.kuali.rice.core.api.uif.RemotableAttributeError> validateDataDictionaryAttribute(AttributeValidatingTypeServiceBase.TypeAttributeDefinition typeAttributeDefinition, String attributeName, String value) Validates the attribute value for the given
AttributeValidatingTypeServiceBase.TypeAttributeDefinitionhaving a componentName.This implementation instantiates a component object using reflection on the class name specified in the
AttributeValidatingTypeServiceBase.TypeAttributeDefinitions componentName, gets aPropertyDescriptorfor the attribute of the component object, hydrates the attribute's value from it's String form, sets that value on the component object, and then delegates tovalidatePrimitiveAttributeFromDescriptor(AttributeValidatingTypeServiceBase.TypeAttributeDefinition, String, Object, java.beans.PropertyDescriptor).- Parameters:
typeAttributeDefinition-attributeName-value-- Returns:
-
getDictionaryValidationService
-
getDataDictionaryService
-
getDataDictionaryRemoteFieldService
-
getConfigurationService
protected org.kuali.rice.core.api.config.property.ConfigurationService getConfigurationService()
-