title: creating logic inside Spring Batch using Tasklet or inside CompositeItemWriter?
body: <p>I have created 3 files writers that creates 3 local files. But all the information that is read goes into each file the same way. I am trying to set some logic so that only the items that are being called go into their proper file. For Example: fileA,FileB,FileC are created. When the reader hits the MONGODB it should parse through the buisness column and find the 3 different types, TypeA,TypeB, and TypeC. Once the reader has found the different types it should add it to the appropriate file, instead of printing everything to each file created. FileA should only have the information from TypeA there shouldnt be any other information written other than that. Is there a way to do it? here is what my code looks like.</p>
  
  <p>ItemReader:</p>
  
  <pre><code>  @Bean
    public MongoItemReader&lt;PaymentAudit&gt; mongoreader() {
      LOG.debug("Mongo-Reader");    
      @SuppressWarnings("unchecked")
      MongoItemReader&lt;PaymentAudit&gt; mongoreader = new MongoItemReader();
      mongoreader.setTemplate(mongoTemplate);
      mongoreader.setQuery("{}");
      mongoreader.setTargetType(PaymentAudit.class);
      mongoreader.setSort(new HashMap&lt;String, Sort.Direction&gt;() {
          {
              put("_id", Direction.ASC);
          }
      });
      return mongoreader;
    }
  </code></pre>
  
  <p>FileItemWriter:</p>
  
  <pre><code>   @StepScope
  @Bean
  public FlatFileItemWriter&lt;PaymentAudit&gt; writer() {
      LOG.debug("Mongo-writer");  
      String exportFilePath="C:\\filewriter\\retail.txt";
      FlatFileItemWriter&lt;PaymentAudit&gt; flatFile = new 
   FlatFileItemWriterBuilder&lt;PaymentAudit&gt;()
              .name("")
              .resource(new FileSystemResource(exportFilePath))
              .lineAggregator(createPaymentPortalLineAggregator())
              .build();
      String exportFileHeader = "TypeA";
      StringHeaderWriter headerWriter = new 
    StringHeaderWriter(exportFileHeader);
      flatFile.setHeaderCallback(headerWriter);
      return flatFile;
  
  }
  @Bean
  public FlatFileItemWriter&lt;PaymentAudit&gt; writer2() {
      LOG.debug("flatFileItemWriter");    
      String exportFilePath="C:\\filewriter\\hcc.txt";
      FlatFileItemWriter&lt;PaymentAudit&gt; flatFile = new 
    FlatFileItemWriterBuilder&lt;PaymentAudit&gt;()
              .name("")
              .resource(new FileSystemResource(exportFilePath))
              .lineAggregator(createPaymentPortalLineAggregator())
              .build();
      String exportFileHeader = "TypeB";
      StringHeaderWriter headerWriter = new 
      StringHeaderWriter(exportFileHeader);
      flatFile.setHeaderCallback(headerWriter);
      return flatFile;
  
  }
  @Bean
  public FlatFileItemWriter&lt;PaymentAudit&gt; writer3() {
      LOG.debug("Mongo-writer");  
      String exportFilePath="C:\\filewriter\\srx.txt";
      FlatFileItemWriter&lt;PaymentAudit&gt; flatFile = new 
      FlatFileItemWriterBuilder&lt;PaymentAudit&gt;()
              .name("")
              .resource(new FileSystemResource(exportFilePath))
              .lineAggregator(createPaymentPortalLineAggregator())
              .build();
      String exportFileHeader = "TypeC";
      StringHeaderWriter headerWriter = new 
      StringHeaderWriter(exportFileHeader);
      flatFile.setHeaderCallback(headerWriter);
      return flatFile;
  
  }
  
  @SuppressWarnings({ "unchecked", "rawtypes" })
  public CompositeItemWriter&lt;PaymentAudit&gt; compositeItemWriter(){
      CompositeItemWriter writer = new CompositeItemWriter();
  
  
    private LineAggregator&lt;PaymentAudit&gt; createPaymentPortalLineAggregator() {
      DelimitedLineAggregator&lt;PaymentAudit&gt; lineAggregator = new 
      DelimitedLineAggregator&lt;&gt;();
      lineAggregator.setDelimiter("|");
      FieldExtractor&lt;PaymentAudit&gt; fieldExtractor = 
      createPaymentPortalFieldExtractor();
      lineAggregator.setFieldExtractor(fieldExtractor);
      return lineAggregator;
  }
  
  private FieldExtractor&lt;PaymentAudit&gt; createPaymentPortalFieldExtractor() {
      BeanWrapperFieldExtractor&lt;PaymentAudit&gt; extractor = new 
  BeanWrapperFieldExtractor&lt;&gt;();
      extractor.setNames(new String[] { "TypeA, TypeB, TypeC"});      
      return extractor;
  }
  </code></pre>