From 1926e5fce72cf65ba964a7613696cd2b50b1ba96 Mon Sep 17 00:00:00 2001 From: Kirk Tarou Date: Mon, 22 Aug 2016 16:34:46 -0700 Subject: [PATCH] NIFI-2440 - Add 'file.lastModifiedTime' attribute to ListSFTP processor Added 'file.lastModifiedTime' attribute to ListFileTransfer, which is the abstract class extended by ListSFTP. String literal attribute names were replaced with static references to attribute name constants in ListFile. ListFileTransfer stores the 'file.lastModifiedTime' attribute in the format specified in ListFile.FILE_MODIFY_DATE_ATTR_FORMAT Updated WritesAttribute description for file last modify time attribute to mirror the entry in ListFile --- .../processors/standard/ListFileTransfer.java | 23 +++++++++++-------- .../nifi/processors/standard/ListSFTP.java | 8 ++++--- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListFileTransfer.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListFileTransfer.java index 2cc3aae383aa..f4557dc37d6b 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListFileTransfer.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListFileTransfer.java @@ -18,10 +18,8 @@ package org.apache.nifi.processors.standard; import java.io.IOException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import org.apache.commons.io.IOUtils; import org.apache.nifi.components.PropertyDescriptor; @@ -30,6 +28,12 @@ import org.apache.nifi.processor.util.StandardValidators; import org.apache.nifi.processors.standard.util.FileInfo; import org.apache.nifi.processors.standard.util.FileTransfer; +import java.util.Map; +import java.util.HashMap; +import java.util.List; +import java.util.Iterator; +import java.util.Date; +import java.util.Locale; public abstract class ListFileTransfer extends AbstractListProcessor { public static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder() @@ -66,14 +70,15 @@ public abstract class ListFileTransfer extends AbstractListProcessor { @Override protected Map createAttributes(final FileInfo fileInfo, final ProcessContext context) { final Map attributes = new HashMap<>(); + final DateFormat formatter = new SimpleDateFormat(ListFile.FILE_MODIFY_DATE_ATTR_FORMAT, Locale.US); attributes.put(getProtocolName() + ".remote.host", context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue()); attributes.put(getProtocolName() + ".remote.port", context.getProperty(UNDEFAULTED_PORT).evaluateAttributeExpressions().getValue()); - attributes.put("file.owner", fileInfo.getOwner()); - attributes.put("file.group", fileInfo.getGroup()); - attributes.put("file.permissions", fileInfo.getPermissions()); - attributes.put(CoreAttributes.FILENAME.key(), fileInfo.getFileName()); attributes.put(getProtocolName() + ".listing.user", context.getProperty(USERNAME).evaluateAttributeExpressions().getValue()); - + attributes.put(ListFile.FILE_LAST_MODIFY_TIME_ATTRIBUTE, formatter.format(new Date(fileInfo.getLastModifiedTime()))); + attributes.put(ListFile.FILE_PERMISSIONS_ATTRIBUTE, fileInfo.getPermissions()); + attributes.put(ListFile.FILE_OWNER_ATTRIBUTE, fileInfo.getOwner()); + attributes.put(ListFile.FILE_GROUP_ATTRIBUTE, fileInfo.getGroup()); + attributes.put(CoreAttributes.FILENAME.key(), fileInfo.getFileName()); final String fullPath = fileInfo.getFullPathFileName(); if (fullPath != null) { final int index = fullPath.lastIndexOf("/"); diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListSFTP.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListSFTP.java index f2df7da248ff..a14532957d45 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListSFTP.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListSFTP.java @@ -45,9 +45,11 @@ @WritesAttribute(attribute = "sftp.remote.host", description = "The hostname of the SFTP Server"), @WritesAttribute(attribute = "sftp.remote.port", description = "The port that was connected to on the SFTP Server"), @WritesAttribute(attribute = "sftp.listing.user", description = "The username of the user that performed the SFTP Listing"), - @WritesAttribute(attribute = "file.owner", description = "The numeric owner id of the source file"), - @WritesAttribute(attribute = "file.group", description = "The numeric group id of the source file"), - @WritesAttribute(attribute = "file.permissions", description = "The read/write/execute permissions of the source file"), + @WritesAttribute(attribute = ListFile.FILE_OWNER_ATTRIBUTE, description = "The numeric owner id of the source file"), + @WritesAttribute(attribute = ListFile.FILE_GROUP_ATTRIBUTE, description = "The numeric group id of the source file"), + @WritesAttribute(attribute = ListFile.FILE_PERMISSIONS_ATTRIBUTE, description = "The read/write/execute permissions of the source file"), + @WritesAttribute(attribute = ListFile.FILE_LAST_MODIFY_TIME_ATTRIBUTE, description = "The timestamp of when the file in the filesystem was" + + "last modified as 'yyyy-MM-dd'T'HH:mm:ssZ'"), @WritesAttribute(attribute = "filename", description = "The name of the file on the SFTP Server"), @WritesAttribute(attribute = "path", description = "The fully qualified name of the directory on the SFTP Server from which the file was pulled"), })