use of org.openforis.collect.manager.validation.SurveyValidator.ValidationParameters in project collect by openforis.
the class SurveyFileVM method validateFileContent.
private boolean validateFileContent(Binder binder) {
String typeName = getFormFieldValue(binder, SurveyFileFormObject.TYPE_FIELD_NAME);
SurveyFileType type = SurveyFileType.valueOf(typeName);
switch(type) {
case COLLECT_EARTH_GRID:
CollectEarthGridTemplateGenerator templateGenerator = new CollectEarthGridTemplateGenerator();
CSVFileValidationResult headersValidationResult = templateGenerator.validate(uploadedFile, survey, new ValidationParameters());
if (headersValidationResult.isSuccessful()) {
return true;
} else {
switch(headersValidationResult.getErrorType()) {
case INVALID_FILE_TYPE:
MessageUtil.showWarning("survey.file.error.invalid_file_type", "CSV (Comma Separated Values)");
// don't block the user
return true;
case INVALID_HEADERS:
MessageUtil.showWarning("survey.file.type.collect_earth_grid.error.invalid_file_structure", new Object[] { headersValidationResult.getExpectedHeaders().toString(), headersValidationResult.getFoundHeaders().toString() });
// don't block the user
return true;
case INVALID_NUMBER_OF_PLOTS_WARNING:
MessageUtil.showWarning("survey.file.error.warning_csv_size", CollectEarthGridTemplateGenerator.CSV_LENGTH_WARNING + "");
// don't block the user
return true;
case INVALID_NUMBER_OF_PLOTS_TOO_LARGE:
MessageUtil.showWarning("survey.file.error.error_csv_size", CollectEarthGridTemplateGenerator.CSV_LENGTH_ERROR + "");
// block the user , a file so large would make the CEP file unusable!
return false;
default:
return true;
}
}
default:
return true;
}
}
use of org.openforis.collect.manager.validation.SurveyValidator.ValidationParameters in project collect by openforis.
the class SurveyEditVM method checkValidity.
/**
* Returns true if the validation didn't give any errors, false if a confirm PopUp will be shown
*/
private boolean checkValidity(boolean showConfirm, final Runnable runIfValid, String confirmButtonLabel, boolean showWarnings) {
SurveyValidator surveyValidator = getSurveyValidator(survey);
ValidationParameters validationParameters = new ValidationParameters();
validationParameters.setWarnOnEmptyCodeLists(showWarnings);
validationParameters.setWarnOnUnusedCodeLists(showWarnings);
SurveyValidationResults results = surveyValidator.validate(survey, validationParameters);
if (results.hasErrors() || results.hasWarnings()) {
final Window validationResultsPopUp = SurveyValidationResultsVM.showPopUp(results, showConfirm, confirmButtonLabel);
validationResultsPopUp.addEventListener(SurveyValidationResultsVM.CONFIRM_EVENT_NAME, new EventListener<ConfirmEvent>() {
public void onEvent(ConfirmEvent event) throws Exception {
runIfValid.run();
closePopUp(validationResultsPopUp);
}
});
return false;
} else {
runIfValid.run();
return true;
}
}
Aggregations