Example usage for org.springframework.batch.item ExecutionContext entrySet

List of usage examples for org.springframework.batch.item ExecutionContext entrySet

Introduction

In this page you can find the example usage for org.springframework.batch.item ExecutionContext entrySet.

Prototype

public Set<Entry<String, Object>> entrySet() 

Source Link

Document

Returns the entry set containing the contents of this context.

Usage

From source file:uk.ac.ebi.intact.editor.controller.admin.AdminJobController.java

public Map<String, String> getImportStatistics(JobExecution jobExecution) {
    Collection<StepExecution> stepExecutions = jobExecution.getStepExecutions();
    Map<String, String> statistics = new HashMap<String, String>();
    if (!stepExecutions.isEmpty()) {
        StepExecution firstStep = stepExecutions.iterator().next();
        ExecutionContext stepContext = firstStep.getExecutionContext();

        for (Map.Entry<String, Object> entry : stepContext.entrySet()) {
            // persisted count
            if (entry.getKey().startsWith(AbstractIntactDbImporter.PERSIST_MAP_COUNT)) {
                statistics.put(entry.getKey().substring(entry.getKey().lastIndexOf("_") + 1),
                        Integer.toString((Integer) entry.getValue()));
            }// ww  w  . j av a2s . co m
        }
    }
    return statistics;
}

From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapExecutionContextDao.java

private ExecutionContext copy(ExecutionContext original) {
    if (original == null)
        return null;
    Map<String, Object> m = new HashMap<String, Object>();
    for (java.util.Map.Entry<String, Object> me : original.entrySet()) {
        m.put(me.getKey(), me.getValue());
    }/*w w w  .  j a  v a  2 s .  co m*/
    ExecutionContext copy = new ExecutionContext();
    Map<String, Object> map = serializer.deserialize(serializer.serialize(m));
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        copy.put(entry.getKey(), entry.getValue());
    }
    return copy;
}

From source file:uk.ac.ebi.intact.editor.controller.dbmanager.ImportJobController.java

public List<Map.Entry<String, String>> getImportStatistics(JobExecution jobExecution) {
    Collection<StepExecution> stepExecutions = jobExecution.getStepExecutions();
    Map<String, String> statistics = new HashMap<String, String>();
    if (!stepExecutions.isEmpty()) {
        StepExecution firstStep = stepExecutions.iterator().next();
        ExecutionContext stepContext = firstStep.getExecutionContext();

        for (Map.Entry<String, Object> entry : stepContext.entrySet()) {
            // persisted count
            if (entry.getKey().startsWith(AbstractIntactDbImporter.PERSIST_MAP_COUNT)) {
                statistics.put(entry.getKey().substring(entry.getKey().lastIndexOf(".") + 1),
                        Integer.toString((Integer) entry.getValue()));
            }// w w w .j a v a  2  s .co m
        }
    }
    return new ArrayList<Map.Entry<String, String>>(statistics.entrySet());
}

From source file:trionsoft.test.StepRunner.java

/**
 * Launch just the specified step as its own job. An IllegalStateException
 * is thrown if there is no Step with the given name.
 * /*from   www.j  a v a 2  s  . c o  m*/
 * @param stepName The name of the step to launch
 * @param jobParameters The JobParameters to use during the launch
 * @param jobExecutionContext An ExecutionContext whose values will be
 * loaded into the Job ExecutionContext prior to launching the step.
 * @return JobExecution
 */
public JobExecution launchStep(Step step, JobParameters jobParameters,
        final ExecutionContext jobExecutionContext) {
    //
    // Create a fake job
    //
    SimpleJob job = new SimpleJob();
    job.setName("TestJob");
    job.setJobRepository(this.jobRepository);

    List<Step> stepsToExecute = new ArrayList<Step>();
    stepsToExecute.add(step);
    job.setSteps(stepsToExecute);

    //
    // Dump the given Job ExecutionContext using a listener
    //
    if (jobExecutionContext != null && !jobExecutionContext.isEmpty()) {
        job.setJobExecutionListeners(new JobExecutionListener[] { new JobExecutionListenerSupport() {
            public void beforeJob(JobExecution jobExecution) {
                ExecutionContext jobContext = jobExecution.getExecutionContext();
                for (Map.Entry<String, Object> entry : jobExecutionContext.entrySet()) {
                    jobContext.put(entry.getKey(), entry.getValue());
                }
            }
        } });
    }

    //
    // Launch the job
    //
    return this.launchJob(job, jobParameters);
}

From source file:org.springframework.batch.test.StepRunner.java

/**
 * Launch just the specified step as its own job. An IllegalStateException
 * is thrown if there is no Step with the given name.
 *
 * @param step The step to launch//from w w w  .  j a  v a  2s. c om
 * @param jobParameters The JobParameters to use during the launch
 * @param jobExecutionContext An ExecutionContext whose values will be
 * loaded into the Job ExecutionContext prior to launching the step.
 * @return JobExecution
 */
public JobExecution launchStep(Step step, JobParameters jobParameters,
        final ExecutionContext jobExecutionContext) {
    //
    // Create a fake job
    //
    SimpleJob job = new SimpleJob();
    job.setName("TestJob");
    job.setJobRepository(this.jobRepository);

    List<Step> stepsToExecute = new ArrayList<Step>();
    stepsToExecute.add(step);
    job.setSteps(stepsToExecute);

    //
    // Dump the given Job ExecutionContext using a listener
    //
    if (jobExecutionContext != null && !jobExecutionContext.isEmpty()) {
        job.setJobExecutionListeners(new JobExecutionListener[] { new JobExecutionListenerSupport() {
            @Override
            public void beforeJob(JobExecution jobExecution) {
                ExecutionContext jobContext = jobExecution.getExecutionContext();
                for (Map.Entry<String, Object> entry : jobExecutionContext.entrySet()) {
                    jobContext.put(entry.getKey(), entry.getValue());
                }
            }
        } });
    }

    //
    // Launch the job
    //
    return this.launchJob(job, jobParameters);
}