Search in sources :

Example 96 with RepositoryFileDto

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

the class RepositoryFileTreeAdapter method marshal.

@Override
public RepositoryFileTreeDto marshal(final RepositoryFileTree v) {
    RepositoryFileTreeDto treeDto = new RepositoryFileTreeDto();
    RepositoryFileDto file = RepositoryFileAdapter.toFileDto(v, membersSet, exclude, includeAcls);
    if (file != null) {
        treeDto.setFile(RepositoryFileAdapter.toFileDto(v, membersSet, exclude, includeAcls));
        List<RepositoryFileTreeDto> children = null;
        if (v.getChildren() != null) {
            children = new ArrayList<RepositoryFileTreeDto>();
            for (RepositoryFileTree child : v.getChildren()) {
                RepositoryFileTreeDto childTreeDto = marshal(child);
                if (childTreeDto != null) {
                    children.add(childTreeDto);
                }
            }
        }
        treeDto.setChildren(children);
        return treeDto;
    } else {
        return null;
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) RepositoryFileTreeDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileTreeDto) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 97 with RepositoryFileDto

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

the class UnifiedRepositoryToWebServiceAdapter method getDataForReadInBatch.

@Override
@SuppressWarnings("unchecked")
public <T extends IRepositoryFileData> java.util.List<T> getDataForReadInBatch(final List<RepositoryFile> files, final Class<T> dataClass) {
    List<RepositoryFileDto> fileDtos = new ArrayList<RepositoryFileDto>(files.size());
    for (RepositoryFile file : files) {
        fileDtos.add(repositoryFileAdapter.marshal(file));
    }
    if (dataClass.equals(NodeRepositoryFileData.class)) {
        List<NodeRepositoryFileDataDto> nodeData = repoWebService.getDataAsNodeForReadInBatch(fileDtos);
        List<T> data = new ArrayList<T>(nodeData.size());
        for (NodeRepositoryFileDataDto node : nodeData) {
            data.add((T) nodeRepositoryFileDataAdapter.unmarshal(node));
        }
        return data;
    } else if (dataClass.equals(SimpleRepositoryFileData.class)) {
        List<SimpleRepositoryFileDataDto> nodeData = repoWebService.getDataAsBinaryForReadInBatch(fileDtos);
        List<T> data = new ArrayList<T>(nodeData.size());
        for (SimpleRepositoryFileDataDto node : nodeData) {
            data.add((T) SimpleRepositoryFileDataDto.convert(node));
        }
        return data;
    } else {
        throw new IllegalArgumentException();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) NodeRepositoryFileDataDto(org.pentaho.platform.api.repository2.unified.webservices.NodeRepositoryFileDataDto) ArrayList(java.util.ArrayList) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ArrayList(java.util.ArrayList) List(java.util.List)

Example 98 with RepositoryFileDto

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

the class RepositoryFileUtils method convertFromRepositoryFileTree.

public static RepositoryFileTreeDto convertFromRepositoryFileTree(RepositoryFileTree tree) {
    RepositoryFileTreeDto fileTreeDto = new RepositoryFileTreeDto();
    List<RepositoryFileTreeDto> fileList = new ArrayList<RepositoryFileTreeDto>();
    RepositoryFileDto file = convertFromRepositoryFile(tree.getFile());
    fileTreeDto.setFile(file);
    for (RepositoryFileTree treeItem : tree.getChildren()) {
        fileList.add(convertFromRepositoryFileTree(treeItem));
    }
    fileTreeDto.setChildren(fileList);
    return fileTreeDto;
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) RepositoryFileTreeDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileTreeDto) ArrayList(java.util.ArrayList) RepositoryFileTree(org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree)

Example 99 with RepositoryFileDto

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

the class SchedulerServiceTest method testDoGetGeneratedContentForSchedule.

@Test
public void testDoGetGeneratedContentForSchedule() throws Exception {
    String lineageId = "test.prpt";
    FileService mockFileService = mock(FileService.class);
    doReturn(mockFileService).when(schedulerService).getFileService();
    SessionResource mockSessionResource = mock(SessionResource.class);
    doReturn(mockSessionResource).when(schedulerService).getSessionResource();
    String currentUserDir = "currentUserDir";
    doReturn(currentUserDir).when(mockSessionResource).doGetCurrentUserDir();
    List<RepositoryFileDto> mockList = mock(List.class);
    doReturn(mockList).when(mockFileService).searchGeneratedContent(currentUserDir, lineageId, QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID);
    List<RepositoryFileDto> list = schedulerService.doGetGeneratedContentForSchedule(lineageId);
    assertEquals(mockList, list);
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) SessionResource(org.pentaho.platform.web.http.api.resources.SessionResource) Test(org.junit.Test)

Example 100 with RepositoryFileDto

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

the class FileServiceTest method testGetDefaultLocation_Scenario_DefaultFolderIsNotAccessible.

@Test
public void testGetDefaultLocation_Scenario_DefaultFolderIsNotAccessible() throws Exception {
    RepositoryFileDto hiddenDto = new RepositoryFileDto();
    hiddenDto.setFolder(true);
    hiddenDto.setHidden(true);
    hiddenDto.setId(RandomStringUtils.randomNumeric(20));
    hiddenDto.setName("suzy");
    hiddenDto.setPath("/home/suzy");
    DefaultUnifiedRepositoryWebService repoWs = mock(DefaultUnifiedRepositoryWebService.class);
    doReturn(repoWs).when(fileService).getRepoWs();
    doReturn(hiddenDto).when(repoWs).getFile("/home/suzy");
    when(PentahoSystem.get(ISystemConfig.class).getProperty(eq(PentahoSystem.DEFAULT_FOLDER_WHEN_HOME_FOLDER_IS_HIDDEN_PROPERTY))).thenReturn("/default-folder");
    doReturn(null).when(repoWs).getFile("/default-folder");
    assertEquals(ClientRepositoryPaths.getRootFolderPath(), fileService.doGetDefaultLocation(":home:suzy"));
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) DefaultUnifiedRepositoryWebService(org.pentaho.platform.repository2.unified.webservices.DefaultUnifiedRepositoryWebService) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)77 RepositoryFileDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto)77 FileNotFoundException (java.io.FileNotFoundException)35 ArrayList (java.util.ArrayList)34 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)29 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 Serializable (java.io.Serializable)26 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)26 Matchers.anyString (org.mockito.Matchers.anyString)25 GeneralSecurityException (java.security.GeneralSecurityException)14 StringKeyStringValueDto (org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto)11 IllegalSelectorException (java.nio.channels.IllegalSelectorException)9 InvalidParameterException (java.security.InvalidParameterException)9 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)9 Properties (java.util.Properties)8 UnifiedRepositoryAccessDeniedException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)8 DefaultUnifiedRepositoryWebService (org.pentaho.platform.repository2.unified.webservices.DefaultUnifiedRepositoryWebService)8 IOException (java.io.IOException)7 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)7 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)7