Search in sources :

Example 26 with RepositoryDirectory

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

the class TransMetaConverterTest method testIncludesSubTransformationsFromRepository.

@Test
public void testIncludesSubTransformationsFromRepository() throws Exception {
    TransMeta parentTransMeta = new TransMeta(getClass().getResource("trans-meta-converter-parent.ktr").getPath());
    Repository repository = mock(Repository.class);
    TransMeta transMeta = new TransMeta();
    RepositoryDirectoryInterface repositoryDirectory = new RepositoryDirectory(null, "public");
    String directory = getClass().getResource("").toString().replace(File.separator, "/");
    when(repository.findDirectory("public")).thenReturn(repositoryDirectory);
    when(repository.loadTransformation("trans-meta-converter-sub.ktr", repositoryDirectory, null, true, null)).thenReturn(transMeta);
    parentTransMeta.setRepository(repository);
    parentTransMeta.setRepositoryDirectory(repositoryDirectory);
    parentTransMeta.setVariable("Internal.Entry.Current.Directory", "public");
    Transformation transformation = TransMetaConverter.convert(parentTransMeta);
    @SuppressWarnings({ "unchecked", "ConstantConditions" }) HashMap<String, Transformation> config = (HashMap<String, Transformation>) transformation.getConfig(TransMetaConverter.SUB_TRANSFORMATIONS_KEY).get();
    assertEquals(1, config.size());
    assertNotNull(config.get("public/trans-meta-converter-sub.ktr"));
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) Repository(org.pentaho.di.repository.Repository) Transformation(org.pentaho.di.engine.api.model.Transformation) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) HashMap(java.util.HashMap) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Test(org.junit.Test)

Example 27 with RepositoryDirectory

use of org.pentaho.di.repository.RepositoryDirectory in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceReferenceSynchronizerTest method before.

@Before
public void before() {
    ObjectId transId = new StringObjectId("transId");
    when(transMeta.getMetaStore()).thenReturn(externalMetastore);
    when(transMeta.getEmbeddedMetaStore()).thenReturn(embeddedMetastore);
    when(transMeta.getObjectId()).thenReturn(transId);
    when(transMeta.getRepository()).thenReturn(repository);
    when(repository.getRepositoryMeta()).thenReturn(repositoryMeta);
    when(repositoryMeta.getRepositoryCapabilities()).thenReturn(mock(RepositoryCapabilities.class));
    RepositoryDirectoryInterface root = mock(RepositoryDirectoryInterface.class);
    RepositoryDirectoryInterface dir = new RepositoryDirectory(root, "location");
    when(root.findDirectory(eq("/"))).thenReturn(dir);
    try {
        when(repository.getTransformationID(eq("location"), eq(dir))).thenReturn(transId);
        when(repository.loadRepositoryDirectoryTree()).thenReturn(root);
    } catch (KettleException ke) {
    // Noop
    }
    when(context.getPushDownFactories()).thenReturn(Collections.emptyList());
    synchronizer = new DataServiceReferenceSynchronizer(context) {

        protected <T> MetaStoreFactory<T> getMetastoreFactory(IMetaStore metaStore, Class<T> clazz) {
            return externalMetaStoreFactory;
        }

        protected MetaStoreFactory<DataServiceMeta> getEmbeddedMetaStoreFactory(TransMeta meta) {
            return embeddedMetaStoreFactory;
        }
    };
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) MetaStoreFactory(org.pentaho.metastore.persist.MetaStoreFactory) TransMeta(org.pentaho.di.trans.TransMeta) StringObjectId(org.pentaho.di.repository.StringObjectId) IMetaStore(org.pentaho.metastore.api.IMetaStore) RepositoryCapabilities(org.pentaho.di.repository.RepositoryCapabilities) Before(org.junit.Before)

Example 28 with RepositoryDirectory

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

the class JobExecutorMeta method exportResources.

@Override
public String exportResources(VariableSpace space, Map<String, ResourceDefinition> definitions, ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore) throws KettleException {
    try {
        // Try to load the transformation from repository or file.
        // Modify this recursively too...
        // 
        // NOTE: there is no need to clone this step because the caller is
        // responsible for this.
        // 
        // First load the executor job metadata...
        // 
        JobMeta executorJobMeta = loadJobMetaProxy(this, repository, space);
        // Also go down into the mapping transformation and export the files
        // there. (mapping recursively down)
        // 
        String proposedNewFilename = executorJobMeta.exportResources(executorJobMeta, definitions, resourceNamingInterface, repository, metaStore);
        // To get a relative path to it, we inject
        // ${Internal.Entry.Current.Directory}
        // 
        String newFilename = "${" + Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY + "}/" + proposedNewFilename;
        // Set the correct filename inside the XML.
        // 
        executorJobMeta.setFilename(newFilename);
        // exports always reside in the root directory, in case we want to turn
        // this into a file repository...
        // 
        executorJobMeta.setRepositoryDirectory(new RepositoryDirectory());
        // change it in the job entry
        // 
        fileName = newFilename;
        setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
        return proposedNewFilename;
    } catch (Exception e) {
        throw new KettleException(BaseMessages.getString(PKG, "JobExecutorMeta.Exception.UnableToLoadJob", fileName));
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleException(org.pentaho.di.core.exception.KettleException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException)

Example 29 with RepositoryDirectory

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

the class KettleFileRepository method createRepositoryDirectory.

@Override
public RepositoryDirectoryInterface createRepositoryDirectory(RepositoryDirectoryInterface parentDirectory, String directoryPath) throws KettleException {
    String folder = calcDirectoryName(parentDirectory);
    String newFolder = folder;
    if (folder.endsWith("/")) {
        newFolder += directoryPath;
    } else {
        newFolder += "/" + directoryPath;
    }
    FileObject parent = KettleVFS.getFileObject(newFolder);
    try {
        parent.createFolder();
    } catch (FileSystemException e) {
        throw new KettleException("Unable to create folder " + newFolder, e);
    }
    // Incremental change of the directory structure...
    // 
    RepositoryDirectory newDir = new RepositoryDirectory(parentDirectory, directoryPath);
    parentDirectory.addSubdirectory(newDir);
    newDir.setObjectId(new StringObjectId(calcObjectId(newDir)));
    return newDir;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) FileSystemException(org.apache.commons.vfs2.FileSystemException) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) FileObject(org.apache.commons.vfs2.FileObject) StringObjectId(org.pentaho.di.repository.StringObjectId)

Example 30 with RepositoryDirectory

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

the class KettleFileRepository method loadRepositoryDirectoryTree.

public RepositoryDirectoryInterface loadRepositoryDirectoryTree(RepositoryDirectoryInterface dir) throws KettleException {
    try {
        String folderName = calcDirectoryName(dir);
        FileObject folder = KettleVFS.getFileObject(folderName);
        for (FileObject child : folder.getChildren()) {
            if (child.getType().equals(FileType.FOLDER)) {
                if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) {
                    if (!".meta".equals(child.getName().getBaseName())) {
                        RepositoryDirectory subDir = new RepositoryDirectory(dir, child.getName().getBaseName());
                        subDir.setObjectId(new StringObjectId(calcObjectId(subDir)));
                        dir.addSubdirectory(subDir);
                        loadRepositoryDirectoryTree(subDir);
                    }
                }
            }
        }
        return dir;
    } catch (Exception e) {
        throw new KettleException("Unable to load the directory tree from this file repository", e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) FileObject(org.apache.commons.vfs2.FileObject) StringObjectId(org.pentaho.di.repository.StringObjectId) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException)

Aggregations

RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)57 KettleException (org.pentaho.di.core.exception.KettleException)23 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)15 Test (org.junit.Test)14 TransMeta (org.pentaho.di.trans.TransMeta)11 LongObjectId (org.pentaho.di.repository.LongObjectId)10 ObjectId (org.pentaho.di.repository.ObjectId)9 KettleFileException (org.pentaho.di.core.exception.KettleFileException)8 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)8 Repository (org.pentaho.di.repository.Repository)8 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)8 ArrayList (java.util.ArrayList)7 StringObjectId (org.pentaho.di.repository.StringObjectId)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)6 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)6 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)6 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)6 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)5 JobMeta (org.pentaho.di.job.JobMeta)5 TreeItem (org.eclipse.swt.widgets.TreeItem)4