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}/to/{toId}", method = RequestMethod.GET)
    public String launchJinniJob(@PathVariable Long fromId,
                                 @PathVariable Long toId) throws Exception
    {
        jinniJobLauncher.launch(fromId, toId);
        return "Crawling job started";
    }

    @RequestMapping(value = "/failedMovies/from/{fromId}/to/{toId}", method = RequestMethod.GET)
    public String launchFailedMoviesJob(@PathVariable Long fromId,
                                        @PathVariable Long toId) throws Exception
    {
        failedMoviesJobLauncher.launch(fromId, toId);
        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.";
    }

}
@@ -1048,32 +1048,36 @@
 om/%7BfromId%7D/
-to/%7BtoId
+range/%7Brange
 %7D%22, method =
@@ -1200,36 +1200,37 @@
 thVariable Long 
-toId
+range
 ) throws Excepti
@@ -1270,36 +1270,37 @@
 .launch(fromId, 
-toId
+range
 );%0A        retur
@@ -1393,16 +1393,20 @@
 Id%7D/
-to/%7BtoId
+range/%7Brange
 %7D%22, 
@@ -1559,20 +1559,21 @@
 le Long 
-toId
+range
 ) throws
@@ -1640,12 +1640,13 @@
 Id, 
-toId
+range
 );%0A 

Fix rest methods launchJob and launchFailedMovies