Search in sources :

Example 31 with JobEntryInterface

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

the class RepositoryExporter method convertFromFileRepository.

private void convertFromFileRepository(JobMeta jobMeta) {
    if (repository instanceof KettleFileRepository) {
        KettleFileRepository fileRep = (KettleFileRepository) repository;
        // The id of the job is the filename.
        // Setting the filename also sets internal variables needed to load the trans/job referenced.
        // 
        String jobMetaFilename = fileRep.calcFilename(jobMeta.getObjectId());
        jobMeta.setFilename(jobMetaFilename);
        for (JobEntryCopy copy : jobMeta.getJobCopies()) {
            JobEntryInterface entry = copy.getEntry();
            if (entry instanceof JobEntryTrans) {
                // convert to a named based reference.
                // 
                JobEntryTrans trans = (JobEntryTrans) entry;
                if (trans.getSpecificationMethod() == ObjectLocationSpecificationMethod.FILENAME) {
                    try {
                        TransMeta meta = trans.getTransMeta(repository, repository.getMetaStore(), jobMeta);
                        FileObject fileObject = KettleVFS.getFileObject(meta.getFilename());
                        trans.setSpecificationMethod(ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME);
                        trans.setFileName(null);
                        trans.setTransname(meta.getName());
                        trans.setDirectory(Const.NVL(calcRepositoryDirectory(fileRep, fileObject), "/"));
                    } catch (Exception e) {
                        log.logError(BaseMessages.getString(PKG, "Repository.Exporter.Log.UnableToLoadJobTrans", trans.getName()), e);
                    }
                }
            }
            if (entry instanceof JobEntryJob) {
                // convert to a named based reference.
                // 
                JobEntryJob jobEntryJob = (JobEntryJob) entry;
                if (jobEntryJob.getSpecificationMethod() == ObjectLocationSpecificationMethod.FILENAME) {
                    try {
                        JobMeta meta = jobEntryJob.getJobMeta(repository, repository.getMetaStore(), jobMeta);
                        FileObject fileObject = KettleVFS.getFileObject(meta.getFilename());
                        jobEntryJob.setSpecificationMethod(ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME);
                        jobEntryJob.setFileName(null);
                        jobEntryJob.setJobName(meta.getName());
                        jobEntryJob.setDirectory(Const.NVL(calcRepositoryDirectory(fileRep, fileObject), "/"));
                    } catch (Exception e) {
                        log.logError(BaseMessages.getString(PKG, "Repository.Exporter.Log.UnableToLoadJobJob", jobEntryJob.getName()), e);
                    }
                }
            }
        }
    }
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobMeta(org.pentaho.di.job.JobMeta) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) JobEntryTrans(org.pentaho.di.job.entries.trans.JobEntryTrans) TransMeta(org.pentaho.di.trans.TransMeta) FileObject(org.apache.commons.vfs2.FileObject) JobEntryJob(org.pentaho.di.job.entries.job.JobEntryJob) KettleFileRepository(org.pentaho.di.repository.filerep.KettleFileRepository) KettleException(org.pentaho.di.core.exception.KettleException) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 32 with JobEntryInterface

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

the class RepositoryImporterTest method testImportJob_patchJobEntries_when_directory_path_ends_with_variable.

@Test
public void testImportJob_patchJobEntries_when_directory_path_ends_with_variable() throws KettleException {
    JobEntryInterface jobEntryInterface = createJobEntry("/myDir/${USER_VARIABLE}");
    StepMetaInterface stepMeta = createStepMeta("");
    RepositoryImporter importer = createRepositoryImporter(jobEntryInterface, stepMeta, true);
    importer.setBaseDirectory(baseDirectory);
    importer.importJob(entityNode, feedback);
    verify((HasRepositoryDirectories) jobEntryInterface).setDirectories(new String[] { "/myDir/${USER_VARIABLE}" });
    JobEntryInterface jobEntryInterface2 = createJobEntry("/myDir/${USER_VARIABLE}");
    RepositoryImporter importerWithCompatibilityImportPath = createRepositoryImporter(jobEntryInterface2, stepMeta, false);
    importerWithCompatibilityImportPath.setBaseDirectory(baseDirectory);
    importerWithCompatibilityImportPath.importJob(entityNode, feedback);
    verify((HasRepositoryDirectories) jobEntryInterface2).setDirectories(new String[] { ROOT_PATH + "/myDir/${USER_VARIABLE}" });
}
Also used : JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) Test(org.junit.Test)

Example 33 with JobEntryInterface

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

the class RepositoryImporterTest method createJobEntry.

private static JobEntryInterface createJobEntry(String directory) {
    JobEntryInterface jobEntryInterface = mock(JobEntryInterface.class, withSettings().extraInterfaces(HasRepositoryDirectories.class));
    when(jobEntryInterface.isReferencedObjectEnabled()).thenReturn(new boolean[] { true });
    doAnswer(invocationOnMock -> new ObjectLocationSpecificationMethod[] { ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME }).when(((HasRepositoryDirectories) jobEntryInterface)).getSpecificationMethods();
    doAnswer(invocationOnMock -> new String[] { directory }).when((HasRepositoryDirectories) jobEntryInterface).getDirectories();
    return jobEntryInterface;
}
Also used : JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface)

Example 34 with JobEntryInterface

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

the class RepositoryImporterTest method testImportTrans_patchTransEntries_with_variable.

@Test
public void testImportTrans_patchTransEntries_with_variable() throws KettleException {
    JobEntryInterface jobEntryInterface = createJobEntry("");
    StepMetaInterface stepMeta = createStepMeta("${USER_VARIABLE}");
    RepositoryImporter importer = createRepositoryImporter(jobEntryInterface, stepMeta, true);
    importer.setBaseDirectory(baseDirectory);
    importer.importTransformation(entityNode, feedback);
    verify((HasRepositoryDirectories) stepMeta).setDirectories(new String[] { "${USER_VARIABLE}" });
}
Also used : JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) Test(org.junit.Test)

Example 35 with JobEntryInterface

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

the class RepositoryImporterTest method testImportJob_patchJobEntries_when_directory_path_starts_with_variable.

@Test
public void testImportJob_patchJobEntries_when_directory_path_starts_with_variable() throws KettleException {
    JobEntryInterface jobEntryInterface = createJobEntry("${USER_VARIABLE}/myDir");
    StepMetaInterface stepMeta = createStepMeta("");
    RepositoryImporter importer = createRepositoryImporter(jobEntryInterface, stepMeta, true);
    importer.setBaseDirectory(baseDirectory);
    importer.importJob(entityNode, feedback);
    verify((HasRepositoryDirectories) jobEntryInterface).setDirectories(new String[] { "${USER_VARIABLE}/myDir" });
    JobEntryInterface jobEntryInterface2 = createJobEntry("${USER_VARIABLE}/myDir");
    RepositoryImporter importerWithCompatibilityImportPath = createRepositoryImporter(jobEntryInterface2, stepMeta, false);
    importerWithCompatibilityImportPath.setBaseDirectory(baseDirectory);
    importerWithCompatibilityImportPath.importJob(entityNode, feedback);
    verify((HasRepositoryDirectories) jobEntryInterface2).setDirectories(new String[] { ROOT_PATH + "/${USER_VARIABLE}/myDir" });
}
Also used : JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) Test(org.junit.Test)

Aggregations

JobEntryInterface (org.pentaho.di.job.entry.JobEntryInterface)43 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)27 Test (org.junit.Test)15 KettleException (org.pentaho.di.core.exception.KettleException)12 JobMeta (org.pentaho.di.job.JobMeta)9 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)8 ArrayList (java.util.ArrayList)7 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)7 Job (org.pentaho.di.job.Job)7 Result (org.pentaho.di.core.Result)5 Point (org.pentaho.di.core.gui.Point)5 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)5 JobEntryBase (org.pentaho.di.job.entry.JobEntryBase)5 NotePadMeta (org.pentaho.di.core.NotePadMeta)4 JobHopMeta (org.pentaho.di.job.JobHopMeta)4 JobEntryDialogInterface (org.pentaho.di.job.entry.JobEntryDialogInterface)4 ObjectId (org.pentaho.di.repository.ObjectId)4 Date (java.util.Date)3 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)3