Repository: nifi Updated Branches: refs/heads/master abaacfa5e -> e25885650
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 Signed-off-by: Joe Skora <[email protected]> This closes #931. Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/e2588565 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/e2588565 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/e2588565 Branch: refs/heads/master Commit: e25885650a169ae2639355f2ba69a0405071188b Parents: abaacfa Author: Kirk Tarou <[email protected]> Authored: Mon Aug 22 16:34:46 2016 -0700 Committer: Joe Skora <[email protected]> Committed: Fri Sep 9 22:44:23 2016 -0400 ---------------------------------------------------------------------- .../processors/standard/ListFileTransfer.java | 23 ++++++++++++-------- .../nifi/processors/standard/ListSFTP.java | 8 ++++--- 2 files changed, 19 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/e2588565/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListFileTransfer.java ---------------------------------------------------------------------- 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 2cc3aae..f4557dc 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.ProcessContext; 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<FileInfo> { public static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder() @@ -66,14 +70,15 @@ public abstract class ListFileTransfer extends AbstractListProcessor<FileInfo> { @Override protected Map<String, String> createAttributes(final FileInfo fileInfo, final ProcessContext context) { final Map<String, String> 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("/"); http://git-wip-us.apache.org/repos/asf/nifi/blob/e2588565/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListSFTP.java ---------------------------------------------------------------------- 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 f2df7da..a145329 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 @@ import org.apache.nifi.processors.standard.util.SFTPTransfer; @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"), })
