Announcement Announcement Module
No announcement yet.
Passing some objects from controller to batch-step Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing some objects from controller to batch-step

    Hello I am a currently new to Spring Batch.And i am facing a difficulty which I searched alot but can't find the solution.My requirement is to process N folders through N policy templates.For example first step will check if the Folder Name is according to my policy or not ,second step will check analyse the files mime type inside the folder according to policy template etc etc...I have configured my steps properly. Upto this point the day was having sunshine for me but I am stuck at point where i need to pass values from my controller method to spring batch.Like selected folders by user and the policy templates from database.So my question is how to pass the objects from controller to my first step of batch process.

    Following is my configuration regarding batch job.


    <!--Batch job configuration starts here-->
        <bean id="jobLauncher" class=""
        <batch:job-repository id="jobRepository"
        <bean id="jobOperator" class="">
            <property name="jobExplorer">
                <bean class="">
                    <property name="dataSource" ref="safeJNDI" />
            <property name="jobRepository" ref="jobRepository" />
            <property name="jobLauncher" ref="jobLauncher" />
            <property name="jobRegistry" ref="jobRegistry"/>
        <bean id="jobRegistry" class=""/>
        <batch:job id="templateMatchingJob" restartable="true">
                <batch:listener ref="templateMatchingJobListener"></batch:listener>
           <batch:step id="basicRuleCheckerStep">
                <batch:tasklet ref="basicRuleCheckerTasklet" />
                <batch:next on="COMPLETED" to="checkMainObjectStep" />
                <batch:next on="FAILED" to="logAndShowErrorMessage" />
                    <batch:listener ref="basicRuleCheckerListener"></batch:listener>
            <batch:step id="checkMainObjectStep">
                <batch:tasklet ref="mainObjectCheckerTasklet" />
                <batch:next on="COMPLETED" to="checkDBXML" />
                <batch:next on="FAILED" to="logAndShowErrorMessage" />
                    <batch:listener ref="mainObjectCheckerListener"></batch:listener>
            <batch:step id="checkDBXML">
                <batch:tasklet ref="dbXMLCheckerTasklet" />
                <batch:next on="COMPLETED" to="checkPDIXML" />
                <batch:next on="FAILED" to="logAndShowErrorMessage" />
                    <batch:listener ref="dbXMLCheckerListener"></batch:listener>
            <batch:step id="checkPDIXML">
                <batch:tasklet ref="pdiXMLCheckerTasklet" />
                <!-- the next is enclosure checking -->
                <batch:next on="COMPLETED" to="logAndShowErrorMessage" />
                <batch:next on="FAILED" to="logAndShowErrorMessage" />
                    <batch:listener ref="pdiXMLCheckerListener"></batch:listener>
            <batch:step id="logAndShowErrorMessage">
                <batch:tasklet ref="logAndShowErrorTasklet" />
                    <batch:listener ref="logAndShowErrorListener"></batch:listener>
       <!--Tasklets for template Matching starts here-->
        <bean id="basicRuleCheckerTasklet" class=""/>
        <bean id="mainObjectCheckerTasklet" class="">
        <bean id="pdiXMLCheckerTasklet" class=""/>
        <bean id="dbXMLCheckerTasklet" class=""/>
        <bean id="logAndShowErrorTasklet" class=""/>
       <!--Tasklets for template Matching ends here-->
       <!--Listeners for each step in Batch Template Matching starts here-->
        <bean id="basicRuleCheckerListener" class=""/>
        <bean id="mainObjectCheckerListener" class=""/>
        <bean id="pdiXMLCheckerListener" class=""/>
        <bean id="dbXMLCheckerListener" class=""/>
        <bean id="logAndShowErrorListener" class=""/>
        <bean id="templateMatchingJobListener" class="" />
       <!--Listeners for each step in Batch Template Matching ends here-->

    @RequestMapping(value = "/decision/batch", method = RequestMethod.POST)
        @ExceptionHandler(value = {GenericException.class})
        public ModelAndView batchMoveFolder(@ModelAttribute(KEY_LOGGED_IN_USER) User whoLoggedIn,      @RequestParam String action, ModelMap model, HttpServletRequest request) 
         //Getting the selected folder list
             /** Details omitted for clarity**/
        //Getting the templates available in database
             /** Details omitted for clarity**/
        //Starting the job
   ,new JobParametersBuilder().addDate(new Date()));   
    I am sorry for my bad English but I was not getting any better way of putting this.Any help is appreciated.

  • #2
    Pass them as JobParameters just like the date... You can only pass simple objects so you will need to do some conversion in your batch job (unless the properties are simple strings)...


    • #3
      Thanks for replying....This is what i have done passing the folder names as parameter.....Is there any better way of achieving this.Suggest me if there's any...Thank you.


      • #4
        The folder names are job parameters so no there isn't a better way this is the way to pass arguments to the batch job.