Search in sources :

Example 51 with RepositoryDirectoryInterface

use of org.pentaho.di.repository.RepositoryDirectoryInterface 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 52 with RepositoryDirectoryInterface

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

the class PurRepository method loadRepositoryDirectoryTree.

@Deprecated
@Override
public RepositoryDirectoryInterface loadRepositoryDirectoryTree(boolean eager) throws KettleException {
    // this method forces a reload of the repository directory tree structure
    // a new rootRef will be obtained - this is a SoftReference which will be used
    // by any calls to getRootDir()
    RepositoryDirectoryInterface rootDir;
    if (eager) {
        RepositoryFileTree rootFileTree = loadRepositoryFileTree(ClientRepositoryPaths.getRootFolderPath());
        rootDir = initRepositoryDirectoryTree(rootFileTree);
    } else {
        RepositoryFile root = pur.getFile("/");
        rootDir = new LazyUnifiedRepositoryDirectory(root, null, pur, purRepositoryServiceRegistry);
    }
    rootRef.setRef(rootDir);
    return rootDir;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 53 with RepositoryDirectoryInterface

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

the class PurRepository method findDirectory.

@Override
public RepositoryDirectoryInterface findDirectory(String directory) throws KettleException {
    RepositoryDirectoryInterface repositoryDirectoryInterface = null;
    // check if we have a rootRef cached
    boolean usingRootDirCache = rootRef.getRef() != null;
    repositoryDirectoryInterface = getRootDir().findDirectory(directory);
    // if we are using a cached version of the repository interface, allow a reload if we do not find
    if (repositoryDirectoryInterface == null && usingRootDirCache) {
        repositoryDirectoryInterface = loadRepositoryDirectoryTree().findDirectory(directory);
    }
    return repositoryDirectoryInterface;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface)

Example 54 with RepositoryDirectoryInterface

use of org.pentaho.di.repository.RepositoryDirectoryInterface 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)

Example 55 with RepositoryDirectoryInterface

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

the class StepWithMappingMetaTest method loadMappingMeta.

@Test
public void loadMappingMeta() throws Exception {
    String variablePath = "Internal.Entry.Current.Directory";
    String virtualDir = "/testFolder/CDA-91";
    String fileName = "testTrans.ktr";
    VariableSpace variables = new Variables();
    StepMeta stepMeta = new StepMeta();
    TransMeta parentTransMeta = new TransMeta();
    stepMeta.setParentTransMeta(parentTransMeta);
    RepositoryDirectoryInterface repositoryDirectory = Mockito.mock(RepositoryDirectoryInterface.class);
    when(repositoryDirectory.toString()).thenReturn(virtualDir);
    stepMeta.getParentTransMeta().setRepositoryDirectory(repositoryDirectory);
    StepWithMappingMeta mappingMetaMock = mock(StepWithMappingMeta.class);
    when(mappingMetaMock.getSpecificationMethod()).thenReturn(ObjectLocationSpecificationMethod.FILENAME);
    when(mappingMetaMock.getFileName()).thenReturn("${" + variablePath + "}/" + fileName);
    when(mappingMetaMock.getParentStepMeta()).thenReturn(stepMeta);
    // mock repo and answers
    Repository rep = mock(Repository.class);
    Mockito.doAnswer(new Answer<TransMeta>() {

        @Override
        public TransMeta answer(final InvocationOnMock invocation) throws Throwable {
            final String originalArgument = (String) (invocation.getArguments())[0];
            // be sure that the variable was replaced by real path
            assertEquals(virtualDir, originalArgument);
            return null;
        }
    }).when(rep).findDirectory(anyString());
    Mockito.doAnswer(new Answer<TransMeta>() {

        @Override
        public TransMeta answer(final InvocationOnMock invocation) throws Throwable {
            final String originalArgument = (String) (invocation.getArguments())[0];
            // be sure that transformation name was resolved correctly
            assertEquals(fileName, originalArgument);
            return mock(TransMeta.class);
        }
    }).when(rep).loadTransformation(anyString(), any(RepositoryDirectoryInterface.class), any(ProgressMonitorListener.class), anyBoolean(), anyString());
    StepWithMappingMeta.loadMappingMeta(mappingMetaMock, rep, null, variables, true);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) VariableSpace(org.pentaho.di.core.variables.VariableSpace) Mockito.anyString(org.mockito.Mockito.anyString) StepMeta(org.pentaho.di.trans.step.StepMeta) Variables(org.pentaho.di.core.variables.Variables) Repository(org.pentaho.di.repository.Repository) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ProgressMonitorListener(org.pentaho.di.core.ProgressMonitorListener) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)163 KettleException (org.pentaho.di.core.exception.KettleException)68 Test (org.junit.Test)32 TransMeta (org.pentaho.di.trans.TransMeta)30 ObjectId (org.pentaho.di.repository.ObjectId)27 JobMeta (org.pentaho.di.job.JobMeta)23 Repository (org.pentaho.di.repository.Repository)22 ArrayList (java.util.ArrayList)17 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)17 RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)15 IOException (java.io.IOException)14 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)13 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)11 RepositoryObject (org.pentaho.di.repository.RepositoryObject)11 FileObject (org.apache.commons.vfs2.FileObject)10 List (java.util.List)8 TreeItem (org.eclipse.swt.widgets.TreeItem)8 KettleFileException (org.pentaho.di.core.exception.KettleFileException)8 Date (java.util.Date)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)7