Search in sources :

Example 1 with ValidationParameters

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;
    }
}
Also used : SurveyFileType(org.openforis.collect.model.SurveyFile.SurveyFileType) ValidationParameters(org.openforis.collect.manager.validation.SurveyValidator.ValidationParameters) CSVFileValidationResult(org.openforis.collect.io.metadata.collectearth.CSVFileValidationResult) CollectEarthGridTemplateGenerator(org.openforis.collect.io.metadata.collectearth.CollectEarthGridTemplateGenerator)

Example 2 with ValidationParameters

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;
    }
}
Also used : SurveyValidator(org.openforis.collect.manager.validation.SurveyValidator) CollectEarthSurveyValidator(org.openforis.collect.manager.validation.CollectEarthSurveyValidator) SurveyValidationResults(org.openforis.collect.manager.validation.SurveyValidator.SurveyValidationResults) Window(org.zkoss.zul.Window) ValidationParameters(org.openforis.collect.manager.validation.SurveyValidator.ValidationParameters) ConfirmEvent(org.openforis.collect.designer.viewmodel.SurveyValidationResultsVM.ConfirmEvent) FileNotFoundException(java.io.FileNotFoundException) SurveyStoreException(org.openforis.collect.persistence.SurveyStoreException) IOException(java.io.IOException)

Aggregations

ValidationParameters (org.openforis.collect.manager.validation.SurveyValidator.ValidationParameters)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ConfirmEvent (org.openforis.collect.designer.viewmodel.SurveyValidationResultsVM.ConfirmEvent)1 CSVFileValidationResult (org.openforis.collect.io.metadata.collectearth.CSVFileValidationResult)1 CollectEarthGridTemplateGenerator (org.openforis.collect.io.metadata.collectearth.CollectEarthGridTemplateGenerator)1 CollectEarthSurveyValidator (org.openforis.collect.manager.validation.CollectEarthSurveyValidator)1 SurveyValidator (org.openforis.collect.manager.validation.SurveyValidator)1 SurveyValidationResults (org.openforis.collect.manager.validation.SurveyValidator.SurveyValidationResults)1 SurveyFileType (org.openforis.collect.model.SurveyFile.SurveyFileType)1 SurveyStoreException (org.openforis.collect.persistence.SurveyStoreException)1 Window (org.zkoss.zul.Window)1