Validation (Optional)
Overview
Version: 1.4.*
Validate row data or entity objects before writing to the database. The validation method must return a boolean. If it returns false, the import process skips that row or object.
| Version | Attribute | Description |
|---|---|---|
| 1.4.* | id | Identifier for this validation. Must match the validationId on the target mapping. |
Example: referencing the validation from a mapping:
<mapping sheet="Bucket" id="brand" validationId="brand">
...
</mapping>
Validate a Row by Plugin Method
<validations>
<validation id="brand" value="plugin(globalName='com.priint.project.demo.somfy.datamapping.ImportTransformPlugin',methodName='validateEntityData')"/>
</validations>
Implement the method the same way as a transformation plugin method.
Validate a Row by Static Method
<validations>
<validation id="brand" value="static(className='com.priint.project.demo.somfy.utils.TransformUtils',methodName='validateEntityData')"/>
</validations>
Implement the method the same way as a transformation static method.
Validate an Object by Plugin Method
The import process passes the entity object (bucket, key value, text, etc.) to the method as the input parameter. The method must check the object type and validate accordingly.
<validations>
<validation id="brand" type="object" value="plugin(globalName='com.priint.project.demo.somfy.datamapping.ImportTransformPlugin',methodName='validateEntityObject')"/>
</validations>
@Stateless(mappedName = ImportTransformPlugin.MAPPED_NAME)
@LocalBean
@PubServerPlugin
public class ImportTransformPlugin extends SomfyPlugin {
public static final String MAPPED_NAME = Constants.PACKAGE_NAME + "datamapping.ImportTransformPlugin";
private static final Logger logger = LoggerFactory.getLogger(ImportTransformPlugin.class);
/**
* return true/false after validate an object
* @param object any kind object: bucket/keyvalue...
* @return boolean value
*/
public boolean validateEntityObject(Object object) {
boolean valid = true;
if (object instanceof Bucket){
final Bucket bucket = (Bucket) object;
logger.debug("{}: validateEntityObject: bucket info:{}", ImportTransformPlugin.class.getSimpleName(), bucket);
if (StringUtils.isBlank(bucket.getEntityIdentifier()))
valid = false;
}
logger.debug("{}: validateEntityObject: return value:{}", ImportTransformPlugin.class.getSimpleName(), valid);
return valid;
}
}
Validate an Object by Static Method
<validations>
<validation id="brand" type="object" value="static(className='com.priint.project.demo.somfy.datamapping.ImportTransformPlugin',methodName='validateEntityObject')"/>
</validations>
public final class TransformUtils {
private static final Logger logger = LoggerFactory.getLogger(TransformUtils.class);
private TransformUtils() {
throw new IllegalStateException("Utility class");
}
/**
* return true/false after validate an object
* @param object any kind object: bucket/keyvalue...
* @return boolean value
*/
public boolean validateEntityObject(Object object) {
boolean valid = true;
if (object instanceof Bucket){
final Bucket bucket = (Bucket) object;
logger.debug("{}: validateEntityObject: bucket info:{}", TransformUtils.class.getSimpleName(), bucket);
if (StringUtils.isBlank(bucket.getEntityIdentifier()))
valid = false;
}
logger.debug("{}: validateEntityObject: return value:{}", TransformUtils.class.getSimpleName(), valid);
return valid;
}
}