use of org.openforis.idm.metamodel.validation.EntityKeyValidator in project collect by openforis.
the class ValidationMessageBuilder method getMessageArgs.
protected String[] getMessageArgs(Attribute<?, ?> attribute, ValidationResult validationResult, Locale locale) {
ValidationRule<?> validator = validationResult.getValidator();
if (validator instanceof ComparisonCheck) {
ComparisonCheck check = (ComparisonCheck) validator;
ArrayList<String> args = new ArrayList<String>();
String labelText = getPrettyLabelText(attribute.getDefinition(), locale);
args.add(labelText);
Map<String, String> expressions = new HashMap<String, String>();
expressions.put("lt", check.getLessThanExpression());
expressions.put("lte", check.getLessThanOrEqualsExpression());
expressions.put("gt", check.getGreaterThanExpression());
expressions.put("gte", check.getGreaterThanOrEqualsExpression());
for (String key : expressions.keySet()) {
String expression = expressions.get(key);
if (expression != null) {
String argPart1 = key;
String argPart2 = getComparisonCheckMessageArg(attribute, expression, locale);
String arg = StringUtils.join(argPart1, MULTIPLE_MESSAGE_ARGS_SEPARATOR, argPart2);
args.add(arg);
}
}
return args.toArray(new String[args.size()]);
} else if (validator instanceof EntityKeyValidator) {
EntityDefinition parentDefn = attribute.getDefinition().getParentEntityDefinition();
String parentLabel = getPrettyLabelText(parentDefn, locale.getLanguage());
List<AttributeDefinition> keyDefns = parentDefn.getKeyAttributeDefinitions();
List<String> keyDefnLabels = new ArrayList<String>(keyDefns.size());
for (AttributeDefinition keyDefn : keyDefns) {
keyDefnLabels.add(getPrettyLabelText(keyDefn, locale.getLanguage()));
}
// TODO localize separator
return new String[] { parentLabel, StringUtils.join(keyDefnLabels, ", ") };
} else {
return null;
}
}
use of org.openforis.idm.metamodel.validation.EntityKeyValidator in project collect by openforis.
the class ValidationMessageBuilder method getMessageKey.
protected String getMessageKey(Attribute<?, ?> attribute, ValidationResult validationResult) {
String key = null;
ValidationRule<?> validator = validationResult.getValidator();
if (validator instanceof CodeValidator) {
key = "validation.codeError";
} else if (validator instanceof CodeParentValidator) {
key = "validation.codeParentError";
} else if (validator instanceof ComparisonCheck) {
key = "validation.comparisonError";
} else if (validator instanceof CoordinateValidator) {
if (attribute.isFilled()) {
key = "validation.coordinateError";
} else {
key = "validation.incompleteCoordinateError";
}
} else if (validator instanceof DateValidator) {
if (attribute.isFilled()) {
key = "validation.dateError";
} else {
key = "validation.incompleteDateError";
}
} else if (validator instanceof DistanceCheck) {
key = "validation.distanceError";
} else if (validator instanceof EntityKeyValidator) {
key = "validation.entityKeyUniquenessError";
} else if (validator instanceof ExternalCodeValidator) {
key = "validation.externalCodeError";
} else if (validator instanceof IntegerRangeValidator) {
key = "validation.integerRangeError";
} else if (validator instanceof PatternCheck) {
key = "validation.patternError";
} else if (validator instanceof RealRangeValidator) {
key = "validation.realRangeError";
} else if (validator instanceof RecordKeyUniquenessValidator) {
key = "validation.recordKeyUniquenessError";
} else if (validator instanceof SpecifiedValidator) {
if (validationResult.getFlag() == ValidationResultFlag.ERROR) {
key = "validation.specifiedError";
} else {
key = "validation.requiredField";
}
} else if (validator instanceof TimeValidator) {
if (attribute.isFilled()) {
key = "validation.timeError";
} else {
key = "validation.incompleteTimeError";
}
} else if (validator instanceof TaxonVernacularLanguageValidator) {
TaxonAttribute taxonAttr = (TaxonAttribute) attribute;
if (StringUtils.isNotBlank(taxonAttr.getVernacularName()) && StringUtils.isBlank(taxonAttr.getLanguageCode())) {
key = "validator.taxon.missingVernacularLanguage";
} else {
key = "validator.taxon.vernacularLanguageNotRequired";
}
} else if (validator instanceof UniquenessCheck) {
key = "validation.uniquenessError";
} else if (validator instanceof NumberValueUnitValidator || validator instanceof NumericRangeUnitValidator) {
key = "validation.unitNotSpecifiedError";
}
return key;
}
Aggregations