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


##########
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've refactored a little bit so Its easier to see what determines the output 
mode
   Made sure that we dont break compatibility so CustomText "" is the same as 
no CustomText, but if CustomText were to evaluate to "" we would create an 
empty FF.
   
https://github.com/apache/nifi-minifi-cpp/pull/1706/commits/626d69c49f1c2ba04ccbd36d3ceba1fff6062e76



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