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);
}
}
}
}
}
}
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}" });
}
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;
}
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}" });
}
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" });
}
Aggregations