MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / processBin

Method processBin

extensions/libarchive/MergeContent.cpp:266–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

264}
265
266bool MergeContent::processBin(core::ProcessContext *context, core::ProcessSession *session, std::unique_ptr<Bin> &bin) {
267 if (mergeStrategy_ != merge_content_options::MERGE_STRATEGY_DEFRAGMENT && mergeStrategy_ != merge_content_options::MERGE_STRATEGY_BIN_PACK)
268 return false;
269
270 if (mergeStrategy_ == merge_content_options::MERGE_STRATEGY_DEFRAGMENT) {
271 // check the flowfile fragment values
272 if (!checkDefragment(bin)) {
273 logger_->log_error("Merge Content check defgrament failed");
274 return false;
275 }
276 // sort the flowfile fragment index
277 std::deque<std::shared_ptr<core::FlowFile>> &flows = bin->getFlowFile();
278 std::sort(flows.begin(), flows.end(), [] (const std::shared_ptr<core::FlowFile> &first, const std::shared_ptr<core::FlowFile> &second)
279 {std::string value;
280 first->getAttribute(BinFiles::FRAGMENT_INDEX_ATTRIBUTE, value);
281 int indexFirst = std::stoi(value);
282 second->getAttribute(BinFiles::FRAGMENT_INDEX_ATTRIBUTE, value);
283 int indexSecond = std::stoi(value);
284 if (indexSecond > indexFirst)
285 return true;
286 else
287 return false;
288 });
289 }
290
291 std::shared_ptr<core::FlowFile> merge_flow = std::static_pointer_cast<FlowFileRecord>(session->create());
292 if (attributeStrategy_ == merge_content_options::ATTRIBUTE_STRATEGY_KEEP_COMMON)
293 KeepOnlyCommonAttributesMerger(bin->getFlowFile()).mergeAttributes(session, merge_flow);
294 else if (attributeStrategy_ == merge_content_options::ATTRIBUTE_STRATEGY_KEEP_ALL_UNIQUE)
295 KeepAllUniqueAttributesMerger(bin->getFlowFile()).mergeAttributes(session, merge_flow);
296 else {
297 logger_->log_error("Attribute strategy not supported %s", attributeStrategy_);
298 return false;
299 }
300
301 auto flowFileReader = [&] (const std::shared_ptr<core::FlowFile>& ff, InputStreamCallback* cb) {
302 return session->read(ff, cb);
303 };
304
305 const char* mimeType;
306 std::unique_ptr<MergeBin> mergeBin;
307 std::unique_ptr<minifi::FlowFileSerializer> serializer = utils::make_unique<PayloadSerializer>(flowFileReader);
308 if (mergeFormat_ == merge_content_options::MERGE_FORMAT_CONCAT_VALUE) {
309 mergeBin = utils::make_unique<BinaryConcatenationMerge>(headerContent_, footerContent_, demarcatorContent_);
310 mimeType = "application/octet-stream";
311 } else if (mergeFormat_ == merge_content_options::MERGE_FORMAT_FLOWFILE_STREAM_V3_VALUE) {
312 // disregard header, demarcator, footer
313 mergeBin = utils::make_unique<BinaryConcatenationMerge>("", "", "");
314 serializer = utils::make_unique<FlowFileV3Serializer>(flowFileReader);
315 mimeType = "application/flowfile-v3";
316 } else if (mergeFormat_ == merge_content_options::MERGE_FORMAT_TAR_VALUE) {
317 mergeBin = utils::make_unique<TarMerge>();
318 mimeType = "application/tar";
319 } else if (mergeFormat_ == merge_content_options::MERGE_FORMAT_ZIP_VALUE) {
320 mergeBin = utils::make_unique<ZipMerge>();
321 mimeType = "application/zip";
322 } else {
323 logger_->log_error("Merge format not supported %s", mergeFormat_);

Callers

nothing calls this directly

Calls 15

log_errorMethod · 0.80
getFlowFileMethod · 0.80
mergeAttributesMethod · 0.80
log_infoMethod · 0.80
to_stringFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
getAttributeMethod · 0.45
createMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected