use of org.pentaho.platform.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 = getRepoWs().getTreeFromRequest(repositoryRequest);
// BISERVER-9599 - Use special sort order
if (isShowingTitle(repositoryRequest)) {
Collator collator = getCollatorInstance();
// ignore case
collator.setStrength(Collator.PRIMARY);
sortByLocaleTitle(collator, tree);
}
return tree;
}
use of org.pentaho.platform.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);
}
use of org.pentaho.platform.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;
}
use of org.pentaho.platform.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;
}
Aggregations