Search in sources :

Example 1 with TaskletStep

use of org.springframework.batch.core.step.tasklet.TaskletStep in project head by mifos.

the class MifosScheduler method schedule.

@Deprecated
public void schedule(final String jobName, Date initialTime, long delay, JobRegistry jobRegistry, final JobRepository jobRepository, Map<String, Object> jobData, ResourcelessTransactionManager transactionManager) throws TaskSystemException {
    try {
        final TaskletStep step = new TaskletStep();
        step.setName(jobName);
        Tasklet tasklet = (Tasklet) Class.forName(BATCH_JOB_CLASS_PATH_PREFIX + getHelperName(jobName)).newInstance();
        step.setTasklet(tasklet);
        step.setJobRepository(jobRepository);
        step.setTransactionManager(transactionManager);
        step.afterPropertiesSet();
        jobRegistry.register(new JobFactory() {

            @Override
            public Job createJob() {
                SimpleJob job = new SimpleJob(jobName + "Job");
                job.setJobRepository(jobRepository);
                job.setRestartable(true);
                job.registerJobExecutionListener(new BatchJobListener());
                job.addStep(step);
                return job;
            }

            @Override
            public String getJobName() {
                return jobName + "Job";
            }
        });
    } catch (Exception e) {
        throw new TaskSystemException(e);
    }
    JobDetailBean jobDetailBean = new JobDetailBean();
    jobDetailBean.setJobDataAsMap(jobData);
    try {
        jobDetailBean.setJobClass(Class.forName(BATCH_JOB_CLASS_PATH_PREFIX + jobName));
    } catch (ClassNotFoundException cnfe) {
        throw new TaskSystemException(cnfe);
    }
    jobDetailBean.setName(jobName + "Job");
    jobDetailBean.setGroup(Scheduler.DEFAULT_GROUP);
    jobDetailBean.afterPropertiesSet();
    SimpleTrigger trigger = new SimpleTrigger();
    trigger.setName(jobName + "Job");
    trigger.setGroup(Scheduler.DEFAULT_GROUP);
    trigger.setStartTime(initialTime);
    trigger.setRepeatInterval(delay);
    trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
    try {
        scheduler.scheduleJob(jobDetailBean, trigger);
    } catch (SchedulerException se) {
        throw new TaskSystemException(se);
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) JobDetailBean(org.springframework.scheduling.quartz.JobDetailBean) Tasklet(org.springframework.batch.core.step.tasklet.Tasklet) TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) SchedulerException(org.quartz.SchedulerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) IOException(java.io.IOException) JobFactory(org.springframework.batch.core.configuration.JobFactory) TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) SimpleJob(org.springframework.batch.core.job.SimpleJob) TaskletStep(org.springframework.batch.core.step.tasklet.TaskletStep) Job(org.springframework.batch.core.Job) SimpleJob(org.springframework.batch.core.job.SimpleJob) SimpleTrigger(org.quartz.SimpleTrigger)

Example 2 with TaskletStep

use of org.springframework.batch.core.step.tasklet.TaskletStep in project head by mifos.

the class MifosScheduler method scheduleLoanArrearsAndPortfolioAtRisk.

@Deprecated
public void scheduleLoanArrearsAndPortfolioAtRisk(Date initialTime, long delay, JobRegistry jobRegistry, final JobRepository jobRepository, Map<String, Object> jobData, ResourcelessTransactionManager transactionManager) throws TaskSystemException {
    final String jobName = "LoanArrearsAndPortfolioAtRiskTask";
    try {
        final TaskletStep step1 = new TaskletStep();
        step1.setName("LoanArrearsAndPortfolioAtRiskTask-step-1");
        step1.setTasklet((Tasklet) Class.forName(BATCH_JOB_CLASS_PATH_PREFIX + getHelperName("LoanArrearsTask")).newInstance());
        step1.setJobRepository(jobRepository);
        step1.setTransactionManager(transactionManager);
        step1.afterPropertiesSet();
        final TaskletStep step2 = new TaskletStep();
        step2.setName("LoanArrearsAndPortfolioAtRiskTask-step-2");
        step2.setTasklet((Tasklet) Class.forName(BATCH_JOB_CLASS_PATH_PREFIX + getHelperName("PortfolioAtRiskTask")).newInstance());
        step2.setJobRepository(jobRepository);
        step2.setTransactionManager(transactionManager);
        step2.afterPropertiesSet();
        jobRegistry.register(new JobFactory() {

            @Override
            public Job createJob() {
                SimpleJob job = new SimpleJob(jobName + "Job");
                job.setJobRepository(jobRepository);
                job.setRestartable(true);
                job.registerJobExecutionListener(new BatchJobListener());
                job.addStep(step1);
                job.addStep(step2);
                return job;
            }

            @Override
            public String getJobName() {
                return jobName + "Job";
            }
        });
    } catch (Exception e) {
        throw new TaskSystemException(e);
    }
    JobDetailBean jobDetailBean = new JobDetailBean();
    jobDetailBean.setJobDataAsMap(jobData);
    try {
        jobDetailBean.setJobClass(Class.forName(BATCH_JOB_CLASS_PATH_PREFIX + "PortfolioAtRiskTask"));
    } catch (ClassNotFoundException cnfe) {
        throw new TaskSystemException(cnfe);
    }
    jobDetailBean.setName(jobName + "Job");
    jobDetailBean.setGroup(Scheduler.DEFAULT_GROUP);
    jobDetailBean.afterPropertiesSet();
    SimpleTrigger trigger = new SimpleTrigger();
    trigger.setName(jobName + "Job");
    trigger.setGroup(Scheduler.DEFAULT_GROUP);
    trigger.setStartTime(initialTime);
    trigger.setRepeatInterval(delay);
    trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
    try {
        scheduler.scheduleJob(jobDetailBean, trigger);
    } catch (SchedulerException se) {
        throw new TaskSystemException(se);
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) JobDetailBean(org.springframework.scheduling.quartz.JobDetailBean) TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) SchedulerException(org.quartz.SchedulerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) IOException(java.io.IOException) JobFactory(org.springframework.batch.core.configuration.JobFactory) TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) SimpleJob(org.springframework.batch.core.job.SimpleJob) TaskletStep(org.springframework.batch.core.step.tasklet.TaskletStep) Job(org.springframework.batch.core.Job) SimpleJob(org.springframework.batch.core.job.SimpleJob) SimpleTrigger(org.quartz.SimpleTrigger)

Example 3 with TaskletStep

use of org.springframework.batch.core.step.tasklet.TaskletStep in project hub-alert by blackducksoftware.

the class CommonConfigTest method testCreateStep.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testCreateStep() {
    final StepBuilderFactory stepBuilderFactory = Mockito.mock(StepBuilderFactory.class);
    final TaskExecutor taskExecutor = Mockito.mock(TaskExecutor.class);
    final PlatformTransactionManager transactionManager = Mockito.mock(PlatformTransactionManager.class);
    final C config = getConfigWithParams(stepBuilderFactory, taskExecutor, transactionManager);
    final R reader = getMockReader();
    final P processor = getMockProcessor();
    final W writer = getMockWriter();
    final StepBuilder stepBuilder = Mockito.mock(StepBuilder.class);
    final SimpleStepBuilder simpleStepBuilder = Mockito.mock(SimpleStepBuilder.class);
    final AbstractTaskletStepBuilder abstractTaskletStepBuilder = Mockito.mock(AbstractTaskletStepBuilder.class);
    Mockito.when(stepBuilderFactory.get(Mockito.anyString())).thenReturn(stepBuilder);
    Mockito.when(stepBuilder.chunk(Mockito.anyInt())).thenReturn(simpleStepBuilder);
    Mockito.when(simpleStepBuilder.reader(reader)).thenReturn(simpleStepBuilder);
    Mockito.when(simpleStepBuilder.processor(processor)).thenReturn(simpleStepBuilder);
    Mockito.when(simpleStepBuilder.writer(writer)).thenReturn(simpleStepBuilder);
    Mockito.when(simpleStepBuilder.taskExecutor(taskExecutor)).thenReturn(abstractTaskletStepBuilder);
    Mockito.when(abstractTaskletStepBuilder.transactionManager(transactionManager)).thenReturn(abstractTaskletStepBuilder);
    Mockito.when(abstractTaskletStepBuilder.build()).thenReturn(new TaskletStep());
    final Step step = config.createStep(reader, processor, writer);
    assertNotNull(step);
}
Also used : AbstractTaskletStepBuilder(org.springframework.batch.core.step.builder.AbstractTaskletStepBuilder) TaskExecutor(org.springframework.core.task.TaskExecutor) AbstractTaskletStepBuilder(org.springframework.batch.core.step.builder.AbstractTaskletStepBuilder) SimpleStepBuilder(org.springframework.batch.core.step.builder.SimpleStepBuilder) StepBuilder(org.springframework.batch.core.step.builder.StepBuilder) SimpleStepBuilder(org.springframework.batch.core.step.builder.SimpleStepBuilder) StepBuilderFactory(org.springframework.batch.core.configuration.annotation.StepBuilderFactory) TaskletStep(org.springframework.batch.core.step.tasklet.TaskletStep) Step(org.springframework.batch.core.Step) TaskletStep(org.springframework.batch.core.step.tasklet.TaskletStep) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) Test(org.junit.Test)

Aggregations

TaskletStep (org.springframework.batch.core.step.tasklet.TaskletStep)3 IOException (java.io.IOException)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 TaskSystemException (org.mifos.framework.components.batchjobs.exceptions.TaskSystemException)2 SchedulerException (org.quartz.SchedulerException)2 SimpleTrigger (org.quartz.SimpleTrigger)2 Job (org.springframework.batch.core.Job)2 JobFactory (org.springframework.batch.core.configuration.JobFactory)2 SimpleJob (org.springframework.batch.core.job.SimpleJob)2 JobDetailBean (org.springframework.scheduling.quartz.JobDetailBean)2 Test (org.junit.Test)1 Step (org.springframework.batch.core.Step)1 StepBuilderFactory (org.springframework.batch.core.configuration.annotation.StepBuilderFactory)1 AbstractTaskletStepBuilder (org.springframework.batch.core.step.builder.AbstractTaskletStepBuilder)1 SimpleStepBuilder (org.springframework.batch.core.step.builder.SimpleStepBuilder)1 StepBuilder (org.springframework.batch.core.step.builder.StepBuilder)1 Tasklet (org.springframework.batch.core.step.tasklet.Tasklet)1 TaskExecutor (org.springframework.core.task.TaskExecutor)1 PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)1