Search in sources :

Example 1 with SurveyValidationResults

use of org.openforis.collect.manager.validation.SurveyValidator.SurveyValidationResults in project collect by openforis.

the class SurveyExportParametersVM method validateSurvey.

private void validateSurvey(CollectSurvey survey, SurveyValidator validator, final SuccessHandler successHandler, boolean showWarningConfirm) {
    SurveyValidationResults validationResults = validator.validate(survey);
    if (validationResults.isOk()) {
        successHandler.onSuccess();
    } else {
        final Window validationResultsPopUp = SurveyValidationResultsVM.showPopUp(validationResults, showWarningConfirm && !validationResults.hasErrors());
        validationResultsPopUp.addEventListener(SurveyValidationResultsVM.CONFIRM_EVENT_NAME, new EventListener<ConfirmEvent>() {

            public void onEvent(ConfirmEvent event) throws Exception {
                successHandler.onSuccess();
                closePopUp(validationResultsPopUp);
            }
        });
    }
}
Also used : SurveyValidationResults(org.openforis.collect.manager.validation.SurveyValidator.SurveyValidationResults) Window(org.zkoss.zul.Window) ConfirmEvent(org.openforis.collect.designer.viewmodel.SurveyValidationResultsVM.ConfirmEvent) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 2 with SurveyValidationResults

use of org.openforis.collect.manager.validation.SurveyValidator.SurveyValidationResults in project collect by openforis.

the class SurveySelectVM method publishSelectedSurvey.

@Command
public void publishSelectedSurvey(@ContextParam(ContextType.BINDER) final Binder binder) throws IOException {
    final CollectSurvey survey = loadSelectedSurvey();
    final CollectSurvey publishedSurvey = selectedSurvey.isPublished() ? surveyManager.getByUri(survey.getUri()) : null;
    SurveyValidator validator = getSurveyValidator(survey);
    SurveyValidationResults validationResults = validator.validateCompatibility(publishedSurvey, survey);
    if (validationResults.isOk()) {
        askConfirmThenPublishSurvey(survey, binder);
    } else {
        final Window validationResultsPopUp = SurveyValidationResultsVM.showPopUp(validationResults, !validationResults.hasErrors());
        validationResultsPopUp.addEventListener(SurveyValidationResultsVM.CONFIRM_EVENT_NAME, new EventListener<ConfirmEvent>() {

            public void onEvent(ConfirmEvent event) throws Exception {
                CollectSurvey survey = loadSelectedSurvey();
                askConfirmThenPublishSurvey(survey, binder);
                closePopUp(validationResultsPopUp);
            }
        });
    }
}
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) ConfirmEvent(org.openforis.collect.designer.viewmodel.SurveyValidationResultsVM.ConfirmEvent) CollectSurvey(org.openforis.collect.model.CollectSurvey) SurveyStoreException(org.openforis.collect.persistence.SurveyStoreException) IOException(java.io.IOException) Command(org.zkoss.bind.annotation.Command) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Example 3 with SurveyValidationResults

use of org.openforis.collect.manager.validation.SurveyValidator.SurveyValidationResults 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

IOException (java.io.IOException)3 ConfirmEvent (org.openforis.collect.designer.viewmodel.SurveyValidationResultsVM.ConfirmEvent)3 SurveyValidationResults (org.openforis.collect.manager.validation.SurveyValidator.SurveyValidationResults)3 Window (org.zkoss.zul.Window)3 FileNotFoundException (java.io.FileNotFoundException)2 CollectEarthSurveyValidator (org.openforis.collect.manager.validation.CollectEarthSurveyValidator)2 SurveyValidator (org.openforis.collect.manager.validation.SurveyValidator)2 SurveyStoreException (org.openforis.collect.persistence.SurveyStoreException)2 ValidationParameters (org.openforis.collect.manager.validation.SurveyValidator.ValidationParameters)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 Command (org.zkoss.bind.annotation.Command)1 GlobalCommand (org.zkoss.bind.annotation.GlobalCommand)1