Search in sources :

Example 21 with RepositoryRequest

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

the class PurRepository method loadRepositoryFileTreeFolders.

private RepositoryFileTree loadRepositoryFileTreeFolders(String path, int depth, boolean includeAcls, boolean showHidden) {
    RepositoryRequest repoRequest = new RepositoryRequest();
    repoRequest.setDepth(depth);
    repoRequest.setIncludeAcls(includeAcls);
    repoRequest.setChildNodeFilter("*");
    repoRequest.setTypes(FILES_TYPE_FILTER.FOLDERS);
    repoRequest.setPath(path);
    repoRequest.setShowHidden(showHidden);
    readWriteLock.readLock().lock();
    RepositoryFileTree result;
    try {
        result = pur.getTree(repoRequest);
    } finally {
        readWriteLock.readLock().unlock();
    }
    return result;
}
Also used : RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 22 with RepositoryRequest

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

the class PurRepositoryUnitTest method testEtcIsNotThereInGetNrDirectories.

@Test
public void testEtcIsNotThereInGetNrDirectories() throws KettleException {
    PurRepository purRepository = new PurRepository();
    IUnifiedRepository mockRepo = mock(IUnifiedRepository.class);
    RepositoryConnectResult result = mock(RepositoryConnectResult.class);
    when(result.getUnifiedRepository()).thenReturn(mockRepo);
    IRepositoryConnector connector = mock(IRepositoryConnector.class);
    when(connector.connect(anyString(), anyString())).thenReturn(result);
    PurRepositoryMeta mockMeta = mock(PurRepositoryMeta.class);
    purRepository.init(mockMeta);
    purRepository.setPurRepositoryConnector(connector);
    ObjectId objectId = mock(ObjectId.class);
    RepositoryFile mockEtcFolder = mock(RepositoryFile.class);
    RepositoryFile mockFolderVisible = mock(RepositoryFile.class);
    RepositoryFile mockRootFolder = mock(RepositoryFile.class);
    RepositoryFileTree mockRepositoryTree = mock(RepositoryFileTree.class);
    String testId = "TEST_ID";
    String visibleFolderId = testId + "2";
    when(objectId.getId()).thenReturn(testId);
    when(mockRepo.getFileById(testId)).thenReturn(mockEtcFolder);
    when(mockRepo.getFile(ClientRepositoryPaths.getEtcFolderPath())).thenReturn(mockEtcFolder);
    when(mockRepo.getFileById(visibleFolderId)).thenReturn(mockFolderVisible);
    when(mockEtcFolder.getPath()).thenReturn("/etc");
    when(mockEtcFolder.getName()).thenReturn("etc");
    when(mockEtcFolder.isFolder()).thenReturn(true);
    when(mockEtcFolder.getId()).thenReturn(testId);
    when(mockFolderVisible.getPath()).thenReturn("/visible");
    when(mockFolderVisible.getName()).thenReturn("visible");
    when(mockFolderVisible.isFolder()).thenReturn(true);
    when(mockFolderVisible.getId()).thenReturn(visibleFolderId);
    when(mockRepositoryTree.getFile()).thenReturn(mockRootFolder);
    when(mockRootFolder.getId()).thenReturn("/");
    when(mockRootFolder.getPath()).thenReturn("/");
    List<RepositoryFile> rootChildren = new ArrayList<>(Arrays.asList(mockEtcFolder, mockFolderVisible));
    when(mockRepo.getChildren(argThat(IsInstanceOf.<RepositoryRequest>instanceOf(RepositoryRequest.class)))).thenReturn(rootChildren);
    // for Lazy Repo
    when(mockRepo.getFile("/")).thenReturn(mockRootFolder);
    // for Eager Repo
    RepositoryFileTree repositoryFileTree = mock(RepositoryFileTree.class);
    when(mockRepo.getTree("/", -1, null, true)).thenReturn(repositoryFileTree);
    when(repositoryFileTree.getFile()).thenReturn(mockRootFolder);
    RepositoryFileTree mockEtcFolderTree = mock(RepositoryFileTree.class);
    when(mockEtcFolderTree.getFile()).thenReturn(mockEtcFolder);
    RepositoryFileTree mockFolderVisibleTree = mock(RepositoryFileTree.class);
    when(mockFolderVisibleTree.getFile()).thenReturn(mockFolderVisible);
    when(repositoryFileTree.getChildren()).thenReturn(new ArrayList<>(Arrays.asList(mockEtcFolderTree, mockFolderVisibleTree)));
    purRepository.connect("TEST_USER", "TEST_PASSWORD");
    int children = purRepository.getRootDir().getNrSubdirectories();
    assertThat(children, equalTo(1));
}
Also used : StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 23 with RepositoryRequest

use of org.pentaho.platform.api.repository2.unified.RepositoryRequest 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;
}
Also used : RepositoryFileTreeDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileTreeDto) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) Collator(java.text.Collator)

Example 24 with RepositoryRequest

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

the class CopyFilesOperation_DeepFolderCopyTest method mockRequest.

/**
 * Enforces to return provided {@code children}, when making a RepositoryRequest to know {@code folder} content.
 */
private void mockRequest(RepositoryFile folder, List<RepositoryFile> children) {
    RepositoryRequest mockedRequest = mock(RepositoryRequest.class);
    doReturn(mockedRequest).when(operation).createRepoRequest(eq(folder), anyInt());
    doReturn(children).when(repo).getChildren(mockedRequest);
}
Also used : RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest)

Example 25 with RepositoryRequest

use of org.pentaho.platform.api.repository2.unified.RepositoryRequest 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)

Aggregations

RepositoryRequest (org.pentaho.platform.api.repository2.unified.RepositoryRequest)31 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)19 RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)19 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 Matchers.anyString (org.mockito.Matchers.anyString)8 ITenant (org.pentaho.platform.api.mt.ITenant)7 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Collator (java.text.Collator)4 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)4 File (java.io.File)3 Serializable (java.io.Serializable)3 ObjectId (org.pentaho.di.repository.ObjectId)3 EERepositoryObject (org.pentaho.di.repository.pur.model.EERepositoryObject)3 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)3 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)3 HashMap (java.util.HashMap)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)2