Package com.linkedin.data.schema.validation

Examples of com.linkedin.data.schema.validation.ValidationResult


    _checked = true;
  }

  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);
    }
View Full Code Here


                                               Map<String, JClass> pathKeyTypes,
                                               Map<String, JClass> assocKeyTypes,
                                               Map<String, List<String>> pathToAssocKeys)
          throws JClassAlreadyExistsException, IOException
  {
    ValidationResult validationResult = ValidateDataAgainstSchema.validate(resource.data(), resource.schema(),
                                                                           new ValidationOptions(
                                                                                           RequiredMode.MUST_BE_PRESENT));
    if (!validationResult.isValid())
    {
        throw new IllegalArgumentException(String.format(
                "Resource validation error.  Resource File '%s', Error Details '%s'",
                sourceFile,
                validationResult.toString()));
    }

    String resourceName = capitalize(resource.getName());

    String packageName = resource.getNamespace();
View Full Code Here

    {
      Object value = field.getDefault();
      if (value != null)
      {
        DataSchema valueSchema = field.getType();
        ValidationResult result = ValidateDataAgainstSchema.validate(value, valueSchema, _validationOptions);
        if (result.isValid() == false)
        {
          startErrorMessage(value).
            append("Default value ").append(value).
            append(" of field \"").append(field.getName()).
            append("\" declared in record \"").append(recordSchema.getFullName()).
            append("\" failed validation.\n");
          MessageUtil.appendMessages(errorMessageBuilder(), result.getMessages());
        }
        Object fixed = result.getFixed();
        field.setDefault(fixed);
      }
      if (field.getDefault() instanceof DataComplex)
      {
        ((DataComplex) field.getDefault()).setReadOnly();
View Full Code Here

        if ((tests & SCHEMA_VALIDATOR) != 0)
        {
          // validate using ValidateDataWithSchema
          VisitedTrackingValidator visitedValidator = new VisitedTrackingValidator(annotationValidator);
          ValidationOptions validationOptions = new ValidationOptions(RequiredMode.CAN_BE_ABSENT_IF_HAS_DEFAULT, CoercionMode.NORMAL);
          ValidationResult result = ValidateDataAgainstSchema.validate(value.copy(), schema, validationOptions, visitedValidator);
          checkValidationResult(value, result, row, visitedValidator);
        }

        if ((tests & OBJECT_VALIDATOR) != 0)
        {
          // validate using ValidateWithValidator
          VisitedTrackingValidator visitedValidator = new VisitedTrackingValidator(annotationValidator);
          @SuppressWarnings("deprecation")
          ValidationResult result = ValidateWithValidator.validate(value.copy(), schema, visitedValidator);
          checkValidationResult(value, result, row, visitedValidator);
        }
      }
      catch (CloneNotSupportedException e)
View Full Code Here

      dataSchemaAnnotationValidator.setDebugMode(debug);

      OrderValidator._orderList.clear();

      ValidationOptions validationOptions = new ValidationOptions();
      ValidationResult validationResult =
        ValidateDataAgainstSchema.validate(dataMap, schema, validationOptions, dataSchemaAnnotationValidator);
      assertTrue(validationResult.isValid());

      if (debug) out.println(validationResult.getMessages());
      if (debug) out.println(OrderValidator._orderList);

      String[] expectedRelations = (String[]) row[i++];
      assertTrue(expectedRelations.length % 2 == 0);
      for (int r = 0; r < expectedRelations.length; r += 2)
View Full Code Here

      AnyRecordValidator.Parameter anyRecordValidatorParameter = (AnyRecordValidator.Parameter) row[i++];

      AnyRecordValidator.setParameter(options, anyRecordValidatorParameter);
      DataSchemaAnnotationValidator validator = new DataSchemaAnnotationValidator(schema);
      if (debug) TestUtil.out.println(validator);
      ValidationResult result = ValidateDataAgainstSchema.validate(object, schema, options, validator);
      checkValidationResult(result, row, i, debug);
    }
  }
View Full Code Here

        object.makeReadOnly();
      }
      AnyRecordValidator.setParameter(options, anyRecordValidatorParameter);
      DataSchemaAnnotationValidator validator = new DataSchemaAnnotationValidator(schema);
      if (debug) TestUtil.out.println(validator);
      ValidationResult result = ValidateDataAgainstSchema.validate(object, schema, options, validator);
      checkValidationResult(result, row, i, debug);
    }
  }
View Full Code Here

    else
    {
      data = DataMapUtils.readMap(request);
    }
    DynamicRecordTemplate template = new DynamicRecordTemplate(data, resourceMethodDescriptor.getRequestDataSchema());
    ValidationResult result =
        ValidateDataAgainstSchema.validate(data, template.schema(), new ValidationOptions(RequiredMode.IGNORE,
                                                                                          CoercionMode.NORMAL));
    if (!result.isValid())
    {
      throw new RoutingException("Parameters of method '" + resourceMethodDescriptor.getActionName()
          + "' failed validation with error '" + result.getMessages() + "'", HttpStatus.S_400_BAD_REQUEST.getCode());
    }
    return new RestLiRequestDataImpl.Builder().entity(template).build();
  }
View Full Code Here

      if (avroRecord != null)
      {
        // translate from Avro back to Pegasus
        DataMap dataMapResult = DataTranslator.genericRecordToDataMap(avroRecord, recordDataSchema, avroSchema);
        ValidationResult vr = ValidateDataAgainstSchema.validate(dataMap,
                                                                 recordDataSchema,
                                                                 new ValidationOptions(RequiredMode.MUST_BE_PRESENT,
                                                                                       CoercionMode.NORMAL));
        DataMap fixedInputDataMap = (DataMap) vr.getFixed();
        assertTrue(vr.isValid());
        if (oneWay == false)
        {
          assertEquals(dataMapResult, fixedInputDataMap);
        }

        // serialize avroRecord to binary and back
        byte[] avroBytes = AvroUtil.bytesFromGenericRecord(avroRecord);
        GenericRecord avroRecordFromBytes = AvroUtil.genericRecordFromBytes(avroBytes, avroRecord.getSchema());
        byte[] avroBytesAgain = AvroUtil.bytesFromGenericRecord(avroRecordFromBytes);
        assertEquals(avroBytes, avroBytesAgain);

        // check result of roundtrip binary serialization
        DataMap dataMapFromBinaryResult = DataTranslator.genericRecordToDataMap(avroRecordFromBytes, recordDataSchema, avroSchema);
        vr = ValidateDataAgainstSchema.validate(dataMapFromBinaryResult,
                                                recordDataSchema,
                                                new ValidationOptions(RequiredMode.MUST_BE_PRESENT,
                                                                      CoercionMode.NORMAL));
        fixedInputDataMap = (DataMap) vr.getFixed();
        assertTrue(vr.isValid());
        if (oneWay == false)
        {
          assertEquals(dataMapResult, fixedInputDataMap);
        }
      }
View Full Code Here

    return sb.toString();
  }

  private static void validate(DataTemplate<?> data, Class<?> clazz)
  {
    final ValidationResult valResult = ValidateDataAgainstSchema.validate(data.data(),
                                                                          data.schema(),
                                                                          _defaultValOptions);
    if (!valResult.isValid())
    {
      throw new IllegalArgumentException("Coercing String \"" + data.data() + "\" to type " + clazz.getName() + " failed due to schema validation: " + valResult.getMessages());
    }
  }
View Full Code Here

TOP

Related Classes of com.linkedin.data.schema.validation.ValidationResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.