Search in sources :

Example 1 with SurveyValidationResult

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

Aggregations

SurveyValidator (org.openforis.collect.manager.validation.SurveyValidator)1 SurveyValidationResult (org.openforis.collect.manager.validation.SurveyValidator.SurveyValidationResult)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1