fgerlits commented on code in PR #1706:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1706#discussion_r1441765143
##########
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:
Yes, good point: we used to treat a `Custom Text` set to empty the same as
if it wasn't set at all, which is consistent with most other processors, and we
probably don't want to change that.
I'm OK with either remembering in `onSchedule` if `Custom Text` was empty,
and using that info here, or to just treat a `Custom Text` expanded to empty as
if it was empty originally -- whichever you prefer. A non-empty `Custom Text`
expanding to empty is an edge case which may never happen in real life.
--
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]