Search in sources :

Example 11 with RepositoryFileTreeDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileTreeDto 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 12 with RepositoryFileTreeDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileTreeDto 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 13 with RepositoryFileTreeDto

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

the class RepositoryFileUtils method convertToRepositoryFileTree.

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

Example 14 with RepositoryFileTreeDto

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

the class RepositoryFileTreeAdapterTest method testWhenChildrenIsDeleted.

@Test
public void testWhenChildrenIsDeleted() throws Exception {
    // mock RepositoryFile to return null
    RepositoryFile mockFile = mock(RepositoryFileProxy.class);
    when(mockFile.isHidden()).thenReturn(null);
    // create tree with the mockFile
    RepositoryFileTree nullValueDir = new RepositoryFileTree(mockFile, Collections.<RepositoryFileTree>emptyList());
    RepositoryFile root = new RepositoryFile.Builder("rootDir").build();
    ArrayList<RepositoryFileTree> children = new ArrayList<RepositoryFileTree>(1);
    children.add(nullValueDir);
    RepositoryFileTree rootDir = new RepositoryFileTree(root, children);
    // to DTO
    RepositoryFileTreeAdapter adapter = new RepositoryFileTreeAdapter();
    RepositoryFileTreeDto dtoThere = adapter.marshal(rootDir);
    // as isHidden() returns null, it's expected that null was returned, so root has no children
    assertTrue(dtoThere.getChildren().isEmpty());
}
Also used : RepositoryFileTreeDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileTreeDto) ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) Test(org.junit.Test)

Example 15 with RepositoryFileTreeDto

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

the class RepositoryFileTreeAdapterTest method testBIServer7777.

/**
 * Assert empty list in RepositoryFileTree#children survives full jaxb serialization roundtrip
 */
@Test
public void testBIServer7777() throws Exception {
    IUnifiedRepository unifiedRepository = mock(IUnifiedRepository.class);
    PentahoSystem.registerObject(unifiedRepository);
    RepositoryFileAcl acl = new RepositoryFileAcl.Builder("admin").build();
    when(unifiedRepository.getAcl(anyString())).thenReturn(acl);
    IRepositoryVersionManager mockRepositoryVersionManager = mock(IRepositoryVersionManager.class);
    when(mockRepositoryVersionManager.isVersioningEnabled(anyString())).thenReturn(true);
    when(mockRepositoryVersionManager.isVersionCommentEnabled(anyString())).thenReturn(false);
    JcrRepositoryFileUtils.setRepositoryVersionManager(mockRepositoryVersionManager);
    // file tree with empty children
    RepositoryFile empty = new RepositoryFile.Builder("empty").build();
    RepositoryFileTree emptyDir = new RepositoryFileTree(empty, Collections.<RepositoryFileTree>emptyList());
    RepositoryFile root = new RepositoryFile.Builder("rootDir").build();
    ArrayList<RepositoryFileTree> children = new ArrayList<RepositoryFileTree>(1);
    children.add(emptyDir);
    RepositoryFileTree rootDir = new RepositoryFileTree(root, children);
    // to DTO
    RepositoryFileTreeAdapter adapter = new RepositoryFileTreeAdapter();
    RepositoryFileTreeDto dtoThere = adapter.marshal(rootDir);
    assertNotNull(dtoThere.getChildren().get(0).getChildren());
    // serialize
    final JAXBContext jaxbContext = JAXBContext.newInstance(RepositoryFileTreeDto.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    StringWriter sw = new StringWriter();
    marshaller.marshal(dtoThere, sw);
    // and bring it back
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    StringReader sr = new StringReader(sw.toString());
    RepositoryFileTreeDto dtoBackAgain = (RepositoryFileTreeDto) unmarshaller.unmarshal(sr);
    assertNotNull(dtoBackAgain.getChildren().get(0).getChildren());
    // unmarshall
    RepositoryFileTree rootDir2 = adapter.unmarshal(dtoBackAgain);
    assertNotNull(rootDir2.getChildren().get(0).getChildren());
    assertEquals(rootDir, rootDir2);
}
Also used : Marshaller(javax.xml.bind.Marshaller) RepositoryFileTreeDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileTreeDto) ArrayList(java.util.ArrayList) JAXBContext(javax.xml.bind.JAXBContext) IRepositoryVersionManager(org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Unmarshaller(javax.xml.bind.Unmarshaller) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

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