Search in sources :

Example 1 with JobEntryListener

use of org.pentaho.di.job.JobEntryListener in project pentaho-kettle by pentaho.

the class JobEntrySetVariables method setParentJob.

@Override
public void setParentJob(Job parentJob) {
    super.setParentJob(parentJob);
    // PDI-16387 Add a listener for recovering changed values of variables
    JobEntryListener jobListener = new JobEntryListener() {

        @Override
        public void beforeExecution(Job job, JobEntryCopy jobEntryCopy, JobEntryInterface jobEntryInterface) {
            for (String key : changedInitialVariables.keySet()) {
                setVariable(key, changedInitialVariables.get(key));
                parentJob.setVariable(key, changedInitialVariables.get(key));
            }
            changedInitialVariables.clear();
        }

        @Override
        public void afterExecution(Job job, JobEntryCopy jobEntryCopy, JobEntryInterface jobEntryInterface, Result result) {
        }
    };
    parentJob.addJobEntryListener(jobListener);
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) JobEntryListener(org.pentaho.di.job.JobEntryListener) Job(org.pentaho.di.job.Job) Result(org.pentaho.di.core.Result)

Example 2 with JobEntryListener

use of org.pentaho.di.job.JobEntryListener in project pentaho-kettle by pentaho.

the class JobEntrySetVariablesTest method testVariableTypeCurrentJob.

@Test
public void testVariableTypeCurrentJob() throws Exception {
    entry.setFilename("src/test/resources/org/pentaho/di/job/entries/setvariables/UTF8Text.properties");
    entry.setVariableName(new String[] {});
    entry.setReplaceVars(true);
    entry.setFileVariableType(JobEntrySetVariables.VARIABLE_TYPE_CURRENT_JOB);
    Result result = entry.execute(new Result(), 0);
    for (JobEntryListener jobEntryListener : job.getJobEntryListeners()) {
        jobEntryListener.beforeExecution(job, null, entry);
    }
    Assert.assertTrue(result.getResult());
    Assert.assertNull(entry.getVariable("Japanese"));
    Assert.assertNull(entry.getVariable("English"));
    Assert.assertNull(entry.getVariable("Chinese"));
}
Also used : JobEntryListener(org.pentaho.di.job.JobEntryListener) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Aggregations

Result (org.pentaho.di.core.Result)2 JobEntryListener (org.pentaho.di.job.JobEntryListener)2 Test (org.junit.Test)1 Job (org.pentaho.di.job.Job)1 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)1 JobEntryInterface (org.pentaho.di.job.entry.JobEntryInterface)1