Lehel44 commented on a change in pull request #5446:
URL: https://github.com/apache/nifi/pull/5446#discussion_r724204924



##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenHTTP.java
##########
@@ -273,13 +310,40 @@ public AllowableValue getAllowableValue() {
     private final AtomicReference<ProcessSessionFactory> 
sessionFactoryReference = new AtomicReference<>();
     private final AtomicReference<StreamThrottler> throttlerRef = new 
AtomicReference<>();
 
+    private volatile boolean isRecordReaderSet;
+    private volatile boolean isRecordWriterSet;
+
     @Override
-    protected Collection<ValidationResult> customValidate(ValidationContext 
context) {
-        List<ValidationResult> results = new ArrayList<>(1);
+    public void onPropertyModified(final PropertyDescriptor descriptor, final 
String oldValue, final String newValue) {
+        if (RECORD_READER.equals(descriptor)) {
+            isRecordReaderSet = StringUtils.isNotEmpty(newValue);
+        } else if (RECORD_WRITER.equals(descriptor)) {
+            isRecordWriterSet = StringUtils.isNotEmpty(newValue);
+        }
+    }
 
-        validatePortsAreNotEqual(context, results);
+    @Override
+    protected Collection<ValidationResult> customValidate(ValidationContext 
validationContext) {
+        final Set<ValidationResult> validationResults = new 
HashSet<>(super.customValidate(validationContext));
+
+        validatePortsAreNotEqual(validationContext, validationResults);
+
+        final String explanation = "%s must be set if %s is set in order to 
write FlowFiles as Records.";
+        if (isRecordReaderSet && !isRecordWriterSet) {
+            validationResults.add(new ValidationResult.Builder()
+                    .subject(RECORD_WRITER.getName())
+                    .explanation(String.format(explanation, 
RECORD_WRITER.getDisplayName(), RECORD_READER.getDisplayName()))
+                    .valid(false)
+                    .build());
+        } else if (isRecordWriterSet && !isRecordReaderSet) {
+            validationResults.add(new ValidationResult.Builder()
+                    .subject(RECORD_READER.getName())
+                    .explanation(String.format(explanation, 
RECORD_READER.getDisplayName(), RECORD_WRITER.getDisplayName()))
+                    .valid(false)
+                    .build());

Review comment:
       The first  and third conditions are met, and I no obstacle to the 
second. Though if I change it, the validation needs to change as well. Now it 
is mandatory to have a writer if a reader is set.




-- 
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]


Reply via email to