Search in sources :

Example 21 with RepositoryDirectory

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

the class MetaInjectMeta 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 transformation metadata...
        // 
        TransMeta executorTransMeta = loadTransformationMeta(repository, space);
        // Also go down into the mapping transformation and export the files
        // there. (mapping recursively down)
        // 
        String proposedNewFilename = executorTransMeta.exportResources(executorTransMeta, 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.
        // 
        executorTransMeta.setFilename(newFilename);
        // exports always reside in the root directory, in case we want to turn
        // this into a file repository...
        // 
        executorTransMeta.setRepositoryDirectory(new RepositoryDirectory());
        // change it in the entry
        // 
        fileName = newFilename;
        setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
        return proposedNewFilename;
    } catch (Exception e) {
        throw new KettleException(BaseMessages.getString(PKG, "MetaInjectMeta.Exception.UnableToLoadTrans", fileName));
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) TransMeta(org.pentaho.di.trans.TransMeta) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Example 22 with RepositoryDirectory

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

the class MetaInjectTest method testWriteInjectedKtrToRepoDifferentDir.

@Test
public void testWriteInjectedKtrToRepoDifferentDir() throws Exception {
    RepositoryDirectory rootDir = PowerMockito.spy(new RepositoryDirectory(null, "/"));
    RepositoryDirectory adminDir = PowerMockito.spy(new RepositoryDirectory(new RepositoryDirectory(new RepositoryDirectory(null, "/"), "home"), "admin"));
    TransMeta cloneMeta = PowerMockito.spy((TransMeta) data.transMeta.clone());
    PowerMockito.doReturn(cloneMeta).when(data.transMeta).clone();
    PowerMockito.doReturn(adminDir).when(repository).createRepositoryDirectory(rootDir, "/home/admin");
    PowerMockito.doReturn(adminDir).when(data.transMeta).getRepositoryDirectory();
    PowerMockito.whenNew(RepositoryDirectory.class).withArguments(null, "/").thenReturn(rootDir);
    metaInject.setRepository(repository);
    Whitebox.<String>invokeMethod(metaInject, "writeInjectedKtrToRepo", "injected_trans");
    verify(repository, times(0)).findDirectory(anyString());
    verify(repository, times(0)).createRepositoryDirectory(any(), any());
    verify(cloneMeta, times(1)).setRepositoryDirectory(adminDir);
    verify(cloneMeta, times(1)).setObjectId(any(ObjectId.class));
    verify(repository, times(1)).save(cloneMeta, null, null, true);
}
Also used : RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) ObjectId(org.pentaho.di.repository.ObjectId) TransMeta(org.pentaho.di.trans.TransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Mockito.anyString(org.mockito.Mockito.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 23 with RepositoryDirectory

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

the class PurRepository method getChildren.

@Override
public List<RepositoryObjectInterface> getChildren(String path, String filter) {
    RepositoryRequest repoRequest = new RepositoryRequest();
    repoRequest.setDepth(-1);
    repoRequest.setChildNodeFilter("*" + filter + "*");
    repoRequest.setIncludeAcls(false);
    repoRequest.setTypes(FILES_TYPE_FILTER.FILES_FOLDERS);
    repoRequest.setPath(path);
    repoRequest.setShowHidden(false);
    List<RepositoryFile> repositoryFiles = pur.getChildren(repoRequest);
    List<RepositoryObjectInterface> repositoryElementInterfaces = new ArrayList<>();
    for (RepositoryFile repositoryFile : repositoryFiles) {
        if (repositoryFile.isFolder()) {
            RepositoryDirectoryInterface repositoryDirectory = new RepositoryDirectory();
            repositoryDirectory.setName(repositoryFile.getName());
            repositoryDirectory.setObjectId(() -> repositoryFile.getId().toString());
            repositoryElementInterfaces.add(repositoryDirectory);
        } else {
            RepositoryObject repositoryObject = new RepositoryObject();
            repositoryObject.setName(repositoryFile.getName());
            repositoryObject.setObjectId(() -> repositoryFile.getId().toString());
            RepositoryObjectType repositoryObjectType = RepositoryObjectType.UNKNOWN;
            if (repositoryFile.getName().endsWith(".ktr")) {
                repositoryObjectType = RepositoryObjectType.TRANSFORMATION;
            }
            if (repositoryFile.getName().endsWith(".kjb")) {
                repositoryObjectType = RepositoryObjectType.JOB;
            }
            repositoryObject.setObjectType(repositoryObjectType);
            repositoryElementInterfaces.add(repositoryObject);
        }
    }
    return repositoryElementInterfaces;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) RepositoryObject(org.pentaho.di.repository.RepositoryObject) EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) ArrayList(java.util.ArrayList) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryObjectInterface(org.pentaho.di.repository.RepositoryObjectInterface)

Example 24 with RepositoryDirectory

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

the class PurRepository method fillRepositoryDirectoryFromTree.

private void fillRepositoryDirectoryFromTree(final RepositoryDirectoryInterface parentDir, final RepositoryFileTree treeNode) throws KettleException {
    try {
        List<RepositoryElementMetaInterface> fileChildren = new ArrayList<RepositoryElementMetaInterface>();
        List<RepositoryFileTree> children = treeNode.getChildren();
        if (children != null) {
            for (RepositoryFileTree child : children) {
                if (child.getFile().isFolder()) {
                    RepositoryDirectory dir = new RepositoryDirectory(parentDir, child.getFile().getName());
                    dir.setObjectId(new StringObjectId(child.getFile().getId().toString()));
                    parentDir.addSubdirectory(dir);
                    fillRepositoryDirectoryFromTree(dir, child);
                } else {
                    // a real file, like a Transformation or Job
                    RepositoryLock lock = unifiedRepositoryLockService.getLock(child.getFile());
                    RepositoryObjectType objectType = getObjectType(child.getFile().getName());
                    fileChildren.add(new EERepositoryObject(child, parentDir, null, objectType, null, lock, false));
                }
            }
            parentDir.setRepositoryObjects(fileChildren);
        }
    } catch (Exception e) {
        throw new KettleException("Unable to load directory structure from repository", e);
    }
}
Also used : EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) ArrayList(java.util.ArrayList) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) RepositoryLock(org.pentaho.di.repository.pur.model.RepositoryLock) StringObjectId(org.pentaho.di.repository.StringObjectId) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) UnifiedRepositoryCreateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException) UnifiedRepositoryUpdateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) KettleException(org.pentaho.di.core.exception.KettleException) IdNotFoundException(org.pentaho.di.core.exception.IdNotFoundException) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 25 with RepositoryDirectory

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

the class KettleFileRepositoryTest method testCurrentDirJob.

@Test
public void testCurrentDirJob() throws Exception {
    final String dirName = "dirName";
    final String jobName = "job";
    JobMeta setupJobMeta = new JobMeta();
    setupJobMeta.setName(jobName);
    RepositoryDirectoryInterface repoDir = repository.createRepositoryDirectory(new RepositoryDirectory(), dirName);
    setupJobMeta.setRepositoryDirectory(repoDir);
    repository.save(setupJobMeta, "");
    JobMeta jobMeta = repository.loadJob(jobName, repoDir, null, "");
    assertEquals(repository, jobMeta.getRepository());
    assertEquals(repoDir.getPath(), jobMeta.getRepositoryDirectory().getPath());
    jobMeta.setInternalKettleVariables();
    String currentDir = jobMeta.getVariable(Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY);
    assertEquals(repoDir.getPath(), currentDir);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) JobMeta(org.pentaho.di.job.JobMeta) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) Test(org.junit.Test)

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