Results 1 to 3 of 3

Thread: Retrieving resource name (filename) from a skipListener

  1. #1
    Join Date
    Dec 2011
    Posts
    3

    Default Retrieving resource name (filename) from a skipListener

    Hello,

    I am using a MultiResourceItemReader in order to read different files in a folder.

    Processing those files might involve an exception if one record is not correctly validated (using ValangValidator), those incorrect records are being handled with a listener in order to log the incorrect record in a database.

    Which is the best approach in order to retrieve the resource name (file name being processed) from the listener that handles the skipped records? I need to store the file name in the database with the incorrect record but i am not able to do that.

    I have seen that MultiResourceItemReader now contains a method called getCurrentResource() but i do not know how to retrieve that information from my "skipListener" class.

    I think that the following post explains the solution, but I do not know how to inject a MultiResourceItemReader into my FieldSetMapper:

    http://forum.springsource.org/showth...FieldSetMapper

    Thanks a lot for your help in advance.

  2. #2

    Default

    but I do not know how to inject a MultiResourceItemReader into my FieldSetMapper
    that should be quite easy, see this pseudocode

    Code:
    <bean id="mrir" class="...MultiResourceItemReader">
    ...
    </bean>
    
    <bean id="mapper" class="...CustomFieldSetMapper">
       <property name="mrir" ref ="mrir" />
    </bean>
    you just create a custom FieldSetMapper like this

    Code:
    public class CustomFieldSetMapper implements FieldSetMapper<String> {
    
        private MultiResourceItemReader mrir;
        
        @Override
        public String mapFieldSet(FieldSet fieldSet) throws BindException {
            
            String fileName = mrir.getCurrentResource().getFilename();
            
            return fieldSet.readString("foo");
        }
    
        public void setMrir(MultiResourceItemReader mrir) {
            this.mrir = mrir;
        }
    }

  3. #3
    Join Date
    Dec 2011
    Posts
    3

    Default

    Thanks a lot Michael!

    I was mixing a couple of concepts, but now they are clear and I have been able to do that.

    Thanks a lot again!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •