本文整理汇总了Java中org.apache.nifi.components.ValidationContext类的典型用法代码示例。如果您正苦于以下问题:Java ValidationContext类的具体用法?Java ValidationContext怎么用?Java ValidationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValidationContext类属于org.apache.nifi.components包,在下文中一共展示了ValidationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import org.apache.nifi.components.ValidationContext; //导入依赖的package包/类
@Override
public ValidationResult validate(String subject, String input, ValidationContext context) {
String libDirPath = context.getProperty(CLIENT_LIB_DIR_PATH).getValue();
StringBuilder invalidationMessageBuilder = new StringBuilder();
if (libDirPath != null) {
File file = new File(libDirPath);
if (!file.isDirectory()) {
invalidationMessageBuilder.append("'MQ Client Libraries path' must point to a directory. Was '"
+ file.getAbsolutePath() + "'.");
}
} else {
invalidationMessageBuilder.append("'MQ Client Libraries path' must be provided. \n");
}
String invalidationMessage = invalidationMessageBuilder.toString();
ValidationResult vResult;
if (invalidationMessage.length() == 0) {
vResult = new ValidationResult.Builder().subject(subject).input(input)
.explanation("Client lib path is valid and points to a directory").valid(true).build();
} else {
vResult = new ValidationResult.Builder().subject(subject).input(input)
.explanation("Client lib path is invalid. " + invalidationMessage)
.valid(false).build();
}
return vResult;
}
示例2: customValidate
import org.apache.nifi.components.ValidationContext; //导入依赖的package包/类
@Override
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
final Collection<ValidationResult> results = new ArrayList<>();
parseAtlasUrls(validationContext.getProperty(ATLAS_URLS), input -> {
final ValidationResult.Builder builder = new ValidationResult.Builder().subject(ATLAS_URLS.getDisplayName()).input(input);
try {
new URL(input);
results.add(builder.explanation("Valid URI").valid(true).build());
} catch (Exception e) {
results.add(builder.explanation("Contains invalid URI: " + e).valid(false).build());
}
});
clusterResolverLoader.forEach(resolver -> results.addAll(resolver.validate(validationContext)));
return results;
}
示例3: validate
import org.apache.nifi.components.ValidationContext; //导入依赖的package包/类
@Override
public Collection<ValidationResult> validate(ValidationContext validationContext) {
final List<ValidationResult> validationResults = new ArrayList<>();
consumeConfigurations(validationContext.getAllProperties(),
(clusterNamePatterns, patterns) -> {},
(entry, e) -> {
final ValidationResult result = new ValidationResult.Builder()
.subject(entry.getKey())
.input(entry.getValue())
.explanation(e.getMessage())
.valid(false)
.build();
validationResults.add(result);
});
return validationResults;
}
示例4: customValidate
import org.apache.nifi.components.ValidationContext; //导入依赖的package包/类
@Override
protected Collection<ValidationResult> customValidate(final ValidationContext context) {
final Collection<ValidationResult> results = new ArrayList<>();
PropertyValue usernameProperty = context.getProperty(USERNAME);
PropertyValue passwordProperty = context.getProperty(PASSWORD);
PropertyValue authDatabaseProperty = context.getProperty(AUTH_DATABASE);
boolean valid = true;
if (usernameProperty.isSet() || passwordProperty.isSet() || authDatabaseProperty.isSet()) {
valid = usernameProperty.isSet() && passwordProperty.isSet() && authDatabaseProperty.isSet();
}
results.add(new ValidationResult.Builder()
.explanation("Using authentication requires Username, Password, and the Authentication Database")
.valid(valid)
.subject("Mongo Authentication")
.build());
return results;
}
示例5: customValidate
import org.apache.nifi.components.ValidationContext; //导入依赖的package包/类
@Override
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
boolean zkQuorumProvided = validationContext.getProperty(ZOOKEEPER_QUORUM).isSet();
boolean instanceNamerovided = validationContext.getProperty(INSTANCE_NAME).isSet();
boolean userProvided = validationContext.getProperty(USER).isSet();
boolean passwordProvided = validationContext.getProperty(PASSWORD).isSet();
final List<ValidationResult> problems = new ArrayList<>();
if (!zkQuorumProvided && (!instanceNamerovided || !userProvided || !passwordProvided)) {
problems.add(new ValidationResult.Builder()
.valid(false)
.subject(this.getClass().getSimpleName())
.explanation("ZooKeeper Quorum, Instance Name, Accumulo User, and Accumulo Password are required " +
"to connect")
.build());
}
return problems;
}
示例6: validate
import org.apache.nifi.components.ValidationContext; //导入依赖的package包/类
@Override
public ValidationResult validate(String subject, String input, ValidationContext context) {
try {
JSONUtils.INSTANCE.load(input, new TypeReference<Map<String, String>>() {
});
} catch (IOException e) {
return new ValidationResult.Builder()
.subject(subject)
.input(value)
.valid(false)
.explanation("Not a valid JSON map value: " + e.getMessage())
.build();
}
return new ValidationResult.Builder()
.valid(true)
.input(value)
.subject(subject)
.build();
}
示例7: customValidate
import org.apache.nifi.components.ValidationContext; //导入依赖的package包/类
@Override
protected Collection<ValidationResult> customValidate(
final ValidationContext validationContext) {
final List<ValidationResult> results = new ArrayList<>();
final String endpointName = validationContext.getProperty(ENDPOINT)
.getValue();
if (ENDPOINT_FILTER.getValue().equals(endpointName)) {
if (!validationContext.getProperty(TERMS).isSet()
&& !validationContext.getProperty(FOLLOWING).isSet()
&& !validationContext.getProperty(LOCATIONS).isSet()) {
results.add(new ValidationResult.Builder()
.input("")
.subject(FOLLOWING.getName())
.valid(false)
.explanation(
"When using the 'Filter Endpoint', at least one of '"
+ TERMS.getName() + "' or '"
+ FOLLOWING.getName() + "'" + "' or '"
+ LOCATIONS.getName() + " must be set")
.build());
}
}
return results;
}
示例8: customValidate
import org.apache.nifi.components.ValidationContext; //导入依赖的package包/类
@Override
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
final List<ValidationResult> results = new ArrayList<>(1);
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = null;
try {
rootNode = mapper.readValue(new File(validationContext.getProperty(GENERATOR_RESOURCE).getValue()), JsonNode.class);
generator = new RecordGenerator(rootNode);
} catch (IOException ioe) {
results.add(new ValidationResult.Builder().subject("Generator Resource").valid(false).explanation("Couldn't read specified resource").build());
}
return results;
}
示例9: validate
import org.apache.nifi.components.ValidationContext; //导入依赖的package包/类
@Override
public Collection<ValidationResult> validate(ValidationContext validationContext) {
Collection<ValidationResult> results = new ArrayList<>();
for (ClusterResolver resolver : resolvers) {
results.addAll(resolver.validate(validationContext));
}
return results;
}
示例10: validate
import org.apache.nifi.components.ValidationContext; //导入依赖的package包/类
@Override
public ValidationResult validate(final String subject, final String value, final ValidationContext context) {
String reason = null;
try {
Object root = JSON.parse(value);
if (!(root instanceof BasicDBList)) {
reason = "not a valid JsonArray";
}
} catch (Exception e) {
// LOGGER.debug("not a valid JSON list", e);
reason = "unable to parse JSON";
}
return new ValidationResult.Builder().subject(subject).input(value).explanation(reason).valid(reason == null).build();
}
示例11: customValidate
import org.apache.nifi.components.ValidationContext; //导入依赖的package包/类
@Override
protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) {
List<ValidationResult> results = new ArrayList<>();
if (validationContext.getProperty(INSERT_COMMAND_SOURCE).getValue().equals("attribute")) {
results.add(StandardValidators.NON_BLANK_VALIDATOR.validate(
INSERT_COMMAND_ATTRIBUTE.getName(),
validationContext.getProperty(INSERT_COMMAND_ATTRIBUTE).getValue(),
validationContext));
}
return results;
}
示例12: customValidate
import org.apache.nifi.components.ValidationContext; //导入依赖的package包/类
/**
* Custom validation for ensuring exactly one of Script File or Script Body is populated
*
* @param validationContext provides a mechanism for obtaining externally
* managed values, such as property values and supplies convenience methods
* for operating on those values
* @return A collection of validation results
*/
public Collection<ValidationResult> customValidate(ValidationContext validationContext) {
Set<ValidationResult> results = new HashSet<>();
// Verify that exactly one of "script file" or "script body" is set
Map<PropertyDescriptor, String> propertyMap = validationContext.getProperties();
if (StringUtils.isEmpty(propertyMap.get(ScriptingComponentUtils.SCRIPT_FILE)) == StringUtils.isEmpty(propertyMap.get(ScriptingComponentUtils.SCRIPT_BODY))) {
results.add(new ValidationResult.Builder().valid(false).explanation(
"Exactly one of Script File or Script Body must be set").build());
}
return results;
}
示例13: validate
import org.apache.nifi.components.ValidationContext; //导入依赖的package包/类
default Collection<ValidationResult> validate(final ValidationContext validationContext) {
return Collections.emptySet();
}
示例14: setupMock
import org.apache.nifi.components.ValidationContext; //导入依赖的package包/类
public void setupMock(Map<String, String> properties) {
context = Mockito.mock(PropertyContext.class);
validationContext = Mockito.mock(ValidationContext.class);
when(validationContext.getAllProperties()).thenReturn(properties);
when(context.getAllProperties()).thenReturn(properties);
}
示例15: validate
import org.apache.nifi.components.ValidationContext; //导入依赖的package包/类
@Override
public ValidationResult validate(String subject, String input, ValidationContext context) {
return validator.validate(subject, input, context);
}