Search in sources :

Example 1 with Message

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));
    }
}
Also used : DataElement(com.linkedin.data.element.DataElement) Message(com.linkedin.data.message.Message)

Example 2 with Message

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));
    }
}
Also used : DataElement(com.linkedin.data.element.DataElement) Message(com.linkedin.data.message.Message) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 3 with Message

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);
}
Also used : Message(com.linkedin.data.message.Message)

Example 4 with Message

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));
    }
}
Also used : DataElement(com.linkedin.data.element.DataElement) Message(com.linkedin.data.message.Message)

Example 5 with Message

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);
                }
            }
        }
    }
}
Also used : RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) SimpleDataElement(com.linkedin.data.element.SimpleDataElement) DataElement(com.linkedin.data.element.DataElement) Message(com.linkedin.data.message.Message) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) SimpleDataElement(com.linkedin.data.element.SimpleDataElement) ValidationResult(com.linkedin.data.schema.validation.ValidationResult) DataMap(com.linkedin.data.DataMap)

Aggregations

Message (com.linkedin.data.message.Message)20 DataElement (com.linkedin.data.element.DataElement)7 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)5 DataMap (com.linkedin.data.DataMap)4 SimpleDataElement (com.linkedin.data.element.SimpleDataElement)4 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)3 TestUtil.dataMapFromString (com.linkedin.data.TestUtil.dataMapFromString)2 TestUtil.dataSchemaFromString (com.linkedin.data.TestUtil.dataSchemaFromString)2 DataSchema (com.linkedin.data.schema.DataSchema)2 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)2 ValidationOptions (com.linkedin.data.schema.validation.ValidationOptions)2 DataComplexProcessor (com.linkedin.data.transform.DataComplexProcessor)2 DataProcessingException (com.linkedin.data.transform.DataProcessingException)2 MockBadRequest (com.linkedin.restli.server.errors.MockBadRequest)2 MockInputError (com.linkedin.restli.server.errors.MockInputError)2 MockInputErrorArray (com.linkedin.restli.server.errors.MockInputErrorArray)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.testng.annotations.Test)2 ByteString (com.linkedin.data.ByteString)1