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;
}
Aggregations