use of com.linkedin.data.message.Message in project incubator-gobblin by apache.
the class CronValidator method validate.
@Override
public void validate(ValidatorContext ctx) {
DataElement element = ctx.dataElement();
Object value = element.getValue();
String str = String.valueOf(value);
if (!CronExpression.isValidExpression(str)) {
ctx.addResult(new Message(element.path(), "\"%1$s\" is not in Cron format", str));
}
}
use of com.linkedin.data.message.Message in project incubator-gobblin by apache.
the class TemplateUriValidator method validate.
@Override
public void validate(ValidatorContext ctx) {
DataElement element = ctx.dataElement();
Object value = element.getValue();
String str = String.valueOf(value);
boolean valid = true;
try {
Iterable<String> uriStrings = Splitter.on(",").omitEmptyStrings().trimResults().split(str);
for (String uriString : uriStrings) {
URI uri = new URI(uriString);
if (!uri.getScheme().equalsIgnoreCase(FS_SCHEME)) {
throw new URISyntaxException(uriString, "Scheme is not FS");
}
}
} catch (URISyntaxException e) {
valid = false;
}
if (!valid) {
ctx.addResult(new Message(element.path(), "\"%1$s\" is not a well-formed comma-separated list of URIs", str));
}
}
use of com.linkedin.data.message.Message in project rest.li by linkedin.
the class SchemaVisitorTraversalResult method addMessage.
/**
* Add a {@link Message} to the message list using constructor of the {@link Message}
* and also add to the string builder
*
* @param path path to show in the message
* @param format format of the message to show
* @param args args for the format string
*
* @see Message
*/
public void addMessage(ArrayDeque<String> path, String format, Object... args) {
Message msg = new Message(path.toArray(), format, args);
addMessage(msg);
}
use of com.linkedin.data.message.Message in project rest.li by linkedin.
the class RegexValidator method validate.
@Override
public void validate(ValidatorContext ctx) {
DataElement element = ctx.dataElement();
Object value = element.getValue();
String str = String.valueOf(value);
boolean matches = _pattern.matcher(str).matches();
if (!matches) {
ctx.addResult(new Message(element.path(), "\"%1$s\" does not match %2$s", str, _regex));
}
}
use of com.linkedin.data.message.Message in project rest.li by linkedin.
the class AnyRecordValidator method validate.
@Override
public void validate(ValidatorContext context) {
DataElement dataElement = context.dataElement();
Object value = dataElement.getValue();
DataSchema schema = dataElement.getSchema();
if (schema.getType() != DataSchema.Type.RECORD || (((RecordDataSchema) schema).getFullName()).equals(SCHEMA_NAME) == false) {
context.addResult(new Message(context.dataElement().path(), "%1$s invoked on schema that is not %2$s", AnyRecordValidator.class.getName(), SCHEMA_NAME));
} else if (value.getClass() != DataMap.class) {
context.addResult(new Message(context.dataElement().path(), "%1$s expects data to be a DataMap, data is %2$s", AnyRecordValidator.class.getName(), value));
} else {
DataMap dataMap = (DataMap) value;
if (dataMap.size() != 1) {
context.addResult(new Message(context.dataElement().path(), "%1$s expects data to be a DataMap with one entry, data is %2$s", AnyRecordValidator.class.getName(), value));
} else {
Map.Entry<String, Object> entry = dataMap.entrySet().iterator().next();
String anySchemaName = entry.getKey();
Object anyValue = entry.getValue();
DataSchema anySchema = schemaFromName(context, anySchemaName);
if (anySchema != null) {
DataElement anyElement = new SimpleDataElement(anyValue, entry.getKey(), anySchema, dataElement);
// do we want to have cache for anySchemaName to validator
// do we care about classMap argument to DataSchemaAnnotationValidator
DataSchemaAnnotationValidator validator = new DataSchemaAnnotationValidator(anySchema);
if (validator.isInitOk() == false) {
boolean errorIfNotValidated = getParameter(context.validationOptions()).isValidSchema();
context.addResult(new Message(context.dataElement().path(), errorIfNotValidated, "%1$s failed to initialize %2$s with %3$s", AnyRecordValidator.class.getName(), DataSchemaAnnotationValidator.class.getSimpleName(), anySchema));
addResult(context, errorIfNotValidated, validator.getInitMessages());
} else {
ValidationResult result = ValidateDataAgainstSchema.validate(anyElement, context.validationOptions(), validator);
addResult(context, result.getMessages());
if (result.hasFix())
context.setHasFix(true);
if (result.hasFixupReadOnlyError())
context.setHasFixupReadOnlyError(true);
}
}
}
}
}
Aggregations