| 115 | } |
| 116 | |
| 117 | void ManipulateArchive::onTrigger(core::ProcessContext* /*context*/, core::ProcessSession *session) { |
| 118 | std::shared_ptr<core::FlowFile> flowFile = session->get(); |
| 119 | |
| 120 | if (!flowFile) { |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | ArchiveMetadata archiveMetadata; |
| 125 | fileutils::FileManager file_man; |
| 126 | |
| 127 | FocusArchiveEntry::ReadCallback readCallback(this, &file_man, &archiveMetadata); |
| 128 | session->read(flowFile, &readCallback); |
| 129 | |
| 130 | auto entries_end = archiveMetadata.entryMetadata.end(); |
| 131 | |
| 132 | auto target_position = archiveMetadata.find(targetEntry_); |
| 133 | |
| 134 | if (target_position == entries_end && operation_ != OPERATION_TOUCH) { |
| 135 | logger_->log_warn("ManipulateArchive could not find entry %s to %s!", |
| 136 | targetEntry_, operation_); |
| 137 | session->transfer(flowFile, Failure); |
| 138 | return; |
| 139 | } else { |
| 140 | logger_->log_info("ManipulateArchive found %s for %s.", |
| 141 | targetEntry_, operation_); |
| 142 | } |
| 143 | |
| 144 | if (!destination_.empty()) { |
| 145 | auto dest_position = archiveMetadata.find(destination_); |
| 146 | if (dest_position != entries_end) { |
| 147 | logger_->log_warn("ManipulateArchive cannot perform %s to existing destination_ %s!", |
| 148 | operation_, destination_); |
| 149 | session->transfer(flowFile, Failure); |
| 150 | return; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | auto position = entries_end; |
| 155 | |
| 156 | // Small speedup for when neither before or after are provided or needed |
| 157 | if ((!before_.empty() || !after_.empty()) && operation_ != OPERATION_REMOVE) { |
| 158 | std::string positionEntry = after_.empty() ? before_ : after_; |
| 159 | position = archiveMetadata.find(positionEntry); |
| 160 | |
| 161 | if (position == entries_end) |
| 162 | logger_->log_warn("ManipulateArchive could not find entry %s to " |
| 163 | "perform %s %s; appending to end of archive...", |
| 164 | positionEntry, operation_, |
| 165 | after_.empty() ? "before" : "after"); |
| 166 | |
| 167 | else |
| 168 | logger_->log_info("ManipulateArchive found entry %s to %s %s.", |
| 169 | positionEntry, operation_, |
| 170 | after_.empty() ? "before" : "after"); |
| 171 | |
| 172 | if (!after_.empty() && position != entries_end) |
| 173 | position++; |
| 174 | } |
nothing calls this directly
no test coverage detected