@Override
        public ValidationResult validate(
            final String subject, final String value, final ValidationContext context) {
          if (context.isExpressionLanguageSupported(subject)
              && context.isExpressionLanguagePresent(value)) {
            return new ValidationResult.Builder()
                .subject(subject)
                .input(value)
                .explanation("Expression Language Present")
                .valid(true)
                .build();
          }

          String reason = "";
          if (!AVRO_FIELDNAME_PATTERN.matcher(subject).matches()) {
            reason = subject + " is not a valid Avro fieldname";
          }
          if (!AVRO_FIELDNAME_PATTERN.matcher(value).matches()) {
            reason = reason + value + " is not a valid Avro fieldname";
          }

          return new ValidationResult.Builder()
              .subject(subject)
              .input(value)
              .explanation(reason)
              .valid(reason.equals(""))
              .build();
        }
Exemple #2
0
        @Override
        public ValidationResult validate(String subject, String input, ValidationContext context) {
          if (context.isExpressionLanguageSupported(subject)
              && context.isExpressionLanguagePresent(input)) {
            final AttributeExpression.ResultType resultType =
                context.newExpressionLanguageCompiler().getResultType(input);
            if (!resultType.equals(AttributeExpression.ResultType.STRING)) {
              return new ValidationResult.Builder()
                  .subject(subject)
                  .input(input)
                  .valid(false)
                  .explanation(
                      "Expected property to to return type "
                          + AttributeExpression.ResultType.STRING
                          + " but expression returns type "
                          + resultType)
                  .build();
            }
            return new ValidationResult.Builder()
                .subject(subject)
                .input(input)
                .valid(true)
                .explanation("Property returns type " + AttributeExpression.ResultType.STRING)
                .build();
          }

          return DPV_RE_VALIDATOR.validate(subject, input, context);
        }
        @Override
        public ValidationResult validate(String subject, String uri, ValidationContext context) {
          Configuration conf = getConfiguration(context.getProperty(CONF_XML_FILES).getValue());
          String inputUri = context.getProperty(INPUT_SCHEMA).getValue();
          String error = null;

          final boolean elPresent =
              context.isExpressionLanguageSupported(subject)
                  && context.isExpressionLanguagePresent(uri);
          if (!elPresent) {
            try {
              Schema outputSchema = getSchema(uri, conf);
              Schema inputSchema = getSchema(inputUri, conf);
              // Get the explicitly mapped fields. This is identical to
              // logic in onTrigger, but ValidationContext and
              // ProcessContext share no ancestor, so we cannot generalize
              // the code.
              Map<String, String> fieldMapping = new HashMap<>();
              for (final Map.Entry<PropertyDescriptor, String> entry :
                  context.getProperties().entrySet()) {
                if (entry.getKey().isDynamic()) {
                  fieldMapping.put(entry.getKey().getName(), entry.getValue());
                }
              }
              AvroRecordConverter converter =
                  new AvroRecordConverter(inputSchema, outputSchema, fieldMapping);
              Collection<String> unmappedFields = converter.getUnmappedFields();
              if (unmappedFields.size() > 0) {
                error = "The following fields are unmapped: " + unmappedFields;
              }

            } catch (SchemaNotFoundException e) {
              error = e.getMessage();
            }
          }
          return new ValidationResult.Builder()
              .subject(subject)
              .input(uri)
              .explanation(error)
              .valid(error == null)
              .build();
        }