@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;
  }
Esempio n. 2
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;
  }
Esempio n. 5
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;
  }