Search in sources :

Example 16 with RepositoryFileTree

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

the class DefaultUnifiedRepositoryWebService method getTreeFromRequest.

public RepositoryFileTreeDto getTreeFromRequest(final RepositoryRequest repositoryRequest) {
    // RepositoryFileTree tree = repo.getTree( path, depth, filter, showHidden );
    IAuthorizationPolicy policy = PentahoSystem.get(IAuthorizationPolicy.class);
    boolean isAdmin = policy.isAllowed(AdministerSecurityAction.NAME);
    // PDI uses this web-service and system folders must be returned to admin repository database connections.
    if (!isAdmin) {
        // Non Admin users can never get system folders
        repositoryRequest.setIncludeSystemFolders(false);
        getLogger().warn("User does not have administrator privileges; setting includeSystemFolders to false.");
    }
    RepositoryFileTree tree = repo.getTree(repositoryRequest);
    return new RepositoryFileTreeAdapter(repositoryRequest).marshal(tree);
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 17 with RepositoryFileTree

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

the class DefaultUnifiedRepositoryContentIT method testGetTreeWithFileTypeFilter.

@Test
public void testGetTreeWithFileTypeFilter() throws Exception {
    RepositoryFileTree root = null;
    loginAsSysTenantAdmin();
    ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
    login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    RepositoryFile publicFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()));
    final String dataString = "Hello World!";
    final String encoding = "UTF-8";
    byte[] data = dataString.getBytes(encoding);
    ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
    final String mimeType = "text/plain";
    final SimpleRepositoryFileData content = new SimpleRepositoryFileData(dataStream, encoding, mimeType);
    RepositoryFile newFile1 = repo.createFile(publicFolder.getId(), new RepositoryFile.Builder("helloworld.xaction").versioned(true).hidden(false).build(), content, null);
    RepositoryFile newFile2 = repo.createFolder(publicFolder.getId(), new RepositoryFile.Builder("testFolder").versioned(false).hidden(false).folder(true).build(), null, null);
    root = repo.getTree(new RepositoryRequest(publicFolder.getPath(), true, 1, "*|FILES"));
    assertFalse(root.getChildren().isEmpty());
    assertEquals(1, root.getChildren().size());
    assertEquals("helloworld.xaction", root.getChildren().get(0).getFile().getName());
    root = repo.getTree(new RepositoryRequest(publicFolder.getPath(), true, 1, "*"));
    assertFalse(root.getChildren().isEmpty());
    assertEquals(2, root.getChildren().size());
    root = repo.getTree(new RepositoryRequest(publicFolder.getPath(), true, 1, "*|FILES_FOLDERS"));
    assertFalse(root.getChildren().isEmpty());
    assertEquals(2, root.getChildren().size());
    root = repo.getTree(new RepositoryRequest(publicFolder.getPath(), true, 1, "*|FOLDERS"));
    assertFalse(root.getChildren().isEmpty());
    assertEquals(1, root.getChildren().size());
    assertEquals("testFolder", root.getChildren().get(0).getFile().getName());
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) Test(org.junit.Test)

Example 18 with RepositoryFileTree

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

the class DefaultUnifiedRepositoryContentIT method testGetTree.

@Test
public void testGetTree() throws Exception {
    loginAsSysTenantAdmin();
    ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
    login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    RepositoryFileTree root = repo.getTree(new RepositoryRequest(ClientRepositoryPaths.getRootFolderPath(), true, 0, null));
    assertNotNull(root.getFile());
    assertNull(root.getChildren());
    root = repo.getTree(new RepositoryRequest(ClientRepositoryPaths.getRootFolderPath(), true, 1, null));
    assertNotNull(root.getFile());
    assertNotNull(root.getChildren());
    assertFalse(root.getChildren().isEmpty());
    assertNull(root.getChildren().get(0).getChildren());
    root = repo.getTree(new RepositoryRequest(ClientRepositoryPaths.getHomeFolderPath(), true, -1, null));
    assertNotNull(root.getFile());
    assertNotNull(root.getChildren());
    assertFalse(root.getChildren().isEmpty());
    assertTrue(root.getChildren().get(0).getChildren().isEmpty());
    root = repo.getTree(new RepositoryRequest(ClientRepositoryPaths.getHomeFolderPath(), true, -1, "*uz*"));
    assertEquals(1, root.getChildren().size());
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) Test(org.junit.Test)

Example 19 with RepositoryFileTree

use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree 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 20 with RepositoryFileTree

use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree 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)

Aggregations

RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)35 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)25 Test (org.junit.Test)14 RepositoryRequest (org.pentaho.platform.api.repository2.unified.RepositoryRequest)13 ArrayList (java.util.ArrayList)10 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)7 Matchers.anyString (org.mockito.Matchers.anyString)6 StringObjectId (org.pentaho.di.repository.StringObjectId)6 RepositoryObjectType (org.pentaho.di.repository.RepositoryObjectType)5 KettleException (org.pentaho.di.core.exception.KettleException)4 ObjectId (org.pentaho.di.repository.ObjectId)4 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)4 ITenant (org.pentaho.platform.api.mt.ITenant)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 File (java.io.File)3 Serializable (java.io.Serializable)3 Date (java.util.Date)3 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)3 RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)3 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)3