Example usage for org.springframework.batch.core.configuration.annotation JobBuilderFactory get

List of usage examples for org.springframework.batch.core.configuration.annotation JobBuilderFactory get

Introduction

In this page you can find the example usage for org.springframework.batch.core.configuration.annotation JobBuilderFactory get.

Prototype

public JobBuilder get(String name) 

Source Link

Document

Creates a job builder and initializes its job repository.

Usage

From source file:de.langmi.spring.batch.examples.basics.purejava.PureJavaJobFactory.java

public static Job createJob(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
    JobBuilderFactory jobBuilderFactory = new JobBuilderFactory(jobRepository);
    StepBuilderFactory stepBuilderFactory = new StepBuilderFactory(jobRepository, transactionManager);

    Step step = stepBuilderFactory.get("step1").tasklet(new Tasklet() {

        @Override/*from  w  ww.jav a2 s  .  c  om*/
        public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
            // why not using println? because it makes testing harder, *nix and
            // windows think different about new line as in \n vs \r\n
            System.out.print("Hello World!");

            // we want the step to stop here, the other status 
            // RepeatStatus.CONTINUABLE would start an endless loop
            return RepeatStatus.FINISHED;

        }
    }).build();

    return jobBuilderFactory.get("job1").start(step).build();
}

From source file:io.spring.marchmadness.MooreStatConfiguration.java

@Bean
public Job importUserJob(JobBuilderFactory jobs, Step s1, JobExecutionListener executionListener) {
    return jobs.get("importUserJob").incrementer(new RunIdIncrementer()).listener(executionListener).flow(s1)
            .end().build();//www  . j  a v a  2  s.c  om
}

From source file:com.create.application.configuration.BatchConfiguration.java

@Bean
public Job importTicketsJob(final JobBuilderFactory jobs, final Step importTicketStep,
        final TicketImportJobExecutionListener ticketImportJobExecutionListener) {
    return jobs.get("importTicketsJob").incrementer(new RunIdIncrementer())
            .listener(ticketImportJobExecutionListener).flow(importTicketStep).end().build();
}

From source file:org.duracloud.snapshot.service.impl.RestoreJobBuilder.java

@Override
public Job buildJob(Restoration restoration, SnapshotJobManagerConfig jobManagerConfig)
        throws SnapshotException {
    Job job;// ww w  . j a v a2s  . com

    try {

        DuracloudEndPointConfig destination = restoration.getDestination();
        String destinationSpaceId = destination.getSpaceId();
        String restoreId = restoration.getRestorationId();

        StoreClientUtil clientUtil = new StoreClientUtil();
        ContentStore contentStore = clientUtil.createContentStore(destination.getHost(), destination.getPort(),
                SnapshotServiceConstants.DURASTORE_CONTEXT, jobManagerConfig.getDuracloudUsername(),
                jobManagerConfig.getDuracloudPassword(), destination.getStoreId());

        Step restoreContentStep = buildRestoreContentStep(restoreId, destinationSpaceId, contentStore,
                jobManagerConfig);
        Step restorePropertiesStep = buildRestoreContentPropertiesStep(restoreId, destinationSpaceId,
                contentStore, jobManagerConfig);

        JobBuilderFactory jobBuilderFactory = new JobBuilderFactory(jobRepository);
        JobBuilder jobBuilder = jobBuilderFactory.get(SnapshotServiceConstants.RESTORE_JOB_NAME);
        SimpleJobBuilder simpleJobBuilder = jobBuilder.start(restoreContentStep).next(restorePropertiesStep);

        simpleJobBuilder.listener(jobListener);
        job = simpleJobBuilder.build();
        log.debug("build job {}", job);
    } catch (Exception e) {
        log.error("Error creating job: {}", e.getMessage(), e);
        throw new SnapshotException(e.getMessage(), e);
    }
    return job;
}

From source file:org.duracloud.snapshot.service.impl.SnapshotJobBuilder.java

@Override
public Job buildJob(Snapshot snapshot, SnapshotJobManagerConfig config) throws SnapshotException {

    Job job;/* w  w  w  .j  a v a2s. c o m*/
    try {

        DuracloudEndPointConfig source = snapshot.getSource();
        StoreClientUtil clientUtil = new StoreClientUtil();

        ContentStore contentStore = clientUtil.createContentStore(source.getHost(), source.getPort(),
                SnapshotServiceConstants.DURASTORE_CONTEXT, config.getDuracloudUsername(),
                config.getDuracloudPassword(), source.getStoreId());

        List<String> spaces = new ArrayList<>();
        spaces.add(source.getSpaceId());

        RetrievalSource retrievalSource = new DuraStoreStitchingRetrievalSource(contentStore, spaces, false);

        ItemReader<ContentItem> itemReader = new SpaceItemReader(retrievalSource);

        File contentDir = new File(
                ContentDirUtils.getDestinationPath(snapshot.getName(), config.getContentRootDir()));
        if (!contentDir.exists()) {
            contentDir.mkdirs();
        }

        File workDir = config.getWorkDir();
        OutputWriter outputWriter = new CSVFileOutputWriter(workDir);

        BufferedWriter propsWriter = createWriter(contentDir,
                SnapshotServiceConstants.CONTENT_PROPERTIES_JSON_FILENAME);
        BufferedWriter md5Writer = createWriter(contentDir, MANIFEST_MD5_TXT_FILE_NAME);
        BufferedWriter sha256Writer = createWriter(contentDir, MANIFEST_SHA256_TXT_FILE_NAME);

        ItemWriter itemWriter = new SpaceItemWriter(snapshot, retrievalSource, contentDir, outputWriter,
                propsWriter, md5Writer, sha256Writer, snapshotManager);

        SimpleStepFactoryBean<ContentItem, File> stepFactory = new SimpleStepFactoryBean<>();
        stepFactory.setJobRepository(jobRepository);
        stepFactory.setTransactionManager(transactionManager);
        stepFactory.setBeanName("step1");
        stepFactory.setItemReader(itemReader);
        stepFactory.setItemWriter(itemWriter);
        stepFactory.setCommitInterval(1);
        stepFactory.setThrottleLimit(20);
        stepFactory.setTaskExecutor(taskExecutor);
        Step step = (Step) stepFactory.getObject();

        JobBuilderFactory jobBuilderFactory = new JobBuilderFactory(jobRepository);
        JobBuilder jobBuilder = jobBuilderFactory.get(SnapshotServiceConstants.SNAPSHOT_JOB_NAME);
        SimpleJobBuilder simpleJobBuilder = jobBuilder.start(step);
        simpleJobBuilder.listener(jobListener);

        job = simpleJobBuilder.build();
        log.debug("build job {}", job);

    } catch (Exception e) {
        log.error("Error creating job: {}", e.getMessage(), e);
        throw new SnapshotException(e.getMessage(), e);
    }
    return job;
}

From source file:org.wallerlab.yoink.config.BatchConfig.java

/**
 * build whole job using a service based job
 *
 * @param jobs//w  ww  .  j  av  a  2s.c o  m
 *            -
 *            {@link org.springframework.batch.core.configuration.annotation.JobBuilderFactory}
 *
 * @return Job -{@link org.springframework.batch.core.Job}
 */
@Bean
public org.springframework.batch.core.Job importServiceJob(JobBuilderFactory jobs) {
    return jobs.get("service").incrementer(new RunIdIncrementer()).flow(serviceStep).end().build();
}

From source file:org.wallerlab.yoink.config.BatchConfig.java

/**
 * build a batch job using a batch based approach.
 *
 * @param jobs/*from w w w.ja  v  a  2  s.  c o  m*/
 *            -
 *            {@link org.springframework.batch.core.configuration.annotation.JobBuilderFactory}
 *
 * @return Job -{@link org.springframework.batch.core.Job}
 */
@Bean
public org.springframework.batch.core.Job importBatchJob(JobBuilderFactory jobs) {
    return jobs.get("batch").incrementer(new RunIdIncrementer()).flow(batchStep).end().build();
}

From source file:org.wallerlab.yoink.config.BatchConfig.java

/**
 * build a batch job using a JMS based approach.
 *
 * @param jobs//from   w w w . j  a  v  a2s  .  c o m
 *            -
 *            {@link org.springframework.batch.core.configuration.annotation.JobBuilderFactory}
 *
 * @return Job -{@link org.springframework.batch.core.Job}
 */
@Bean
public org.springframework.batch.core.Job importJmsJob(JobBuilderFactory jobs) {
    return jobs.get("jms").incrementer(new RunIdIncrementer()).flow(jmsStep).end().build();
}

From source file:uk.ac.kcl.batch.LocalConfiguration.java

@Bean
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps, Partitioner partitioner,
        JobCompleteNotificationListener jobCompleteNotificationListener,
        @Qualifier("partitionHandler") PartitionHandler partitionHandler,
        @Qualifier("tLJobParametersIncrementer") TLJobParametersIncrementer runIdIncrementer

) {//from w ww  .ja va 2s . co m
    return jobs.get(env.getProperty("job.jobName")).incrementer(runIdIncrementer)
            .listener(jobCompleteNotificationListener)
            .flow(steps.get(jobName + "MasterStep").partitioner((jobName + "SlaveStep"), partitioner)
                    .partitionHandler(partitionHandler).build())
            .end().build();

}

From source file:uk.ac.kcl.batch.RemoteConfiguration.java

@Bean
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps, Partitioner partitioner,
        @Qualifier("partitionHandler") PartitionHandler partitionHandler,
        JobCompleteNotificationListener jobCompleteNotificationListener,
        @Qualifier("tLJobParametersIncrementer") TLJobParametersIncrementer runIdIncrementer

) {/* w  w  w.  j  a  va2 s  .  c om*/
    return jobs.get(jobName).incrementer(runIdIncrementer).listener(jobCompleteNotificationListener)
            .flow(steps.get(jobName + "MasterStep").partitioner((jobName + "SlaveStep"), partitioner)
                    .partitionHandler(partitionHandler).build())
            .end().build();

}