/**
  * creates a batch job that fetches the latest file for a given pattern, moving older files to a
  * skipped directory.
  *
  * @param config configuration of downloader job.
  * @param client remote client operations <b>The caller is responsible to release resources after
  *     the Job executes, if applicable.<b>
  * @param remoteConfiguration remote client storage configuration.
  * @param fileType type of file that one wants to download.
  * @return Batch Job that can be executed.
  */
 public static BatchJob<SftpFilename, ControlFilePersistenceOutputInfo>
     makeOldFilesMovingLatestFileDownloaderJob(
         final CtlDownloaderJob.Configuration config,
         final RemoteClient client,
         final RemoteConfiguration remoteConfiguration,
         final FileType fileType) {
   return makeDownloaderJob(
       config,
       client,
       remoteConfiguration,
       new SftpOldFilesMovingLatestFileFetcher(
           client,
           remoteConfiguration.getSkippedFolder(),
           remoteConfiguration.getProcessingFolder(),
           remoteConfiguration.getIncomingFolder(),
           fileType));
 }
  /**
   * creates the batch job.
   *
   * @param config configuration of downloader job.
   * @param client remote client operations <b>The caller is responsible to release resources after
   *     the Job executes, if applicable.<b>
   * @param remoteConfiguration remote client storage configuration.
   * @param fileFetcher Provides the names of the Files that should be fetched
   * @return Batch Job that can be executed.
   */
  public static BatchJob<SftpFilename, ControlFilePersistenceOutputInfo> makeDownloaderJob(
      final CtlDownloaderJob.Configuration config,
      final RemoteClient client,
      final RemoteConfiguration remoteConfiguration,
      final Fetcher<SftpFilename> fileFetcher) {

    final Processor<FetchedItem<SftpFilename>, SftpFilename, ControlFilePersistenceOutputInfo>
        downloader =
            Processors.controlledFileWriter(
                config.getDownloadDirPath(),
                config.getControlFileEnding(),
                new SftpDownloadingFileWriterAdapter(client));

    final SftpResultFileMover remoteFileMover =
        new SftpResultFileMover(client, remoteConfiguration.getArchivedFolder());

    return new BatchJob.Builder<SftpFilename, ControlFilePersistenceOutputInfo>()
        .setFetcher(fileFetcher)
        .addListener(new BatchStatisticsLoggingListener<>(CtlDownloaderJob.LOG_NAME_BATCH))
        .addListener(new ItemProgressLoggingListener<>(CtlDownloaderJob.LOG_NAME_ITEM))
        .setProcessor(Processors.compose(remoteFileMover, downloader))
        .setProcessingBatchSize(1 /*No advantage in processing multiple files at once*/)
        .build();
  }