@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();
        }
  @Override
  protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) {
    final List<ValidationResult> problems =
        new ArrayList<>(super.customValidate(validationContext));

    final boolean accessKeySet = validationContext.getProperty(ACCESS_KEY).isSet();
    final boolean secretKeySet = validationContext.getProperty(SECRET_KEY).isSet();
    if ((accessKeySet && !secretKeySet) || (secretKeySet && !accessKeySet)) {
      problems.add(
          new ValidationResult.Builder()
              .input("Access Key")
              .valid(false)
              .explanation("If setting Secret Key or Access Key, must set both")
              .build());
    }

    final boolean credentialsFileSet = validationContext.getProperty(CREDENTAILS_FILE).isSet();
    if ((secretKeySet || accessKeySet) && credentialsFileSet) {
      problems.add(
          new ValidationResult.Builder()
              .input("Access Key")
              .valid(false)
              .explanation("Cannot set both Credentials File and Secret Key/Access Key")
              .build());
    }

    return problems;
  }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
  @Override
  protected Collection<ValidationResult> customValidate(final ValidationContext context) {
    final Collection<ValidationResult> results = new ArrayList<>();

    if (context.getProperty(URL).getValue().startsWith("https")
        && context.getProperty(SSL_CONTEXT_SERVICE).getValue() == null) {
      results.add(
          new ValidationResult.Builder()
              .explanation("URL is set to HTTPS protocol but no SSLContext has been specified")
              .valid(false)
              .subject("SSL Context")
              .build());
    }

    return results;
  }
        @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();
        }
  @Override
  protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
    Set<ValidationResult> results = new HashSet<>();

    // Ensure that if username or password is set, then the other is too
    String userName =
        validationContext.getProperty(USERNAME).evaluateAttributeExpressions().getValue();
    String password =
        validationContext.getProperty(PASSWORD).evaluateAttributeExpressions().getValue();
    if (StringUtils.isEmpty(userName) != StringUtils.isEmpty(password)) {
      results.add(
          new ValidationResult.Builder()
              .valid(false)
              .explanation(
                  "If username or password is specified, then the other must be specified as well")
              .build());
    }

    return results;
  }
Exemplo n.º 7
0
  @Override
  protected final Collection<ValidationResult> customValidate(ValidationContext context) {
    final List<ValidationResult> problems = new ArrayList<>();

    if (SOLR_TYPE_CLOUD.equals(context.getProperty(SOLR_TYPE).getValue())) {
      final String collection = context.getProperty(COLLECTION).getValue();
      if (collection == null || collection.trim().isEmpty()) {
        problems.add(
            new ValidationResult.Builder()
                .subject(COLLECTION.getName())
                .input(collection)
                .valid(false)
                .explanation("A collection must specified for Solr Type of Cloud")
                .build());
      }
    }

    Collection<ValidationResult> otherProblems = this.additionalCustomValidation(context);
    if (otherProblems != null) {
      problems.addAll(otherProblems);
    }

    return problems;
  }
Exemplo n.º 8
0
  @Override
  protected Collection<ValidationResult> customValidate(final ValidationContext context) {
    final List<ValidationResult> reasons = new ArrayList<>(super.customValidate(context));

    Criteria criteria = null;
    try {
      criteria = CriteriaSerDe.deserialize(context.getAnnotationData());
    } catch (IllegalArgumentException iae) {
      reasons.add(
          new ValidationResult.Builder()
              .valid(false)
              .explanation("Unable to deserialize the update criteria." + iae.getMessage())
              .build());
    }

    // if there is criteria, validate it
    if (criteria != null) {
      final List<Rule> rules = criteria.getRules();

      if (rules == null) {
        reasons.add(
            new ValidationResult.Builder()
                .valid(false)
                .explanation("Update criteria has been specified by no rules were found.")
                .build());
      } else {
        // validate the each rule
        for (final Rule rule : rules) {
          if (rule.getName() == null || rule.getName().trim().isEmpty()) {
            reasons.add(
                new ValidationResult.Builder()
                    .valid(false)
                    .explanation("A rule name was not specified.")
                    .build());
          }

          // validate each condition
          final Set<Condition> conditions = rule.getConditions();
          if (conditions == null) {
            reasons.add(
                new ValidationResult.Builder()
                    .valid(false)
                    .explanation(
                        String.format("No conditions for rule '%s' found.", rule.getName()))
                    .build());
          } else {
            for (final Condition condition : conditions) {
              if (condition.getExpression() == null) {
                reasons.add(
                    new ValidationResult.Builder()
                        .valid(false)
                        .explanation(
                            String.format(
                                "No expression for a condition in rule '%s' was found.",
                                rule.getName()))
                        .build());
              } else {
                final String expression = condition.getExpression().trim();
                reasons.add(
                    StandardValidators.createAttributeExpressionLanguageValidator(
                            AttributeExpression.ResultType.BOOLEAN, false)
                        .validate(
                            String.format("Condition for rule '%s'.", rule.getName()),
                            expression,
                            context));
              }
            }
          }

          // validate each action
          final Set<Action> actions = rule.getActions();
          if (actions == null) {
            reasons.add(
                new ValidationResult.Builder()
                    .valid(false)
                    .explanation(String.format("No actions for rule '%s' found.", rule.getName()))
                    .build());
          } else {
            for (final Action action : actions) {
              if (action.getAttribute() == null) {
                reasons.add(
                    new ValidationResult.Builder()
                        .valid(false)
                        .explanation(
                            String.format(
                                "An action in rule '%s' is missing the attribute name.",
                                rule.getName()))
                        .build());
              } else if (action.getValue() == null) {
                reasons.add(
                    new ValidationResult.Builder()
                        .valid(false)
                        .explanation(
                            String.format(
                                "No value for attribute '%s' in rule '%s' was found.",
                                action.getAttribute(), rule.getName()))
                        .build());
              } else {
                reasons.add(
                    StandardValidators.createAttributeExpressionLanguageValidator(
                            AttributeExpression.ResultType.STRING, true)
                        .validate(
                            String.format("Action for rule '%s'.", rule.getName()),
                            action.getValue(),
                            context));
              }
            }
          }
        }
      }
    }

    return reasons;
  }