Search in sources :

Example 6 with RepositoryFileTreeDto

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

the class RepositoryFileTreeAdapter method unmarshal.

@Override
public RepositoryFileTree unmarshal(final RepositoryFileTreeDto v) {
    List<RepositoryFileTree> children = null;
    List<RepositoryFileTreeDto> childrenDTO = v.getChildren();
    if (childrenDTO != null) {
        children = new ArrayList<RepositoryFileTree>();
        for (RepositoryFileTreeDto child : childrenDTO) {
            children.add(unmarshal(child));
        }
    }
    RepositoryFileTree repositoryFileTree = new RepositoryFileTree(RepositoryFileAdapter.toFile(v.getFile()), children);
    Boolean versioningEnable = v.getFile().getVersioningEnabled();
    Boolean versionCommentEnabled = v.getFile().getVersionCommentEnabled();
    if (versioningEnable != null) {
        repositoryFileTree.setVersioningEnabled(versioningEnable);
    }
    if (versionCommentEnabled != null) {
        repositoryFileTree.setVersionCommentEnabled(versionCommentEnabled);
    }
    return repositoryFileTree;
}
Also used : RepositoryFileTreeDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileTreeDto) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 7 with RepositoryFileTreeDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileTreeDto 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);
    if (tree != null) {
        return new RepositoryFileTreeAdapter(repositoryRequest).marshal(tree);
    } else {
        return null;
    }
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 8 with RepositoryFileTreeDto

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

the class FileServiceTest method testDoGetTree.

@Test
public void testDoGetTree() {
    String pathId = ":path:to:file:file1.ext";
    int depth = 1;
    String filter = "*|FOLDERS";
    boolean showHidden = true;
    boolean includeAcls = true;
    // Test 1
    doReturn("test").when(fileService).idToPath(anyString());
    RepositoryRequest mockRequest = mock(RepositoryRequest.class);
    doReturn(mockRequest).when(fileService).getRepositoryRequest(anyString(), anyBoolean(), anyInt(), anyString());
    RepositoryFileDto mockChildFile = mock(RepositoryFileDto.class);
    doReturn("test").when(mockChildFile).getId();
    RepositoryFileTreeDto mockChildDto = mock(RepositoryFileTreeDto.class);
    doReturn(mockChildFile).when(mockChildDto).getFile();
    List<RepositoryFileTreeDto> mockChildrenDto = new ArrayList<RepositoryFileTreeDto>();
    mockChildrenDto.add(mockChildDto);
    RepositoryFileTreeDto mockTreeDto = mock(RepositoryFileTreeDto.class);
    doReturn(mockChildrenDto).when(mockTreeDto).getChildren();
    doReturn(mockTreeDto).when(fileService.defaultUnifiedRepositoryWebService).getTreeFromRequest(mockRequest);
    doReturn(true).when(fileService).isShowingTitle(mockRequest);
    Collator mockCollator = mock(Collator.class);
    doReturn(mockCollator).when(fileService).getCollatorInstance();
    doNothing().when(fileService).sortByLocaleTitle(mockCollator, mockTreeDto);
    Map<String, Serializable> fileMeta = new HashMap<String, Serializable>();
    fileMeta.put(IUnifiedRepository.SYSTEM_FOLDER, new Boolean(false));
    doReturn(fileMeta).when(fileService.repository).getFileMetadata(anyString());
    fileService.doGetTree(pathId, depth, filter, showHidden, includeAcls);
    verify(fileService, times(1)).idToPath(anyString());
    verify(mockRequest, times(1)).setIncludeAcls(anyBoolean());
    verify(mockCollator, times(1)).setStrength(Collator.PRIMARY);
    verify(fileService, times(1)).sortByLocaleTitle(mockCollator, mockTreeDto);
    // verify( mockTreeDto ).setChildren( mockChildrenDto );
    // Test 2 - path id is null
    pathId = null;
    fileService.doGetTree(pathId, depth, filter, showHidden, includeAcls);
    verify(fileService, times(1)).getRepositoryRequest(eq(FileUtils.PATH_SEPARATOR), anyBoolean(), anyInt(), anyString());
    // Test 3 - path id is set to the file utils path separator
    pathId = FileUtils.PATH_SEPARATOR;
    fileService.doGetTree(pathId, depth, filter, showHidden, includeAcls);
    verify(fileService, times(2)).getRepositoryRequest(eq(FileUtils.PATH_SEPARATOR), anyBoolean(), anyInt(), anyString());
    // Test 3 - includeSystemFolders is false
    mockRequest.setIncludeSystemFolders(false);
    doReturn(mockTreeDto).when(fileService.defaultUnifiedRepositoryWebService).getTreeFromRequest(mockRequest);
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) Serializable(java.io.Serializable) HashMap(java.util.HashMap) RepositoryFileTreeDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileTreeDto) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Collator(java.text.Collator) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) Test(org.junit.Test)

Example 9 with RepositoryFileTreeDto

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

the class UnifiedRepositoryPurgeServiceTest method getPurgeService.

// create the necessary mocks for running a full Purge Utility job
private static UnifiedRepositoryPurgeService getPurgeService(IUnifiedRepository mockRepo) {
    UnifiedRepositoryPurgeService purgeService = new UnifiedRepositoryPurgeService(mockRepo);
    DefaultUnifiedRepositoryWebService mockRepoWs = mock(DefaultUnifiedRepositoryWebService.class);
    UnifiedRepositoryPurgeService.repoWs = mockRepoWs;
    // Create a mocked tree to be returned
    JAXBContext jc;
    RepositoryFileTreeDto tree = null;
    try {
        jc = JAXBContext.newInstance(RepositoryFileTreeDto.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        ByteArrayInputStream xml = new ByteArrayInputStream(treeResponse.getBytes());
        tree = (RepositoryFileTreeDto) unmarshaller.unmarshal(xml);
    } catch (JAXBException e) {
        e.printStackTrace();
        fail("Test class has invalid xml representation of tree");
    }
    when(mockRepoWs.getTreeFromRequest(any(RepositoryRequest.class))).thenReturn(tree);
    return purgeService;
}
Also used : DefaultUnifiedRepositoryWebService(org.pentaho.platform.repository2.unified.webservices.DefaultUnifiedRepositoryWebService) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryFileTreeDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileTreeDto) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 10 with RepositoryFileTreeDto

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

the class FileService method doGetTree.

public RepositoryFileTreeDto doGetTree(String pathId, Integer depth, String filter, Boolean showHidden, Boolean includeAcls, Boolean includeSystemFolders) {
    String path = null;
    if (pathId == null || pathId.equals(FileUtils.PATH_SEPARATOR)) {
        path = FileUtils.PATH_SEPARATOR;
    } else if (!pathId.startsWith(FileUtils.PATH_SEPARATOR)) {
        path = idToPath(pathId);
    }
    RepositoryRequest repositoryRequest = getRepositoryRequest(path, showHidden, depth, filter);
    repositoryRequest.setIncludeAcls(includeAcls);
    repositoryRequest.setIncludeSystemFolders(includeSystemFolders);
    RepositoryFileTreeDto tree = null;
    try {
        tree = getRepoWs().getTreeFromRequest(repositoryRequest);
    } catch (UnifiedRepositoryException e) {
        logger.error(e.getCause());
    }
    // BISERVER-9599 - Use special sort order
    if (tree != null && isShowingTitle(repositoryRequest)) {
        Collator collator = getCollatorInstance();
        // ignore case
        collator.setStrength(Collator.PRIMARY);
        sortByLocaleTitle(collator, tree);
    }
    return tree;
}
Also used : RepositoryFileTreeDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileTreeDto) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) Collator(java.text.Collator)

Aggregations

RepositoryFileTreeDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileTreeDto)13 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)5 RepositoryRequest (org.pentaho.platform.api.repository2.unified.RepositoryRequest)5 RepositoryFileDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto)4 Collator (java.text.Collator)3 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 JAXBContext (javax.xml.bind.JAXBContext)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 RepositoryFileTree (org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1 ArgumentMatchers.anyBoolean (org.mockito.ArgumentMatchers.anyBoolean)1 Matchers.anyBoolean (org.mockito.Matchers.anyBoolean)1