You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nifi.apache.org by olegz <gi...@git.apache.org> on 2016/04/17 21:10:11 UTC

[GitHub] nifi pull request: NIFI-1568: Add Filter Capability to UnpackConte...

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

    https://github.com/apache/nifi/pull/248#discussion_r59990453
  
    --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/UnpackContent.java ---
    @@ -154,75 +171,85 @@ protected void init(final ProcessorInitializationContext context) {
             return properties;
         }
     
    -    @Override
    -    public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
    -        FlowFile flowFile = session.get();
    -        if (flowFile == null) {
    -            return;
    -        }
    +    @OnStopped
    +    public void onStopped() {
    +        unpacker = null;
    +        fileFilter = null;
    +    }
     
    -        final ProcessorLog logger = getLogger();
    -        String packagingFormat = context.getProperty(PACKAGING_FORMAT).getValue().toLowerCase();
    -        if (AUTO_DETECT_FORMAT.equals(packagingFormat)) {
    -            final String mimeType = flowFile.getAttribute(CoreAttributes.MIME_TYPE.key());
    -            if (mimeType == null) {
    -                logger.error("No mime.type attribute set for {}; routing to failure", new Object[]{flowFile});
    -                session.transfer(flowFile, REL_FAILURE);
    -                return;
    -            }
    +    @OnScheduled
    +    public void onScheduled(ProcessContext context) throws ProcessException {
    +        if (fileFilter == null) {
    +            fileFilter = Pattern.compile(context.getProperty(FILE_FILTER).getValue());
    +            tarUnpacker = new TarUnpacker(fileFilter);
    +            zipUnpacker = new ZipUnpacker(fileFilter);
    +            flowFileStreamV3Unpacker = new FlowFileStreamUnpacker(new FlowFileUnpackagerV3());
    +            flowFileStreamV2Unpacker = new FlowFileStreamUnpacker(new FlowFileUnpackagerV2());
    +            flowFileTarUnpacker = new FlowFileStreamUnpacker(new FlowFileUnpackagerV1());
    +        }
     
    -            switch (mimeType.toLowerCase()) {
    -                case "application/tar":
    -                    packagingFormat = TAR_FORMAT;
    -                    break;
    -                case "application/x-tar":
    -                    packagingFormat = TAR_FORMAT;
    -                    break;
    -                case "application/zip":
    -                    packagingFormat = ZIP_FORMAT;
    -                    break;
    -                case "application/flowfile-v3":
    -                    packagingFormat = FLOWFILE_STREAM_FORMAT_V3;
    -                    break;
    -                case "application/flowfile-v2":
    -                    packagingFormat = FLOWFILE_STREAM_FORMAT_V2;
    -                    break;
    -                case "application/flowfile-v1":
    -                    packagingFormat = FLOWFILE_TAR_FORMAT;
    -                    break;
    -                default: {
    -                    logger.info("Cannot unpack {} because its mime.type attribute is set to '{}', which is not a format that can be unpacked; routing to 'success'", new Object[]{flowFile, mimeType});
    -                    session.transfer(flowFile, REL_SUCCESS);
    -                    return;
    -                }
    -            }
    +        PackageFormat format = PackageFormat.getFormat(context.getProperty(PACKAGING_FORMAT).getValue());
    +        if (format != PackageFormat.AUTO_DETECT_FORMAT && unpacker == null) {
    +            initUnpacker(format);
             }
    +    }
     
    -        final Unpacker unpacker;
    -        final boolean addFragmentAttrs;
    +    public void initUnpacker(PackageFormat packagingFormat) {
             switch (packagingFormat) {
    --- End diff --
    
    This one complains with the compile-warning "The enum constant AUTO_DETECT_FORMAT needs a corresponding case label in this enum switch on UnpackContent.PackageFormat". Can you take a look?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---