public abstract class AttributeValidatingTypeServiceBase extends Object
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.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
AttributeValidatingTypeServiceBase.TypeAttributeDefinition
A 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 |
AttributeValidatingTypeServiceBase.TypeAttributeValidationException |
| Constructor and Description |
|---|
AttributeValidatingTypeServiceBase() |
| Modifier and Type | Method and Description |
|---|---|
protected String |
createErrorString(String errorKey,
String... params)
creates an error String from the given errorKey and parameters.
|
protected List<String> |
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 String |
getAttributeErrorLabel(RemotableAttributeField definition)
Returns a String suitable for use in error messages to represent the given attribute.
|
protected Formatter |
getAttributeFormatter(RemotableAttributeField field)
Gets a
Formatter appropriate for the data type of the given field. |
protected Pattern |
getAttributeValidatingExpression(RemotableAttributeField field)
Gets the validation
Pattern for the given RemotableAttributeField. |
protected ConfigurationService |
getConfigurationService() |
protected DataDictionaryRemoteFieldService |
getDataDictionaryRemoteFieldService() |
protected DataDictionaryService |
getDataDictionaryService() |
protected DictionaryValidationService |
getDictionaryValidationService() |
protected abstract List<AttributeValidatingTypeServiceBase.TypeAttributeDefinition> |
getTypeAttributeDefinitions(String typeId)
Retrieves active type attribute definitions and translates them into a module-independent representation.
|
protected List<RemotableAttributeError> |
validateAttributeFormat(RemotableAttributeField field,
String objectClassName,
String attributeName,
String attributeValue,
String errorKey)
Validates the format of the value for the given attribute field.
|
protected List<RemotableAttributeError> |
validateAttributeRequired(RemotableAttributeField field,
String objectClassName,
String attributeName,
Object attributeValue,
String errorKey)
Validates required-ness of an attribute against its corresponding value
|
List<RemotableAttributeError> |
validateAttributes(String typeId,
Map<String,String> attributes)
This is the default implementation.
|
protected List<RemotableAttributeError> |
validateDataDictionaryAttribute(AttributeValidatingTypeServiceBase.TypeAttributeDefinition typeAttributeDefinition,
String attributeName,
String value)
Validates the attribute value for the given
AttributeValidatingTypeServiceBase.TypeAttributeDefinition having a componentName. |
protected abstract List<RemotableAttributeError> |
validateNonDataDictionaryAttribute(RemotableAttributeField attr,
String key,
String value)
Validates an attribute that is *not* mapped to a data dictionary component via
AttributeValidatingTypeServiceBase.TypeAttributeDefinition.componentName and AttributeValidatingTypeServiceBase.TypeAttributeDefinition.name. |
protected List<RemotableAttributeError> |
validatePrimitiveAttributeFromDescriptor(AttributeValidatingTypeServiceBase.TypeAttributeDefinition typeAttributeDefinition,
String componentName,
Object object,
PropertyDescriptor propertyDescriptor)
Validates a data dictionary mapped attribute for a primitive property.
|
protected List<RemotableAttributeError> |
validateReferencesExistAndActive(Map<String,AttributeValidatingTypeServiceBase.TypeAttributeDefinition> typeAttributeDefinitionMap,
Map<String,String> attributes,
List<RemotableAttributeError> previousValidationErrors)
Cross-validates referenced components amongst attributes to ensure they refer to existing and active
business objects.
|
public AttributeValidatingTypeServiceBase()
protected abstract List<AttributeValidatingTypeServiceBase.TypeAttributeDefinition> getTypeAttributeDefinitions(String typeId)
typeId - the identifier for the typeprotected abstract List<RemotableAttributeError> validateNonDataDictionaryAttribute(RemotableAttributeField attr, String key, String value)
AttributeValidatingTypeServiceBase.TypeAttributeDefinition.componentName and AttributeValidatingTypeServiceBase.TypeAttributeDefinition.name.attr - the RemotableAttributeField for which to validate.key - the attribute namevalue - the attribute valueRemotableAttributeErrors with fully resolved error messages (not error keys). May
return null or an empty List if no errors are encountered.public List<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 calls
validateNonDataDictionaryAttribute(org.kuali.rice.core.api.uif.RemotableAttributeField, String, String)
or validateDataDictionaryAttribute(AttributeValidatingTypeServiceBase.TypeAttributeDefinition, String, String)
as appropriate. Lastly it calls validateReferencesExistAndActive(java.util.Map, java.util.Map, java.util.List).
typeId - the identifier for the typeattributes - the Map of attribute names to valuesRemotableAttributeErrors) encountered during validation.protected List<RemotableAttributeError> validateReferencesExistAndActive(Map<String,AttributeValidatingTypeServiceBase.TypeAttributeDefinition> typeAttributeDefinitionMap, Map<String,String> attributes, List<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 DataDictionaryService to get relationship information. Then, through the
DictionaryValidationService it 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 to
extractErrorsFromGlobalVariablesErrorMap(String)
TODO: who can explain this? :-)
typeAttributeDefinitionMap - a Map from attribute name to AttributeValidatingTypeServiceBase.TypeAttributeDefinition containing 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.protected static String getAttributeErrorLabel(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.
definition - the definition for which to create an error label.protected String createErrorString(String errorKey, String... params)
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 using MessageFormat.format(String, Object...). If the errorKey can't be
resolved, it will return a string like the following: errorKey:param1;param2;param3;
errorKey - the errorKeyparams - the error paramsprotected List<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 DataDictionaryService if it is
from a specific set of types defined in TypeUtils. Then, if the value is not blank, it checks for errors by
calling
validateAttributeFormat(org.kuali.rice.core.api.uif.RemotableAttributeField, String, String, String, String).
If it is blank, it checks for errors by calling
validateAttributeRequired(org.kuali.rice.core.api.uif.RemotableAttributeField, String, String, Object, String)
.
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 toRemotableAttributeErrors) encountered during validation. Cannot return null.protected List<RemotableAttributeError> validateAttributeRequired(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
RemotableAttributeField is required. If it is, a RemotableAttributeError is created
with the message populated by a call to createErrorString(String, String...).
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 fieldRemotableAttributeErrors) encountered during validation. Cannot return null.protected Pattern getAttributeValidatingExpression(RemotableAttributeField field)
Gets the validation Pattern for the given RemotableAttributeField.
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.
protected Formatter getAttributeFormatter(RemotableAttributeField field)
Gets a Formatter appropriate for the data type of the given field.
This implementation returns null if RemotableAttributeField.getDataType()
returns null. Otherwise, it returns the result of calling Formatter.getFormatter(Class) on the
DataType's type
protected List<RemotableAttributeError> validateAttributeFormat(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 Pattern returned by
getAttributeValidatingExpression(org.kuali.rice.core.api.uif.RemotableAttributeField)). If that doesn't
match, it will use the Formatter returned by
getAttributeFormatter(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 the
RemotableAttributeError that is generated.
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 toRemotableAttributeErrors) that are detected.protected List<String> 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.
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
attributeName - the attribute name for which to extract errors from the global error map.protected List<RemotableAttributeError> validateDataDictionaryAttribute(AttributeValidatingTypeServiceBase.TypeAttributeDefinition typeAttributeDefinition, String attributeName, String value)
Validates the attribute value for the given AttributeValidatingTypeServiceBase.TypeAttributeDefinition having a componentName.
This implementation instantiates a component object using reflection on the class name specified in the
AttributeValidatingTypeServiceBase.TypeAttributeDefinitions componentName, gets a PropertyDescriptor for 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 to
validatePrimitiveAttributeFromDescriptor(AttributeValidatingTypeServiceBase.TypeAttributeDefinition, String, Object, java.beans.PropertyDescriptor).
typeAttributeDefinition - attributeName - value - protected DictionaryValidationService getDictionaryValidationService()
protected DataDictionaryService getDataDictionaryService()
protected DataDictionaryRemoteFieldService getDataDictionaryRemoteFieldService()
protected ConfigurationService getConfigurationService()
Copyright © 2005–2018 The Kuali Foundation. All rights reserved.