mirror of https://github.com/apache/nifi.git
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 <jskora@gmail.com> This closes #931.
This commit is contained in:
parent
abaacfa5e5
commit
e25885650a
|
@ -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("/");
|
||||
|
|
|
@ -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"),
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue