fgerlits commented on code in PR #1706:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1706#discussion_r1439395796


##########
extensions/standard-processors/processors/GenerateFlowFile.cpp:
##########
@@ -58,57 +58,69 @@ void generateData(std::vector<char>& data, bool textData = 
false) {
 }
 
 void GenerateFlowFile::onSchedule(core::ProcessContext& context, 
core::ProcessSessionFactory&) {
-  if (context.getProperty(FileSize.name, fileSize_)) {
-    logger_->log_trace("File size is configured to be {}", fileSize_);
+  if (context.getProperty(FileSize.name, file_size_)) {
+    logger_->log_trace("File size is configured to be {}", file_size_);
   }
 
-  if (context.getProperty(BatchSize.name, batchSize_)) {
-    logger_->log_trace("Batch size is configured to be {}", batchSize_);
+  if (context.getProperty(BatchSize.name, batch_size_)) {
+    logger_->log_trace("Batch size is configured to be {}", batch_size_);
   }
 
-  std::string value;
-  if (context.getProperty(DataFormat.name, value)) {
-    textData_ = (value == GenerateFlowFile::DATA_FORMAT_TEXT);
+  if (auto data_format = context.getProperty(DataFormat)) {
+    textData_ = (*data_format == DATA_FORMAT_TEXT);
   }
-  if (context.getProperty(UniqueFlowFiles.name, uniqueFlowFile_)) {
-    logger_->log_trace("Unique Flow files is configured to be {}", 
uniqueFlowFile_);
+  if (context.getProperty(UniqueFlowFiles.name, unique_flow_file_)) {
+    logger_->log_trace("Unique Flow files is configured to be {}", 
unique_flow_file_);
   }
 
   std::string custom_text;
   context.getProperty(CustomText, custom_text, nullptr);
   if (!custom_text.empty()) {
-    if (textData_ && !uniqueFlowFile_) {
-      data_.assign(custom_text.begin(), custom_text.end());
+    if (textData_ && !unique_flow_file_) {
+      non_unique_data_.assign(custom_text.begin(), custom_text.end());
       return;
-    } else {
-      logger_->log_warn("Custom Text property is set, but not used!");
     }
+    logger_->log_warn("Custom Text property is set, but not used!");
   }
 
-  if (!uniqueFlowFile_) {
-    data_.resize(gsl::narrow<size_t>(fileSize_));
-    generateData(data_, textData_);
+  if (!unique_flow_file_) {
+    non_unique_data_.resize(gsl::narrow<size_t>(file_size_));
+    generateData(non_unique_data_, textData_);
+  }
+}
+
+// If the Data Format is text and if Unique FlowFiles is false, the custom 
text has to be evaluated once per batch
+void GenerateFlowFile::regenerateNonUniqueData(core::ProcessContext& context) {
+  std::string custom_text;
+  context.getProperty(CustomText, custom_text, nullptr);
+  if (!custom_text.empty()) {
+    if (textData_ && !unique_flow_file_) {
+      non_unique_data_.assign(custom_text.begin(), custom_text.end());
+      return;
+    }
+    logger_->log_warn("Custom Text property is set, but not used!");

Review Comment:
   I think this would be simpler, and would avoid doing some unnecessary work:
   ```c++
     if (!textData_ || unique_flow_file_) return;
   
     std::string custom_text;
     context.getProperty(CustomText, custom_text, nullptr);
     if (!custom_text.empty()) {
       non_unique_data_.assign(custom_text.begin(), custom_text.end());
     }
   ```
   We would lose the warning, but we have warned in `onSchedule()` already.
   
   Also, if the expanded custom text is empty now, but it wasn't empty before, 
I think the flow file should be empty, so
   ```c++
     if (!textData_ || unique_flow_file_) return;
   
     std::string custom_text;
     context.getProperty(CustomText, custom_text, nullptr);
     non_unique_data_.assign(custom_text.begin(), custom_text.end());
   ```
   would be better.



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