Search in sources :

Example 1 with GenericFileNoOpProcessStrategy

use of org.apache.camel.component.file.strategy.GenericFileNoOpProcessStrategy in project camel by apache.

the class SftpProcessStrategyFactory method createGenericFileProcessStrategy.

public static GenericFileProcessStrategy<ChannelSftp.LsEntry> createGenericFileProcessStrategy(CamelContext context, Map<String, Object> params) {
    // We assume a value is present only if its value not null for String and 'true' for boolean
    Expression moveExpression = (Expression) params.get("move");
    Expression moveFailedExpression = (Expression) params.get("moveFailed");
    Expression preMoveExpression = (Expression) params.get("preMove");
    boolean isNoop = params.get("noop") != null;
    boolean isDelete = params.get("delete") != null;
    boolean isMove = moveExpression != null || preMoveExpression != null || moveFailedExpression != null;
    if (isDelete) {
        GenericFileDeleteProcessStrategy<ChannelSftp.LsEntry> strategy = new GenericFileDeleteProcessStrategy<ChannelSftp.LsEntry>();
        strategy.setExclusiveReadLockStrategy(getExclusiveReadLockStrategy(params));
        if (preMoveExpression != null) {
            GenericFileExpressionRenamer<ChannelSftp.LsEntry> renamer = new GenericFileExpressionRenamer<ChannelSftp.LsEntry>();
            renamer.setExpression(preMoveExpression);
            strategy.setBeginRenamer(renamer);
        }
        if (moveFailedExpression != null) {
            GenericFileExpressionRenamer<ChannelSftp.LsEntry> renamer = new GenericFileExpressionRenamer<ChannelSftp.LsEntry>();
            renamer.setExpression(moveFailedExpression);
            strategy.setFailureRenamer(renamer);
        }
        return strategy;
    } else if (isMove || isNoop) {
        GenericFileRenameProcessStrategy<ChannelSftp.LsEntry> strategy = new GenericFileRenameProcessStrategy<ChannelSftp.LsEntry>();
        strategy.setExclusiveReadLockStrategy(getExclusiveReadLockStrategy(params));
        if (!isNoop && moveExpression != null) {
            // move on commit is only possible if not noop
            GenericFileExpressionRenamer<ChannelSftp.LsEntry> renamer = new GenericFileExpressionRenamer<ChannelSftp.LsEntry>();
            renamer.setExpression(moveExpression);
            strategy.setCommitRenamer(renamer);
        }
        // both move and noop supports pre move
        if (moveFailedExpression != null) {
            GenericFileExpressionRenamer<ChannelSftp.LsEntry> renamer = new GenericFileExpressionRenamer<ChannelSftp.LsEntry>();
            renamer.setExpression(moveFailedExpression);
            strategy.setFailureRenamer(renamer);
        }
        // both move and noop supports pre move
        if (preMoveExpression != null) {
            GenericFileExpressionRenamer<ChannelSftp.LsEntry> renamer = new GenericFileExpressionRenamer<ChannelSftp.LsEntry>();
            renamer.setExpression(preMoveExpression);
            strategy.setBeginRenamer(renamer);
        }
        return strategy;
    } else {
        // default strategy will do nothing
        GenericFileNoOpProcessStrategy<ChannelSftp.LsEntry> strategy = new GenericFileNoOpProcessStrategy<ChannelSftp.LsEntry>();
        strategy.setExclusiveReadLockStrategy(getExclusiveReadLockStrategy(params));
        return strategy;
    }
}
Also used : ChannelSftp(com.jcraft.jsch.ChannelSftp) Expression(org.apache.camel.Expression) GenericFileRenameProcessStrategy(org.apache.camel.component.file.strategy.GenericFileRenameProcessStrategy) GenericFileExpressionRenamer(org.apache.camel.component.file.strategy.GenericFileExpressionRenamer) GenericFileDeleteProcessStrategy(org.apache.camel.component.file.strategy.GenericFileDeleteProcessStrategy) GenericFileNoOpProcessStrategy(org.apache.camel.component.file.strategy.GenericFileNoOpProcessStrategy)

Example 2 with GenericFileNoOpProcessStrategy

use of org.apache.camel.component.file.strategy.GenericFileNoOpProcessStrategy in project camel by apache.

the class FtpProcessStrategyFactory method createGenericFileProcessStrategy.

public static GenericFileProcessStrategy<FTPFile> createGenericFileProcessStrategy(CamelContext context, Map<String, Object> params) {
    // We assume a value is present only if its value not null for String and 'true' for boolean
    Expression moveExpression = (Expression) params.get("move");
    Expression moveFailedExpression = (Expression) params.get("moveFailed");
    Expression preMoveExpression = (Expression) params.get("preMove");
    boolean isNoop = params.get("noop") != null;
    boolean isDelete = params.get("delete") != null;
    boolean isMove = moveExpression != null || preMoveExpression != null || moveFailedExpression != null;
    if (isDelete) {
        GenericFileDeleteProcessStrategy<FTPFile> strategy = new GenericFileDeleteProcessStrategy<FTPFile>();
        strategy.setExclusiveReadLockStrategy(getExclusiveReadLockStrategy(params));
        if (preMoveExpression != null) {
            GenericFileExpressionRenamer<FTPFile> renamer = new GenericFileExpressionRenamer<FTPFile>();
            renamer.setExpression(preMoveExpression);
            strategy.setBeginRenamer(renamer);
        }
        if (moveFailedExpression != null) {
            GenericFileExpressionRenamer<FTPFile> renamer = new GenericFileExpressionRenamer<FTPFile>();
            renamer.setExpression(moveFailedExpression);
            strategy.setFailureRenamer(renamer);
        }
        return strategy;
    } else if (isMove || isNoop) {
        GenericFileRenameProcessStrategy<FTPFile> strategy = new GenericFileRenameProcessStrategy<FTPFile>();
        strategy.setExclusiveReadLockStrategy(getExclusiveReadLockStrategy(params));
        if (!isNoop && moveExpression != null) {
            // move on commit is only possible if not noop
            GenericFileExpressionRenamer<FTPFile> renamer = new GenericFileExpressionRenamer<FTPFile>();
            renamer.setExpression(moveExpression);
            strategy.setCommitRenamer(renamer);
        }
        // both move and noop supports pre move
        if (moveFailedExpression != null) {
            GenericFileExpressionRenamer<FTPFile> renamer = new GenericFileExpressionRenamer<FTPFile>();
            renamer.setExpression(moveFailedExpression);
            strategy.setFailureRenamer(renamer);
        }
        // both move and noop supports pre move
        if (preMoveExpression != null) {
            GenericFileExpressionRenamer<FTPFile> renamer = new GenericFileExpressionRenamer<FTPFile>();
            renamer.setExpression(preMoveExpression);
            strategy.setBeginRenamer(renamer);
        }
        return strategy;
    } else {
        // default strategy will do nothing
        GenericFileNoOpProcessStrategy<FTPFile> strategy = new GenericFileNoOpProcessStrategy<FTPFile>();
        strategy.setExclusiveReadLockStrategy(getExclusiveReadLockStrategy(params));
        return strategy;
    }
}
Also used : Expression(org.apache.camel.Expression) GenericFileRenameProcessStrategy(org.apache.camel.component.file.strategy.GenericFileRenameProcessStrategy) GenericFileExpressionRenamer(org.apache.camel.component.file.strategy.GenericFileExpressionRenamer) FTPFile(org.apache.commons.net.ftp.FTPFile) GenericFileDeleteProcessStrategy(org.apache.camel.component.file.strategy.GenericFileDeleteProcessStrategy) GenericFileNoOpProcessStrategy(org.apache.camel.component.file.strategy.GenericFileNoOpProcessStrategy)

Aggregations

Expression (org.apache.camel.Expression)2 GenericFileDeleteProcessStrategy (org.apache.camel.component.file.strategy.GenericFileDeleteProcessStrategy)2 GenericFileExpressionRenamer (org.apache.camel.component.file.strategy.GenericFileExpressionRenamer)2 GenericFileNoOpProcessStrategy (org.apache.camel.component.file.strategy.GenericFileNoOpProcessStrategy)2 GenericFileRenameProcessStrategy (org.apache.camel.component.file.strategy.GenericFileRenameProcessStrategy)2 ChannelSftp (com.jcraft.jsch.ChannelSftp)1 FTPFile (org.apache.commons.net.ftp.FTPFile)1