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