use of org.pentaho.platform.api.repository2.unified.RepositoryRequest in project pentaho-platform by pentaho.
the class FileService method getRepositoryRequest.
protected RepositoryRequest getRepositoryRequest(RepositoryFileDto repositoryFileDto, Boolean showHidden, String filter, Boolean includeAcls) {
RepositoryRequest repositoryRequest = new RepositoryRequest(repositoryFileDto.getId(), showHidden, 0, filter);
repositoryRequest.setIncludeAcls(includeAcls);
return repositoryRequest;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryRequest in project pentaho-platform by pentaho.
the class FileServiceTest method testDoGetChildren.
@Test
public void testDoGetChildren() {
RepositoryFileDto mockRepositoryFileDto = mock(RepositoryFileDto.class);
Collator mockCollator = mock(Collator.class);
List<RepositoryFileDto> mockRepositoryFileDtos = new ArrayList<RepositoryFileDto>();
mockRepositoryFileDtos.add(mockRepositoryFileDto);
RepositoryRequest mockRepositoryRequest = mock(RepositoryRequest.class);
doReturn(true).when(fileService).isPathValid(anyString());
doReturn(mockRepositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
doReturn(mockCollator).when(fileService).getCollator(anyInt());
doReturn(mockRepositoryRequest).when(fileService).getRepositoryRequest((RepositoryFileDto) anyObject(), anyBoolean(), anyString(), anyBoolean());
doReturn(mockRepositoryFileDtos).when(fileService.defaultUnifiedRepositoryWebService).getChildrenFromRequest(mockRepositoryRequest);
doReturn(true).when(fileService).isShowingTitle(mockRepositoryRequest);
List<RepositoryFileDto> repositoryFileDtos = fileService.doGetChildren("mock:path:fileName", null, true, true);
verify(fileService, times(1)).isPathValid(anyString());
verify(fileService.defaultUnifiedRepositoryWebService, times(1)).getFile(anyString());
verify(fileService, times(1)).getCollator(anyInt());
verify(fileService, times(1)).getRepositoryRequest((RepositoryFileDto) anyObject(), anyBoolean(), anyString(), anyBoolean());
verify(fileService.defaultUnifiedRepositoryWebService, times(1)).getChildrenFromRequest(mockRepositoryRequest);
verify(fileService, times(1)).isShowingTitle(mockRepositoryRequest);
assertEquals(mockRepositoryFileDtos, repositoryFileDtos);
assertEquals(1, repositoryFileDtos.size());
assertEquals(mockRepositoryFileDto, repositoryFileDtos.get(0));
}
use of org.pentaho.platform.api.repository2.unified.RepositoryRequest 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.RepositoryRequest in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testGetRoot.
@Test
public void testGetRoot() 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 });
RepositoryFile rootFolder = repo.getFile("/");
assertNotNull(rootFolder);
assertEquals("", rootFolder.getName());
assertNotNull(rootFolder.getId());
assertNotNull(repo.getChildren(new RepositoryRequest(String.valueOf(rootFolder.getId()), true, -1, null)));
RepositoryFileAcl rootFolderAcl = repo.getAcl(rootFolder.getId());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryRequest 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());
}
Aggregations