Search in sources :

Example 1 with CollectEarthSurveyValidator

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

Aggregations

CollectEarthSurveyValidator (org.openforis.collect.manager.validation.CollectEarthSurveyValidator)1 SurveyValidator (org.openforis.collect.manager.validation.SurveyValidator)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1