Example usage for org.springframework.integration.ftp.filters FtpRegexPatternFileListFilter FtpRegexPatternFileListFilter

List of usage examples for org.springframework.integration.ftp.filters FtpRegexPatternFileListFilter FtpRegexPatternFileListFilter

Introduction

In this page you can find the example usage for org.springframework.integration.ftp.filters FtpRegexPatternFileListFilter FtpRegexPatternFileListFilter.

Prototype

public FtpRegexPatternFileListFilter(Pattern pattern) 

Source Link

Usage

From source file:org.springframework.cloud.stream.app.ftp.source.FtpSourceConfiguration.java

@Bean
public IntegrationFlow ftpInboundFlow(SessionFactory<FTPFile> ftpSessionFactory, FtpSourceProperties properties,
        FileConsumerProperties fileConsumerProperties) {
    FtpInboundChannelAdapterSpec messageSourceBuilder = Ftp.inboundAdapter(ftpSessionFactory)
            .preserveTimestamp(properties.isPreserveTimestamp()).remoteDirectory(properties.getRemoteDir())
            .remoteFileSeparator(properties.getRemoteFileSeparator()).localDirectory(properties.getLocalDir())
            .autoCreateLocalDirectory(properties.isAutoCreateLocalDir())
            .temporaryFileSuffix(properties.getTmpFileSuffix())
            .deleteRemoteFiles(properties.isDeleteRemoteFiles());

    if (StringUtils.hasText(properties.getFilenamePattern())) {
        messageSourceBuilder.filter(new FtpSimplePatternFileListFilter(properties.getFilenamePattern()));
    } else if (properties.getFilenameRegex() != null) {
        messageSourceBuilder.filter(new FtpRegexPatternFileListFilter(properties.getFilenameRegex()));
    }//from  ww  w .  j  av  a  2 s.c o m

    IntegrationFlowBuilder flowBuilder = IntegrationFlows.from(messageSourceBuilder,
            new Consumer<SourcePollingChannelAdapterSpec>() {

                @Override
                public void accept(SourcePollingChannelAdapterSpec sourcePollingChannelAdapterSpec) {
                    sourcePollingChannelAdapterSpec.poller(FtpSourceConfiguration.this.defaultPoller);
                }

            });

    return FileUtils.enhanceFlowForReadingMode(flowBuilder, fileConsumerProperties)
            .channel(this.source.output()).get();
}

From source file:org.springframework.integration.dsl.ftp.FtpInboundChannelAdapterSpec.java

@Override
public FtpInboundChannelAdapterSpec regexFilter(String regex) {
    return filter(new FtpRegexPatternFileListFilter(regex));
}

From source file:org.springframework.integration.dsl.ftp.FtpOutboundGatewaySpec.java

@Override
public FtpOutboundGatewaySpec regexFileNameFilter(String regex) {
    return filter(new FtpRegexPatternFileListFilter(regex));
}

From source file:org.springframework.integration.ftp.dsl.FtpInboundChannelAdapterSpec.java

/**
 * Specify a regular expression to match remote files.
 * @param regex the expression.//from  w w w.j  a va  2  s  .c om
 * @see FtpRegexPatternFileListFilter
 * @see #filter(org.springframework.integration.file.filters.FileListFilter)
 */
@Override
public FtpInboundChannelAdapterSpec regexFilter(String regex) {
    return filter(composeFilters(new FtpRegexPatternFileListFilter(regex)));
}

From source file:org.springframework.integration.ftp.dsl.FtpOutboundGatewaySpec.java

/**
 * @see FtpRegexPatternFileListFilter/*ww  w. j a  v  a  2 s. c o m*/
 */
@Override
public FtpOutboundGatewaySpec regexFileNameFilter(String regex) {
    return filter(new FtpRegexPatternFileListFilter(regex));
}

From source file:org.springframework.integration.ftp.dsl.FtpStreamingInboundChannelAdapterSpec.java

/**
 * Specify a regular expression to match remote files (e.g. '[0-9].*.txt').
 * @param regex the expression./*from   ww  w.j ava2  s  .  co m*/
 * @see FtpRegexPatternFileListFilter
 * @see #filter(org.springframework.integration.file.filters.FileListFilter)
 */
@Override
public FtpStreamingInboundChannelAdapterSpec regexFilter(String regex) {
    return filter(composeFilters(new FtpRegexPatternFileListFilter(regex)));
}

From source file:org.springframework.integration.ftp.inbound.FtpInboundRemoteFileSystemSynchronizerTests.java

@Test
public void testCopyFileToLocalDir() throws Exception {
    File localDirectoy = new File("test");
    assertFalse(localDirectoy.exists());

    TestFtpSessionFactory ftpSessionFactory = new TestFtpSessionFactory();
    ftpSessionFactory.setUsername("kermit");
    ftpSessionFactory.setPassword("frog");
    ftpSessionFactory.setHost("foo.com");
    FtpInboundFileSynchronizer synchronizer = spy(new FtpInboundFileSynchronizer(ftpSessionFactory));
    synchronizer.setDeleteRemoteFiles(true);
    synchronizer.setRemoteDirectory("remote-test-dir");
    synchronizer.setFilter(new FtpRegexPatternFileListFilter(".*\\.test$"));
    synchronizer.setIntegrationEvaluationContext(ExpressionUtils.createStandardEvaluationContext());

    ExpressionParser expressionParser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
    Expression expression = expressionParser.parseExpression("#this.toUpperCase() + '.a'");
    synchronizer.setLocalFilenameGeneratorExpression(expression);

    FtpInboundFileSynchronizingMessageSource ms = new FtpInboundFileSynchronizingMessageSource(synchronizer);

    ms.setAutoCreateLocalDirectory(true);

    ms.setLocalDirectory(localDirectoy);
    ms.afterPropertiesSet();/*w w  w .j  ava  2s. c  o m*/
    Message<File> atestFile = ms.receive();
    assertNotNull(atestFile);
    assertEquals("A.TEST.a", atestFile.getPayload().getName());
    Message<File> btestFile = ms.receive();
    assertNotNull(btestFile);
    assertEquals("B.TEST.a", btestFile.getPayload().getName());
    Message<File> nothing = ms.receive();
    assertNull(nothing);

    // two times because on the third receive (above) the internal queue will be empty, so it will attempt
    verify(synchronizer, times(2)).synchronizeToLocalDirectory(localDirectoy);

    assertTrue(new File("test/A.TEST.a").exists());
    assertTrue(new File("test/B.TEST.a").exists());
}