Search in sources :

Example 31 with RepositoryFileDto

use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileService method doGetFileAcl.

/**
 * Retrieves the acls of the selected repository file
 *
 * @param pathId (colon separated path for the repository file)
 * @return <code> RepositoryFileAclDto </code>
 */
public RepositoryFileAclDto doGetFileAcl(String pathId) {
    RepositoryFileDto file = getRepoWs().getFile(FileUtils.idToPath(pathId));
    RepositoryFileAclDto fileAcl = getRepoWs().getAcl(file.getId());
    if (fileAcl.isEntriesInheriting()) {
        List<RepositoryFileAclAceDto> aces = getRepoWs().getEffectiveAcesWithForceFlag(file.getId(), fileAcl.isEntriesInheriting());
        fileAcl.setAces(aces, fileAcl.isEntriesInheriting());
    }
    addAdminRole(fileAcl);
    return fileAcl;
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) RepositoryFileAclAceDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)

Example 32 with RepositoryFileDto

use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileService method doCreateDirFor.

private boolean doCreateDirFor(String pathWithSlashes) {
    // $NON-NLS-1$//$NON-NLS-2$
    String[] folders = pathWithSlashes.split("[" + FileUtils.PATH_SEPARATOR + "]");
    RepositoryFileDto parentDir = getRepoWs().getFile(FileUtils.PATH_SEPARATOR);
    boolean dirCreated = false;
    for (String folder : folders) {
        String currentFolderPath = (parentDir.getPath() + FileUtils.PATH_SEPARATOR + folder).substring(1);
        if (!currentFolderPath.startsWith(FileUtils.PATH_SEPARATOR)) {
            currentFolderPath = FileUtils.PATH_SEPARATOR + currentFolderPath;
        }
        RepositoryFileDto currentFolder = getRepoWs().getFile(currentFolderPath);
        if (currentFolder == null) {
            currentFolder = new RepositoryFileDto();
            currentFolder.setFolder(true);
            currentFolder.setName(decode(folder));
            currentFolder.setPath(parentDir.getPath() + FileUtils.PATH_SEPARATOR + folder);
            currentFolder = getRepoWs().createFolder(parentDir.getId(), currentFolder, currentFolderPath);
            dirCreated = true;
        }
        parentDir = currentFolder;
    }
    return dirCreated;
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)

Example 33 with RepositoryFileDto

use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileServiceTest method testSetFileAcls.

@Test
public void testSetFileAcls() throws Exception {
    RepositoryFileDto file = mock(RepositoryFileDto.class);
    doReturn("file.txt").when(file).getName();
    when(fileService.defaultUnifiedRepositoryWebService.getFile(anyString())).thenReturn(file);
    String pathId = "/usr/folder/file.txt";
    RepositoryFileAclDto acl = mock(RepositoryFileAclDto.class);
    fileService.setFileAcls(pathId, acl);
    verify(acl, times(1)).setId(anyString());
    verify(file, times(1)).getId();
    verify(fileService.defaultUnifiedRepositoryWebService, times(1)).updateAcl(acl);
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 34 with RepositoryFileDto

use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileServiceTest method getMockedRepositoryFileDtoList.

public List<RepositoryFileDto> getMockedRepositoryFileDtoList(String[] fileNames) {
    List<RepositoryFileDto> repoFileDtoList = new ArrayList<>();
    for (String fileName : fileNames) {
        RepositoryFileDto repoFileDto = mock(RepositoryFileDto.class);
        when(repoFileDto.getName()).thenReturn(fileName);
        when(repoFileDto.getId()).thenReturn(fileName);
        repoFileDtoList.add(repoFileDto);
    }
    return repoFileDtoList;
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString)

Example 35 with RepositoryFileDto

use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileServiceTest method testSearchGeneratedContent.

@Test
public void testSearchGeneratedContent() {
    String lineageId = "test.prpt", pathId = "test.prpt", userFolder = "public/admin";
    RepositoryFileDto fileDetailsMock = mock(RepositoryFileDto.class);
    RepositoryFile workspaceFolder = mock(RepositoryFile.class);
    doReturn(userFolder).when(workspaceFolder).getId();
    SessionResource sessionResource = mock(SessionResource.class);
    List<RepositoryFile> children = new ArrayList<RepositoryFile>();
    RepositoryFile mockedChild = mock(RepositoryFile.class);
    doReturn(false).when(mockedChild).isFolder();
    children.add(mockedChild);
    Map<String, Serializable> mockedFileMetadata = mock(Map.class);
    doReturn(lineageId).when(mockedFileMetadata).get(QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID);
    when(fileService.repository.getFileMetadata(mockedChild.getId())).thenReturn(mockedFileMetadata);
    doReturn(pathId).when(fileDetailsMock).getId();
    doReturn(userFolder).when(sessionResource).doGetCurrentUserDir();
    doReturn(workspaceFolder).when(fileService.repository).getFile(userFolder);
    doReturn(sessionResource).when(fileService).getSessionResource();
    doReturn(children).when(fileService.repository).getChildren(userFolder);
    RepositoryFileDto mockedRepositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(mockedRepositoryFileDto).when(fileService).toFileDto(mockedChild, null, false);
    try {
        doReturn(fileDetailsMock).when(fileService).doGetProperties(pathId);
        List<RepositoryFileDto> list = fileService.searchGeneratedContent(userFolder, lineageId, QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID);
        assertEquals(list.size(), 1);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail();
    } catch (Throwable t) {
        fail();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) Serializable(java.io.Serializable) SessionResource(org.pentaho.platform.web.http.api.resources.SessionResource) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)66 Test (org.junit.Test)42 Matchers.anyString (org.mockito.Matchers.anyString)26 FileNotFoundException (java.io.FileNotFoundException)23 ArrayList (java.util.ArrayList)20 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)18 Serializable (java.io.Serializable)15 GeneralSecurityException (java.security.GeneralSecurityException)11 StringKeyStringValueDto (org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto)9 IllegalSelectorException (java.nio.channels.IllegalSelectorException)8 InvalidParameterException (java.security.InvalidParameterException)8 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)8 UnifiedRepositoryAccessDeniedException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)8 IOException (java.io.IOException)7 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)6 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)6 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)6 Properties (java.util.Properties)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 RepositoryFileAclAceDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAceDto)4