Search in sources :

Example 1 with KettleFileRepository

use of org.pentaho.di.repository.filerep.KettleFileRepository in project pentaho-kettle by pentaho.

the class RepositoryExporter method convertFromFileRepository.

private void convertFromFileRepository(TransMeta transMeta) {
    Object[] metaInjectObjectArray = new Object[4];
    metaInjectObjectArray[0] = transMeta;
    metaInjectObjectArray[1] = PKG;
    if (repository instanceof KettleFileRepository) {
        KettleFileRepository fileRep = (KettleFileRepository) repository;
        metaInjectObjectArray[2] = fileRep;
        // The id of the transformation is the relative filename.
        // Setting the filename also sets internal variables needed to load the trans/job referenced.
        // 
        String transMetaFilename = fileRep.calcFilename(transMeta.getObjectId());
        transMeta.setFilename(transMetaFilename);
        for (StepMeta stepMeta : transMeta.getSteps()) {
            if (stepMeta.isMapping()) {
                MappingMeta mappingMeta = (MappingMeta) stepMeta.getStepMetaInterface();
                // 
                if (mappingMeta.getSpecificationMethod() == ObjectLocationSpecificationMethod.FILENAME) {
                    try {
                        TransMeta meta = MappingMeta.loadMappingMeta(mappingMeta, fileRep, fileRep.metaStore, transMeta);
                        FileObject fileObject = KettleVFS.getFileObject(meta.getFilename());
                        mappingMeta.setSpecificationMethod(ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME);
                        mappingMeta.setFileName(null);
                        mappingMeta.setTransName(meta.getName());
                        mappingMeta.setDirectoryPath(Const.NVL(calcRepositoryDirectory(fileRep, fileObject), "/"));
                    } catch (Exception e) {
                        log.logError(BaseMessages.getString(PKG, "Repository.Exporter.Log.UnableToLoadTransInMap", mappingMeta.getName()), e);
                    }
                }
            }
            metaInjectObjectArray[3] = stepMeta;
            try {
                ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.RepositoryExporterPatchTransStep.id, metaInjectObjectArray);
            } catch (KettleException ke) {
                log.logError(ke.getMessage(), ke);
            }
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) MappingMeta(org.pentaho.di.trans.steps.mapping.MappingMeta) TransMeta(org.pentaho.di.trans.TransMeta) FileObject(org.apache.commons.vfs2.FileObject) FileObject(org.apache.commons.vfs2.FileObject) StepMeta(org.pentaho.di.trans.step.StepMeta) 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 2 with KettleFileRepository

use of org.pentaho.di.repository.filerep.KettleFileRepository in project pentaho-kettle by pentaho.

the class JobExportIT method setUp.

@Before
public void setUp() throws KettleException {
    KettleFileRepositoryMeta repositoryMeta = new KettleFileRepositoryMeta(FILE_REPOSITORY_ID, FILE_REPOSITORY_NAME, FILE_REPOSITORY_DESC, REPOSITORY_ROOT_DIR);
    repository = new KettleFileRepository();
    repository.init(repositoryMeta);
    repository.connect(null, null);
}
Also used : KettleFileRepositoryMeta(org.pentaho.di.repository.filerep.KettleFileRepositoryMeta) KettleFileRepository(org.pentaho.di.repository.filerep.KettleFileRepository) Before(org.junit.Before)

Example 3 with KettleFileRepository

use of org.pentaho.di.repository.filerep.KettleFileRepository in project pentaho-kettle by pentaho.

the class JobImportIT method setUp.

@Before
public void setUp() throws KettleException {
    KettleEnvironment.init();
    Props.init(Props.TYPE_PROPERTIES_SPOON);
    deleteFolder(new File(REPOSITORY_ROOT_DIR));
    KettleFileRepositoryMeta repositoryMeta = new KettleFileRepositoryMeta(FILE_REPOSITORY_ID, FILE_REPOSITORY_NAME, FILE_REPOSITORY_DESC, REPOSITORY_ROOT_DIR);
    repository = new KettleFileRepository();
    repository.init(repositoryMeta);
    repository.connect(null, null);
    importer = new RepositoryImporter(repository);
}
Also used : KettleFileRepositoryMeta(org.pentaho.di.repository.filerep.KettleFileRepositoryMeta) RepositoryImporter(org.pentaho.di.repository.RepositoryImporter) File(java.io.File) KettleFileRepository(org.pentaho.di.repository.filerep.KettleFileRepository) Before(org.junit.Before)

Example 4 with KettleFileRepository

use of org.pentaho.di.repository.filerep.KettleFileRepository in project pentaho-kettle by pentaho.

the class KettleFileRepositoryIT method testDatabaseRepository.

public void testDatabaseRepository() throws Exception {
    KettleEnvironment.init();
    String dirName = System.getProperty("java.io.tmpdir") + "/" + UUID.randomUUID();
    File dirFile = new File(dirName);
    if (!dirFile.mkdir()) {
        throw new KettleException("bad luck, directory '" + dirName + "' already exists and can't be used to put a file repository in it.");
    }
    System.out.println("Using folder '" + dirName + "' to store a file repository in.");
    try {
        repositoryMeta = new KettleFileRepositoryMeta("KettleFileRepository", "FileRep", "File repository", dirName);
        repository = new KettleFileRepository();
        repository.init(repositoryMeta);
        // Test connecting... (no security needed)
        // 
        repository.connect(null, null);
        assertTrue(repository.isConnected());
        // Test loading the directory tree
        // 
        tree = repository.loadRepositoryDirectoryTree();
        assertNotNull(tree);
        // Test directory creation
        // 
        RepositoryDirectoryInterface fooDirectory = repository.createRepositoryDirectory(tree, "foo");
        RepositoryDirectoryInterface barDirectory = repository.createRepositoryDirectory(fooDirectory, "bar");
        RepositoryDirectoryInterface samplesDirectory = repository.createRepositoryDirectory(fooDirectory, "samples");
        // Test directory path lookup
        RepositoryDirectoryInterface checkBar = tree.findDirectory("/foo/bar");
        assertNotNull(checkBar);
        assertTrue(checkBar.equals(barDirectory));
        // Save all the transformations samples.
        // 
        verifyTransformationSamples(samplesDirectory);
        verifyJobSamples(samplesDirectory);
        // Verify metastore functionality
        // 
        IMetaStore metaStore = repository.getMetaStore();
        KettleMetaStoreTestBase testBase = new KettleMetaStoreTestBase();
        testBase.testFunctionality(metaStore);
        // Test directory deletion
        repository.deleteRepositoryDirectory(samplesDirectory);
        RepositoryDirectoryInterface checkDelete = tree.findDirectory("/foo/bar/samples");
        assertNull(checkDelete);
        // Finally test disconnecting
        repository.disconnect();
        assertFalse(repository.isConnected());
    } catch (Exception e) {
        e.printStackTrace();
        throw new KettleException("Error during database repository unit testing", e);
    } finally {
        // Remove all the files and folders in the repository...
        // 
        FileUtils.deleteDirectory(dirFile);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleFileRepositoryMeta(org.pentaho.di.repository.filerep.KettleFileRepositoryMeta) File(java.io.File) IMetaStore(org.pentaho.metastore.api.IMetaStore) KettleFileRepository(org.pentaho.di.repository.filerep.KettleFileRepository) KettleException(org.pentaho.di.core.exception.KettleException)

Example 5 with KettleFileRepository

use of org.pentaho.di.repository.filerep.KettleFileRepository in project pentaho-metaverse by pentaho.

the class DIRepositoryLocatorTest method testGetContentsKettleFileRepository.

@Test
public void testGetContentsKettleFileRepository() throws Exception {
    when(spyLocator.getRepository()).thenReturn(new KettleFileRepository());
    spyLocator.getContents(repositoryFile);
}
Also used : KettleFileRepository(org.pentaho.di.repository.filerep.KettleFileRepository) Test(org.junit.Test)

Aggregations

KettleFileRepository (org.pentaho.di.repository.filerep.KettleFileRepository)10 KettleException (org.pentaho.di.core.exception.KettleException)4 KettleFileRepositoryMeta (org.pentaho.di.repository.filerep.KettleFileRepositoryMeta)4 TransMeta (org.pentaho.di.trans.TransMeta)4 FileObject (org.apache.commons.vfs2.FileObject)3 FileSystemException (org.apache.commons.vfs2.FileSystemException)3 File (java.io.File)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Before (org.junit.Before)2 Test (org.junit.Test)2 JobMeta (org.pentaho.di.job.JobMeta)2 StepMeta (org.pentaho.di.trans.step.StepMeta)2 JobEntryJob (org.pentaho.di.job.entries.job.JobEntryJob)1 JobEntryTrans (org.pentaho.di.job.entries.trans.JobEntryTrans)1 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)1 JobEntryInterface (org.pentaho.di.job.entry.JobEntryInterface)1 ObjectId (org.pentaho.di.repository.ObjectId)1 Repository (org.pentaho.di.repository.Repository)1 RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)1