Search in sources :

Example 11 with Message

use of com.linkedin.data.message.Message in project rest.li by linkedin.

the class ResourceCompatibilityChecker method validateData.

private boolean validateData(DataMap object, DataSchema schema, ValidationOptions options) {
    final ValidationResult valResult = ValidateDataAgainstSchema.validate(object, schema, options);
    if (valResult.isValid()) {
        return true;
    }
    final Collection<Message> valErrorMessages = valResult.getMessages();
    for (final Message message : valErrorMessages) {
        _infoMap.addRestSpecInfo(message);
    }
    return false;
}
Also used : Message(com.linkedin.data.message.Message) CompatibilityMessage(com.linkedin.data.schema.compatibility.CompatibilityMessage) ValidationResult(com.linkedin.data.schema.validation.ValidationResult)

Example 12 with Message

use of com.linkedin.data.message.Message in project rest.li by linkedin.

the class StrlenValidator method validate.

@Override
public void validate(ValidatorContext ctx) {
    DataElement element = ctx.dataElement();
    Object value = element.getValue();
    String str = String.valueOf(value);
    int strlen = str.length();
    if ((strlen < _min) || (strlen > _max)) {
        ctx.addResult(new Message(element.path(), "length of \"%1$s\" is out of range %2$d...%3$d", str, _min, _max));
    }
}
Also used : DataElement(com.linkedin.data.element.DataElement) Message(com.linkedin.data.message.Message)

Example 13 with Message

use of com.linkedin.data.message.Message in project rest.li by linkedin.

the class RestLiDataValidator method validationResultWithErrorMessage.

private static ValidationErrorResult validationResultWithErrorMessage(String errorMessage) {
    ValidationErrorResult result = new ValidationErrorResult();
    result.addMessage(new Message(new Object[] {}, errorMessage));
    return result;
}
Also used : Message(com.linkedin.data.message.Message)

Example 14 with Message

use of com.linkedin.data.message.Message in project rest.li by linkedin.

the class RestLiDataValidator method checkDeletesAreValid.

private void checkDeletesAreValid(DataSchema schema, MessageList<Message> messages, ValidationErrorResult result) {
    for (Message message : messages) {
        Object[] path = message.getPath();
        if (path[path.length - 1].toString().equals(PatchConstants.DELETE_COMMAND)) {
            // Replace $delete with the field name to get the full path
            path[path.length - 1] = message.getFormat();
            RecordDataSchema.Field field = DataSchemaUtil.getField(schema, path);
            if (field != null && !field.getOptional() && field.getDefault() == null) {
                result.addMessage(new Message(path, "cannot delete a required field"));
            }
            DataElement fakeElement = hollowElementFromPath(path);
            if (_readOnlyDescendantPredicate.evaluate(fakeElement)) {
                result.addMessage(new Message(path, "cannot delete a ReadOnly field or its descendants"));
            } else if (_createOnlyDescendantPredicate.evaluate(fakeElement)) {
                result.addMessage(new Message(path, "cannot delete a CreateOnly field or its descendants"));
            }
        }
    }
}
Also used : SimpleDataElement(com.linkedin.data.element.SimpleDataElement) DataElement(com.linkedin.data.element.DataElement) Message(com.linkedin.data.message.Message) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema)

Example 15 with Message

use of com.linkedin.data.message.Message in project rest.li by linkedin.

the class MockValidationErrorHandler method updateErrorDetails.

@Override
public void updateErrorDetails(RestLiServiceException exception, Map<String, Collection<Message>> messages) {
    MockBadRequest badRequest = new MockBadRequest();
    MockInputErrorArray inputErrors = new MockInputErrorArray();
    for (Map.Entry<String, Collection<Message>> entry : messages.entrySet()) {
        for (Message message : entry.getValue()) {
            if (message.isError() && message.getErrorDetails() instanceof MockInputError) {
                MockInputError inputError = (MockInputError) message.getErrorDetails();
                inputError.setKey(entry.getKey());
                inputErrors.add(inputError);
            }
        }
    }
    badRequest.setInputErrors(inputErrors);
    exception.setErrorDetails(badRequest);
    exception.setCode(ERROR_CODE);
}
Also used : MockInputError(com.linkedin.restli.server.errors.MockInputError) Message(com.linkedin.data.message.Message) Collection(java.util.Collection) MockInputErrorArray(com.linkedin.restli.server.errors.MockInputErrorArray) MockBadRequest(com.linkedin.restli.server.errors.MockBadRequest) Map(java.util.Map)

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