Search in sources :

Example 6 with RepositoryRequest

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;
}
Also used : RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest)

Example 7 with 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));
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) ArrayList(java.util.ArrayList) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) Collator(java.text.Collator) Test(org.junit.Test)

Example 8 with RepositoryRequest

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);
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 9 with RepositoryRequest

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());
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 10 with RepositoryRequest

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

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