Skip to content

Commit

Permalink
Merge pull request #2089 from AvintisSolutions/feature/WSO2-213
Browse files Browse the repository at this point in the history
Add transport parameters transport.vfs.MinimumAge and transport.vfs.MaximumAge
  • Loading branch information
arunans23 authored Sep 3, 2024
2 parents c3a88cb + 4d0a0f1 commit 807576e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ public final class VFSConstants {
public static final String SCHEME_FTPS = "ftps";
// sftp scheme file option list
public static enum SFTP_FILE_OPTION {Identities, UserDirIsRoot, IdentityPassPhrase};

/** Parameter for minimum age **/
public static final String TRANSPORT_FILE_MINIMUM_AGE = "transport.vfs.MinimumAge";
/** Parameter for maximum age **/
public static final String TRANSPORT_FILE_MAXIMUM_AGE = "transport.vfs.MaximumAge";

public static final String FILE_TYPE_PREFIX = "transport.vfs.fileType";
public static final String FILE_TYPE = "filetype";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ public class PollTableEntry extends AbstractPollTableEntry {

private static final Log log = LogFactory.getLog(PollTableEntry.class);

private Long minimumAge = null; //defines a minimum age of a file before being consumed. Use to avoid just written files to be consumed
private Long maximumAge = null; //defines a maximum age of a file being consumed. Old files will stay in the directory


public PollTableEntry(boolean fileLocking) {
this.fileLocking = fileLocking;
}
Expand Down Expand Up @@ -537,6 +541,14 @@ public void setSubfolderTimestamp(String subfolderTimestamp) {
this.subfolderTimestamp = subfolderTimestamp;
}

public Long getMinimumAge() {
return minimumAge;
}

public Long getMaximumAge() {
return maximumAge;
}

@Override
public boolean loadConfiguration(ParameterInclude params) throws AxisFault {
decryptParamsIfRequired(params);
Expand Down Expand Up @@ -742,6 +754,23 @@ protected boolean loadConfigurationsFromService(ParameterInclude params) throws
}
}

String strMinimumAge = ParamUtils.getOptionalParam(params, VFSConstants.TRANSPORT_FILE_MINIMUM_AGE);
if(strMinimumAge != null){
try {
minimumAge = Long.parseLong(strMinimumAge);
} catch (NumberFormatException nfe) {
log.warn("VFS File MinimumAge value is invalid : " + strMinimumAge, nfe);
}
}
String strMaximumAge = ParamUtils.getOptionalParam(params, VFSConstants.TRANSPORT_FILE_MAXIMUM_AGE);
if(strMaximumAge != null){
try {
maximumAge = Long.parseLong(strMaximumAge);
} catch (NumberFormatException nfe) {
log.warn("VFS File MaximumAge value is invalid : " + strMinimumAge, nfe);
}
}

String strAutoLock = ParamUtils.getOptionalParam(params,
VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE);
autoLockRelease = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,22 @@ protected void scanFileOrDirectory(final PollTableEntry entry, String fileURI) {
isFailedRecord = isFailedRecord(child, entry);
}

if(entry.getMinimumAge() != null){
long age = child.getContent().getLastModifiedTime();
long time = System.currentTimeMillis();
if((time-age)/1000 <= entry.getMinimumAge()){
continue;
}
}

if(entry.getMaximumAge() != null){
long age = child.getContent().getLastModifiedTime();
long time = System.currentTimeMillis();
if((time-age)/1000 >= entry.getMaximumAge()){
continue;
}
}

if(entry.getFileNamePattern()!=null &&
child.getName().getBaseName().matches(entry.getFileNamePattern())){
//child's file name matches the file name pattern
Expand Down

0 comments on commit 807576e

Please sign in to comment.