-
Notifications
You must be signed in to change notification settings - Fork 7
DataValidation
cgendreau edited this page Apr 5, 2013
·
2 revisions
All processors must implement a validation method from the DataProcessor
interface. The validation applied is a non-contextual validation. It means that it will only ensure that the data can be processed without errors. Contextual validations are out of the scope of the narwhal-processor.
##Usage Example using validation with multiple processors:
//register some processors
List<AbstractDataProcessor> allProcessorsList = new ArrayList<AbstractDataProcessor>();
allProcessorsList.add(new CountryProcessor());
allProcessorsList.add(new DateProcessor("eventDate", "eventStartYear", "eventStartMonth", "eventStartDay"));
MockRawOccurrenceModel mockRawModel = new MockRawOccurrenceModel();
mockRawModel.setCountry("u.s.a");
mockRawModel.setEventDate("2010-01-02");
boolean isValid = true;
for(AbstractDataProcessor currProcessor : allProcessorsList){
isValid = isValid && currProcessor.validateBean(mockRawModel,false,null,null);
}
System.out.println("Is valid? " + isValid);
//prints: Is valid? true
Example to display the reason why a value is not valid:
//register some processors
List<AbstractDataProcessor> allProcessorsList = new ArrayList<AbstractDataProcessor>();
allProcessorsList.add(new CountryProcessor());
allProcessorsList.add(new DateProcessor("eventDate", "eventStartYear", "eventStartMonth", "eventStartDay"));
MockRawOccurrenceModel mockRawModel = new MockRawOccurrenceModel();
mockRawModel.setCountry("u.s.a");
mockRawModel.setEventDate("2010-01-A");
boolean isValid = true;
ProcessingResult pr = new ProcessingResult();
for(AbstractDataProcessor currProcessor : allProcessorsList){
isValid = isValid && currProcessor.validateBean(mockRawModel,false,null,pr);
}
System.out.println("Is valid? " + isValid + ", Reason : " + pr.getErrorString());
//prints: Is valid? false, Reason : The date [2010-01-A] could not be processed.