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