Search in sources :

Example 1 with SurveyValidator

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

the class AttributeDefinitionFormValidator method validateReferencedAttribute.

private void validateReferencedAttribute(ValidationContext ctx) {
    String referencedAttributePath = getValue(ctx, REFERENCED_ATTRIBUTE_PATH_FIELD, false);
    if (StringUtils.isNotBlank(referencedAttributePath)) {
        AttributeDefinition attrDef = (AttributeDefinition) getEditedNode(ctx);
        CollectSurvey survey = attrDef.getSurvey();
        AttributeDefinition referencedAttribute = (AttributeDefinition) survey.getSchema().getDefinitionByPath(referencedAttributePath);
        if (referencedAttribute == null) {
            addInvalidMessage(ctx, REFERENCED_ATTRIBUTE_PATH_FIELD, Labels.getLabel(REFERENCED_ATTRIBUTE_DELETED_MESSAGE_KEY));
        } else {
            SurveyValidationResult validationResult = new SurveyValidator().validateReferencedKeyAttribute(attrDef, referencedAttribute);
            if (validationResult.getFlag() == Flag.ERROR) {
                addInvalidMessage(ctx, REFERENCED_ATTRIBUTE_PATH_FIELD, Labels.getLabel(validationResult.getMessageKey(), validationResult.getMessageArgs()));
            }
        }
    }
}
Also used : SurveyValidationResult(org.openforis.collect.manager.validation.SurveyValidator.SurveyValidationResult) SurveyValidator(org.openforis.collect.manager.validation.SurveyValidator) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 2 with SurveyValidator

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

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

the class NodeDefinitionFormValidator method validateName.

protected boolean validateName(ValidationContext ctx) {
    boolean valid = validateRequired(ctx, NAME_FIELD);
    if (valid) {
        EntityDefinition parentEntity = getParentEntity(ctx);
        String name = getValue(ctx, NAME_FIELD);
        CollectSurvey survey = getEditedNode(ctx).getSurvey();
        if (survey.getTarget() == SurveyTarget.COLLECT_EARTH) {
            CollectEarthSurveyValidator collectEarthSurveyValidator = new CollectEarthSurveyValidator();
            if (parentEntity == null) {
                valid = collectEarthSurveyValidator.validateRootEntityName(name);
                if (!valid) {
                    addInvalidMessage(ctx, NAME_FIELD, Labels.getLabel("survey.validation.collect_earth.invalid_root_entity_name"));
                }
            } else {
                valid = collectEarthSurveyValidator.validateNodeName(name);
                if (!valid) {
                    addInvalidMessage(ctx, NAME_FIELD, Labels.getLabel("survey.validation.collect_earth.invalid_node_name"));
                }
            }
        } else {
            valid = super.validateInternalName(ctx, NAME_FIELD);
            if (valid) {
                SurveyValidator surveyValidator = new SurveyValidator();
                valid = surveyValidator.validateNodeNameMaxLength(parentEntity, name);
                if (!valid) {
                    String errorMessage = Labels.getLabel("survey.validation.node.name.error.max_length_exceeded", new Object[] { surveyValidator.generateFullInternalName(parentEntity, name).length(), SurveyValidator.MAX_NODE_NAME_LENGTH });
                    addInvalidMessage(ctx, NAME_FIELD, errorMessage);
                }
            }
        }
        if (valid) {
            valid = validateNameUniqueness(ctx);
        }
    }
    return valid;
}
Also used : SurveyValidator(org.openforis.collect.manager.validation.SurveyValidator) CollectEarthSurveyValidator(org.openforis.collect.manager.validation.CollectEarthSurveyValidator) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectEarthSurveyValidator(org.openforis.collect.manager.validation.CollectEarthSurveyValidator) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 4 with SurveyValidator

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

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