package ba.aljovic.amer.component.webservice;

import ba.aljovic.amer.batch.launcher.FailedMoviesJobLauncher;
import ba.aljovic.amer.batch.launcher.JinniJobLauncher;
import org.springframework.batch.core.launch.JobExecutionNotRunningException;
import org.springframework.batch.core.launch.JobOperator;
import org.springframework.batch.core.launch.NoSuchJobException;
import org.springframework.batch.core.launch.NoSuchJobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@RestController
public class BatchController
{
    @Autowired
    private JinniJobLauncher jinniJobLauncher;

    @Autowired
    FailedMoviesJobLauncher failedMoviesJobLauncher;

    @Autowired
    private JobOperator jobOperator;

    @RequestMapping(value = "/crawl/from/{fromId}/range/{range}", method = RequestMethod.GET)
    public String launchJinniJob(@PathVariable Long fromId,
                                 @PathVariable Long range) throws Exception
    {
        jinniJobLauncher.launch(fromId, range);
        return "Crawling job started";
    }

    @RequestMapping(value = "/failedMovies/from/{fromId}/range/{range}", method = RequestMethod.GET)
    public String launchFailedMoviesJob(@PathVariable Long fromId,
                                        @PathVariable Long range) throws Exception
    {
        failedMoviesJobLauncher.launch(fromId, range);
        return "Failed movies job started";
    }

    @RequestMapping(value = "/stopJob/{jobName}", method = RequestMethod.GET)
    public String stopJob(@PathVariable String jobName)
            throws NoSuchJobException, NoSuchJobExecutionException, JobExecutionNotRunningException
    {
        Set<Long> executions = jobOperator.getRunningExecutions(jobName);
        for(Long executionId : executions)
        {
            jobOperator.stop(executionId);
        }
        return jobName + " successfully stopped.";
    }

}
@@ -155,24 +155,69 @@
 obLauncher;%0A
+import ba.aljovic.amer.database.MovieFacade;%0A
 import org.s
@@ -1043,24 +1043,69 @@
 bOperator;%0A%0A
+    @Autowired%0A    MovieFacade movieFacade;%0A%0A
     @Request
@@ -2263,9 +2263,200 @@
 %0A    %7D%0A%0A
+    @RequestMapping(value = %22/resetDatabase%22, method = RequestMethod.GET)%0A    public String resetDatabase()%0A    %7B%0A        movieFacade.deleteALl();%0A        return %22Deleted all tables%22;%0A    %7D%0A%0A
 %7D

Add "resetDatabase" method to web service to easily wipe the whole database