MikeThomsen commented on code in PR #4044:
URL: https://github.com/apache/nifi/pull/4044#discussion_r1181105179
##########
nifi-nar-bundles/nifi-jolt-record-bundle/nifi-jolt-record-processors/src/main/java/org/apache/nifi/processors/jolt/record/JoltTransformRecord.java:
##########
@@ -238,48 +254,65 @@ protected Collection<ValidationResult>
customValidate(ValidationContext validati
final List<ValidationResult> results = new
ArrayList<>(super.customValidate(validationContext));
final String transform =
validationContext.getProperty(JOLT_TRANSFORM).getValue();
final String customTransform =
validationContext.getProperty(CUSTOM_CLASS).getValue();
- if (!validationContext.getProperty(JOLT_SPEC).isSet() ||
StringUtils.isEmpty(validationContext.getProperty(JOLT_SPEC).getValue())) {
- if (!SORTR.getValue().equals(transform)) {
- final String message = "A specification is required for this
transformation";
- results.add(new ValidationResult.Builder().valid(false)
- .explanation(message)
- .build());
+ final String modulePath =
validationContext.getProperty(MODULES).isSet()?
validationContext.getProperty(MODULES).getValue() : null;
+ final String joltSpecBody =
validationContext.getProperty(JOLT_SPEC).getValue();
+ final String joltSpecFile =
validationContext.getProperty(JOLT_SPEC_FILE).getValue();
+
+ if (StringUtils.isEmpty(joltSpecBody) ==
StringUtils.isEmpty(joltSpecFile)) {
+ if(!SORTR.getValue().equals(transform)) {
+ results.add(new ValidationResult.Builder().subject("Spec Body
or Spec File").valid(false).explanation(
+ "exactly one of 'Jolt Specification' or 'Path To Jolt
Specification' must be set, or the Transformation must be 'Sort'").build());
}
} else {
+ final ClassLoader customClassLoader;
+
try {
- final String specValue =
validationContext.getProperty(JOLT_SPEC).getValue();
+ if (modulePath != null) {
+ customClassLoader =
ClassLoaderUtils.getCustomClassLoader(modulePath,
this.getClass().getClassLoader(), getJarFilenameFilter());
+ } else {
+ customClassLoader = this.getClass().getClassLoader();
+ }
- if (validationContext.isExpressionLanguagePresent(specValue) )
{
+ String specValue =
validationContext.getProperty(JOLT_SPEC).getValue();
+ final boolean useBody = !StringUtils.isEmpty(specValue);
+ if (!useBody) {
+ specValue =
validationContext.getProperty(JOLT_SPEC_FILE).getValue();
+ }
+ final PropertyDescriptor pd = useBody ? JOLT_SPEC :
JOLT_SPEC_FILE;
+ final boolean elPresent =
validationContext.isExpressionLanguagePresent(specValue);
+
+ if (elPresent) {
final String invalidExpressionMsg =
validationContext.newExpressionLanguageCompiler().validateExpression(specValue,
true);
if (!StringUtils.isEmpty(invalidExpressionMsg)) {
results.add(new ValidationResult.Builder().valid(false)
- .subject(JOLT_SPEC.getDisplayName())
+ .subject(pd.getDisplayName())
.explanation("Invalid Expression Language: " +
invalidExpressionMsg)
.build());
}
} else {
- //for validation we want to be able to ensure the spec is
syntactically correct and not try to resolve variables since they may not exist
yet
- Object specJson = SORTR.getValue().equals(transform) ?
null : JsonUtils.jsonToObject(specValue.replaceAll("\\$\\{", "\\\\\\\\\\$\\{"),
DEFAULT_CHARSET);
-
- if (CUSTOMR.getValue().equals(transform)) {
- if (StringUtils.isEmpty(customTransform)) {
- final String customMessage = "A custom
transformation class should be provided. ";
- results.add(new
ValidationResult.Builder().valid(false)
- .explanation(customMessage)
- .build());
- } else if
(validationContext.isExpressionLanguagePresent(customTransform)) {
- final String invalidExpressionMsg =
validationContext.newExpressionLanguageCompiler().validateExpression(customTransform,
true);
- if (!StringUtils.isEmpty(invalidExpressionMsg)) {
+ if (!SORTR.getValue().equals(transform)) {
+
+ //for validation we want to be able to ensure the spec
is syntactically correct and not try to resolve variables since they may not
exist yet
+ final String content;
+ if(useBody) {
+ content = specValue;
+ } else {
+ content = new
String(Files.readAllBytes(Paths.get(specValue)), DEFAULT_CHARSET);
+ }
+ final Object specJson =
JsonUtils.jsonToObject(content.replaceAll("\\$\\{", "\\\\\\\\\\$\\{"),
DEFAULT_CHARSET);
+
+ if (CUSTOMR.getValue().equals(transform)) {
Review Comment:
Aren't `SORTR` and `CUSTOMR` mutually exclusive? Not sure I'm following the
validation logic since they're both `AllowableValue` entries on the same
property description.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]