public RepositoryFileTree build() { return new RepositoryFileTree( file, toTreeChildren( children ) ); }
private RepositoryFileTree getTree( final File file, final int depth, final String childNodeFilter, RepositoryRequest.FILES_TYPE_FILTER types ) { RepositoryFile rootFile = internalGetFile( file ); List<RepositoryFileTree> children; if ( depth != 0 ) { children = new ArrayList<RepositoryFileTree>(); if ( file.isDirectory() ) { File[] childrenArray = file.listFiles(); for ( File child : childrenArray ) { if ( child.isFile() ) { if ( types == RepositoryRequest.FILES_TYPE_FILTER.FILES_FOLDERS || types == RepositoryRequest.FILES_TYPE_FILTER.FILES ) { children.add( new RepositoryFileTree( internalGetFile( child ), new ArrayList<>() ) ); } continue; } RepositoryFileTree repositoryChildFileTree = getTree( child, depth - 1, childNodeFilter, types ); if ( repositoryChildFileTree != null ) { children.add( repositoryChildFileTree ); } } } Collections.sort( children ); } else { children = null; } return new RepositoryFileTree( rootFile, children ); }
children = null; return new RepositoryFileTree( rootFile, children );
@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() ); }
@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; } }
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 );
@Override public RepositoryFileTree getTree( final String path, final int depth, final String filter, final boolean showHidden ) { FileRecord r = root.getFileRecord( path ); RepositoryFile rootFile = r.getFile(); if ( ( !showHidden && rootFile.isHidden() ) || rootFile.isAclNode() ) { return null; } List<RepositoryFileTree> children; if ( depth != 0 ) { children = new ArrayList<RepositoryFileTree>(); if ( rootFile.isFolder() ) { List<RepositoryFile> childrenTmp = getChildren( rootFile.getId(), filter ); for ( RepositoryFile child : childrenTmp ) { RepositoryFileTree repositoryFileTree = getTree( child.getPath(), depth - 1, filter, showHidden ); if ( repositoryFileTree != null ) { children.add( repositoryFileTree ); } } } Collections.sort( children ); } else { children = null; } return new RepositoryFileTree( rootFile, children ); }