Example usage for org.springframework.batch.core.scope.context StepSynchronizationManager getContext

List of usage examples for org.springframework.batch.core.scope.context StepSynchronizationManager getContext

Introduction

In this page you can find the example usage for org.springframework.batch.core.scope.context StepSynchronizationManager getContext.

Prototype

@Nullable
public static StepContext getContext() 

Source Link

Document

Getter for the current context if there is one, otherwise returns null .

Usage

From source file:de.codecentric.batch.metrics.AbstractBatchMetricsAspect.java

private String getStepIdentifier() {
    StepContext stepContext = StepSynchronizationManager.getContext();
    StepExecution stepExecution = StepSynchronizationManager.getContext().getStepExecution();
    return stepContext.getJobName() + "." + stepExecution.getStepName();
}

From source file:fr.acxio.tools.agia.file.pdf.MergePDFProcessor.java

private StepExecution getStepExecution() {
    StepContext context = StepSynchronizationManager.getContext();
    if (context == null) {
        return null;
    }/*w w w  .  j  a  va  2 s  .co  m*/
    return context.getStepExecution();
}

From source file:de.codecentric.batch.metrics.BatchMetricsImpl.java

private StepExecution getStepExecution() {
    if (StepSynchronizationManager.getContext() != null) {
        return StepSynchronizationManager.getContext().getStepExecution();
    }//  www. j a v  a  2  s  . co m
    return null;
}

From source file:org.springframework.batch.core.jsr.configuration.support.BatchPropertyBeanPostProcessor.java

private String getBeanPropertyName(String beanName) {
    StepContext stepContext = StepSynchronizationManager.getContext();

    if (stepContext != null) {
        String stepName = stepContext.getStepName();
        String jobName = stepContext.getStepExecution().getJobExecution().getJobInstance().getJobName();
        return jobName + "." + stepName + "." + beanName.substring("scopedTarget.".length());
    }// w  w w. j  av a  2 s  .  c o  m

    return beanName;
}

From source file:org.springframework.batch.core.jsr.launch.support.BatchPropertyBeanPostProcessor.java

private Properties getArtifactProperties(String artifactName) {
    String originalArtifactName = artifactName;

    if (originalArtifactName.startsWith(SCOPED_TARGET_BEAN_PREFIX)) {
        originalArtifactName = artifactName.substring(SCOPED_TARGET_BEAN_PREFIX.length());
    }//from w w  w  .j  av  a  2s.  c  o  m

    StepContext stepContext = StepSynchronizationManager.getContext();

    if (stepContext != null) {
        return batchPropertyContext.getStepArtifactProperties(stepContext.getStepName(), originalArtifactName);
    }

    return batchPropertyContext.getArtifactProperties(originalArtifactName);
}

From source file:org.springframework.batch.core.scope.StepScope.java

/**
 * Get an attribute accessor in the form of a {@link StepContext} that can
 * be used to store scoped bean instances.
 *
 * @return the current step context which we can use as a scope storage
 * medium/*from  w  ww .ja va 2s  . c o  m*/
 */
private StepContext getContext() {
    StepContext context = StepSynchronizationManager.getContext();
    if (context == null) {
        throw new IllegalStateException("No context holder available for step scope");
    }
    return context;
}