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);
}
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());
}
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());
}
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);
}
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;
}
Aggregations