[ 
https://issues.apache.org/jira/browse/MINIFICPP-39?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16210999#comment-16210999
 ] 

ASF GitHub Bot commented on MINIFICPP-39:
-----------------------------------------

Github user phrocker commented on a diff in the pull request:

    https://github.com/apache/nifi-minifi-cpp/pull/148#discussion_r145691644
  
    --- Diff: libminifi/src/processors/FocusArchiveEntry.cpp ---
    @@ -0,0 +1,340 @@
    +/**
    + * @file FocusArchiveEntry.cpp
    + * FocusArchiveEntry class implementation
    + *
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +#include "processors/FocusArchiveEntry.h"
    +
    +#include <archive.h>
    +#include <archive_entry.h>
    +
    +#include <string.h>
    +
    +#include <boost/filesystem.hpp>
    +
    +#include <string>
    +#include <set>
    +
    +#include <iostream>
    +#include <fstream>
    +#include <memory>
    +
    +#include "core/ProcessContext.h"
    +#include "core/ProcessSession.h"
    +
    +#include "json/json.h"
    +#include "json/writer.h"
    +
    +namespace org {
    +namespace apache {
    +namespace nifi {
    +namespace minifi {
    +namespace processors {
    +
    +core::Property FocusArchiveEntry::Path(
    +    "Path",
    +    "The path within the archive to focus (\"/\" to focus the total 
archive)",
    +    "");
    +core::Relationship FocusArchiveEntry::Success(
    +    "success",
    +    "success operational on the flow record");
    +
    +bool 
FocusArchiveEntry::set_del_or_update_attr(std::shared_ptr<core::FlowFile> 
flowFile, const std::string key, std::string* value) const {
    +  if (value == nullptr)
    +    return flowFile->removeAttribute(key);
    +  else if (flowFile->updateAttribute(key, *value))
    +    return true;
    +  else
    +    return flowFile->addAttribute(key, *value);
    +}
    +
    +void FocusArchiveEntry::initialize() {
    +  //! Set the supported properties
    +  std::set<core::Property> properties;
    +  properties.insert(Path);
    +  setSupportedProperties(properties);
    +  //! Set the supported relationships
    +  std::set<core::Relationship> relationships;
    +  relationships.insert(Success);
    +  setSupportedRelationships(relationships);
    +}
    +
    +void FocusArchiveEntry::onTrigger(core::ProcessContext *context,
    +                                  core::ProcessSession *session) {
    +  auto flowFile = session->get();
    +  std::shared_ptr<FlowFileRecord> flowFileRecord = 
std::static_pointer_cast<FlowFileRecord>(flowFile);
    +
    +  if (!flowFile) {
    +    return;
    +  }
    +
    +  std::string targetEntry;
    +  context->getProperty(Path.getName(), targetEntry);
    +
    +  // Extract archive contents
    +  ArchiveMetadata archiveMetadata;
    +  archiveMetadata.focusedEntry = targetEntry;
    +  ReadCallback cb(&archiveMetadata);
    +  session->read(flowFile, &cb);
    +
    +  // For each extracted entry, import & stash to key
    +  std::string targetEntryStashKey;
    +
    +  for (auto &entryMetadata : archiveMetadata.entryMetadata) {
    +    if (entryMetadata.entryType == AE_IFREG) {
    +      logger_->log_info("FocusArchiveEntry importing %s from %s",
    +          entryMetadata.entryName.c_str(),
    +          entryMetadata.tmpFileName.c_str());
    +      session->import(entryMetadata.tmpFileName, flowFile, false, 0);
    +      char stashKey[37];
    +      uuid_t stashKeyUuid;
    --- End diff --
    
    Is there any reason you were unable to use the ID generator? 


> Create FocusArchive processor
> -----------------------------
>
>                 Key: MINIFICPP-39
>                 URL: https://issues.apache.org/jira/browse/MINIFICPP-39
>             Project: NiFi MiNiFi C++
>          Issue Type: Task
>            Reporter: Andrew Christianson
>            Assignee: Andrew Christianson
>            Priority: Minor
>
> Create an FocusArchive processor which implements a lens over an archive 
> (tar, etc.). A concise, though informal, definition of a lens is as follows:
> "Essentially, they represent the act of “peering into” or “focusing in on” 
> some particular piece/path of a complex data object such that you can more 
> precisely target particular operations without losing the context or 
> structure of the overall data you’re working with." 
> https://medium.com/@dtipson/functional-lenses-d1aba9e52254#.hdgsvbraq
> Why an FocusArchive in MiNiFi? Simply put, it will enable us to "focus in on" 
> an entry in the archive, perform processing *in-context* of that entry, then 
> re-focus on the overall archive. This allows for transformation or other 
> processing of an entry in the archive without losing the overall context of 
> the archive.
> Initial format support is tar, due to its simplicity and ubiquity.
> Attributes:
> - Path (the path in the archive to focus; "/" to re-focus the overall archive)



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to