Search in sources :

Example 31 with RepositoryRequest

use of org.pentaho.platform.api.repository2.unified.RepositoryRequest in project pentaho-platform by pentaho.

the class UnifiedRepositoryTestUtils method stubGetChildren.

/**
 * Stubs a {@code getChildren} call. {@code childrenNames} is zero or more file/folder names. A folder is
 * indicated by a trailing forward slash.
 *
 * <p>
 * Example:
 * </p>
 *
 * <pre>
 * stubGetChildren( repo, &quot;/public&quot;, &quot;hello/&quot;, &quot;file1.txt&quot; );
 * </pre>
 */
public static void stubGetChildren(final IUnifiedRepository repo, RepositoryRequest request, final String... childrenNames) {
    List<RepositoryFile> children = new ArrayList<RepositoryFile>(childrenNames.length);
    for (String childName : childrenNames) {
        if (childName.startsWith(RepositoryFile.SEPARATOR)) {
            throw new IllegalArgumentException("child names must not begin with a forward slash");
        }
        final String fullChildPath = request.getPath() + RepositoryFile.SEPARATOR + (childName.endsWith(RepositoryFile.SEPARATOR) ? StringUtils.substringBefore(childName, RepositoryFile.SEPARATOR) : childName);
        RepositoryFile child = null;
        if (childName.endsWith(RepositoryFile.SEPARATOR)) {
            child = makeFolderObject(fullChildPath, true);
        } else {
            child = makeFileObject(fullChildPath, true);
        }
        children.add(child);
    }
    doReturn(children).when(repo).getChildren(request);
}
Also used : ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 32 with RepositoryRequest

use of org.pentaho.platform.api.repository2.unified.RepositoryRequest in project pentaho-metaverse by pentaho.

the class RepositoryLocator method startScan.

@Override
public void startScan() throws MetaverseLocatorException {
    if (unifiedRepository == null) {
        try {
            unifiedRepository = getUnifiedRepository(session);
        } catch (Exception e) {
            throw new MetaverseLocatorException(Messages.getString("ERROR.RepositoryLocator.ScanAbortedNoRepo"), e);
        }
    }
    RepositoryRequest request = new RepositoryRequest(ClientRepositoryPaths.getRootFolderPath(), true, -1, null);
    RepositoryFileTree root = unifiedRepository.getTree(request);
    List<RepositoryFileTree> children = root.getChildren();
    LocatorRunner lr = new RepositoryLocatorRunner();
    lr.setRoot(children);
    startScan(lr);
}
Also used : MetaverseLocatorException(org.pentaho.metaverse.api.MetaverseLocatorException) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) MetaverseLocatorException(org.pentaho.metaverse.api.MetaverseLocatorException) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 33 with RepositoryRequest

use of org.pentaho.platform.api.repository2.unified.RepositoryRequest in project pentaho-metaverse by pentaho.

the class LocatorTestUtils method getMockIUnifiedRepository.

public static IUnifiedRepository getMockIUnifiedRepository() {
    IUnifiedRepository repo = mock(IUnifiedRepository.class);
    when(repo.getTree(any(RepositoryRequest.class))).thenAnswer(new Answer<RepositoryFileTree>() {

        @Override
        public RepositoryFileTree answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            return getTree((RepositoryRequest) args[0]);
        }
    });
    return repo;
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 34 with RepositoryRequest

use of org.pentaho.platform.api.repository2.unified.RepositoryRequest in project pentaho-kettle by pentaho.

the class RepositoryBrowserController method populateFoldersLazy.

public void populateFoldersLazy(RepositoryDirectory repositoryDirectory) {
    RepositoryRequest repositoryRequest = new RepositoryRequest(repositoryDirectory.getPath(), true, 1, null);
    repositoryRequest.setTypes(RepositoryRequest.FILES_TYPE_FILTER.FOLDERS);
    repositoryRequest.setIncludeSystemFolders(false);
    RepositoryFileTree tree = getRepository().getUnderlyingRepository().getTree(repositoryRequest);
    for (RepositoryFileTree repositoryFileTree : tree.getChildren()) {
        org.pentaho.platform.api.repository2.unified.RepositoryFile repositoryFile = repositoryFileTree.getFile();
        RepositoryDirectory repositoryDirectory1 = RepositoryDirectory.build(repositoryDirectory.getPath(), repositoryFile, isAdmin());
        repositoryDirectory.addChild(repositoryDirectory1);
    }
}
Also used : RepositoryDirectory(org.pentaho.repo.model.RepositoryDirectory) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 35 with RepositoryRequest

use of org.pentaho.platform.api.repository2.unified.RepositoryRequest in project pentaho-kettle by pentaho.

the class RepositoryFileProvider method populateFoldersLazy.

public void populateFoldersLazy(RepositoryDirectory repositoryDirectory) {
    RepositoryRequest repositoryRequest = new RepositoryRequest(repositoryDirectory.getPath(), true, 1, null);
    repositoryRequest.setTypes(RepositoryRequest.FILES_TYPE_FILTER.FOLDERS);
    repositoryRequest.setIncludeSystemFolders(false);
    RepositoryFileTree tree = getRepository().getUnderlyingRepository().getTree(repositoryRequest);
    for (RepositoryFileTree repositoryFileTree : tree.getChildren()) {
        org.pentaho.platform.api.repository2.unified.RepositoryFile repositoryFile = repositoryFileTree.getFile();
        RepositoryDirectory repositoryDirectory1 = RepositoryDirectory.build(repositoryDirectory.getPath(), repositoryFile, isAdmin());
        repositoryDirectory.addChild(repositoryDirectory1);
    }
}
Also used : RepositoryDirectory(org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryDirectory) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Aggregations

RepositoryRequest (org.pentaho.platform.api.repository2.unified.RepositoryRequest)31 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)19 RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)19 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 Matchers.anyString (org.mockito.Matchers.anyString)8 ITenant (org.pentaho.platform.api.mt.ITenant)7 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Collator (java.text.Collator)4 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)4 File (java.io.File)3 Serializable (java.io.Serializable)3 ObjectId (org.pentaho.di.repository.ObjectId)3 EERepositoryObject (org.pentaho.di.repository.pur.model.EERepositoryObject)3 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)3 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)3 HashMap (java.util.HashMap)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)2