Search in sources :

Example 1 with RepositoryFileTree

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

the class PurRepositoryUnitTest method testGetObjectInformationGetsAclByFileId.

@Test
public void testGetObjectInformationGetsAclByFileId() throws KettleException {
    PurRepository purRepository = new PurRepository();
    IUnifiedRepository mockRepo = mock(IUnifiedRepository.class);
    RepositoryConnectResult result = mock(RepositoryConnectResult.class);
    when(result.getUnifiedRepository()).thenReturn(mockRepo);
    RepositoryServiceRegistry registry = mock(RepositoryServiceRegistry.class);
    UnifiedRepositoryLockService lockService = new UnifiedRepositoryLockService(mockRepo);
    when(registry.getService(ILockService.class)).thenReturn(lockService);
    when(result.repositoryServiceRegistry()).thenReturn(registry);
    IRepositoryConnector connector = mock(IRepositoryConnector.class);
    when(connector.connect(anyString(), anyString())).thenReturn(result);
    PurRepositoryMeta mockMeta = mock(PurRepositoryMeta.class);
    purRepository.init(mockMeta);
    purRepository.setPurRepositoryConnector(connector);
    // purRepository.setTest( mockRepo );
    ObjectId objectId = mock(ObjectId.class);
    RepositoryFile mockFile = mock(RepositoryFile.class);
    RepositoryFile mockRootFolder = mock(RepositoryFile.class);
    RepositoryObjectType repositoryObjectType = RepositoryObjectType.TRANSFORMATION;
    RepositoryFileTree mockRepositoryTree = mock(RepositoryFileTree.class);
    String testId = "TEST_ID";
    String testFileId = "TEST_FILE_ID";
    when(objectId.getId()).thenReturn(testId);
    when(mockRepo.getFileById(testId)).thenReturn(mockFile);
    when(mockFile.getPath()).thenReturn("/home/testuser/path.ktr");
    when(mockFile.isLocked()).thenReturn(false);
    when(mockFile.getId()).thenReturn(testFileId);
    when(mockRepo.getTree(anyString(), anyInt(), anyString(), anyBoolean())).thenReturn(mockRepositoryTree);
    when(mockRepositoryTree.getFile()).thenReturn(mockRootFolder);
    when(mockRootFolder.getId()).thenReturn("/");
    when(mockRootFolder.getPath()).thenReturn("/");
    when(mockRepo.getFile("/")).thenReturn(mockRootFolder);
    purRepository.connect("TEST_USER", "TEST_PASSWORD");
    purRepository.getObjectInformation(objectId, repositoryObjectType);
    verify(mockRepo).getAcl(testFileId);
}
Also used : StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 2 with RepositoryFileTree

use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree 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<RepositoryFileTree>(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 3 with RepositoryFileTree

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

the class LazyUnifiedRepositoryDirectory method getRepositoryObjects.

@Override
public List<RepositoryElementMetaInterface> getRepositoryObjects() {
    if (fileChildren == null) {
        fileChildren = new ArrayList<RepositoryElementMetaInterface>();
        synchronized (fileChildren) {
            UnifiedRepositoryLockService lockService = (UnifiedRepositoryLockService) registry.getService(ILockService.class);
            RepositoryFileTree tree = repository.getTree(new RepositoryRequest(this.self.getPath(), true, 1, null));
            for (RepositoryFileTree tchild : tree.getChildren()) {
                RepositoryFile child = tchild.getFile();
                if (!child.isFolder()) {
                    RepositoryLock lock = null;
                    try {
                        lock = lockService.getLock(child);
                        RepositoryObjectType objectType = PurRepository.getObjectType(child.getName());
                        EERepositoryObject repositoryObject = new EERepositoryObject(child, this, null, objectType, null, lock, false);
                        repositoryObject.setVersioningEnabled(tchild.getVersioningEnabled());
                        repositoryObject.setVersionCommentEnabled(tchild.getVersionCommentEnabled());
                        fileChildren.add(repositoryObject);
                    } catch (KettleException e) {
                        logger.error("Error converting Unified Repository file to PDI RepositoryObject: " + child.getPath() + ". File will be skipped", e);
                    }
                }
            }
        }
    }
    return fileChildren;
}
Also used : EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) KettleException(org.pentaho.di.core.exception.KettleException) ILockService(org.pentaho.di.ui.repository.pur.services.ILockService) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryLock(org.pentaho.di.repository.pur.model.RepositoryLock) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 4 with RepositoryFileTree

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

the class PurRepository method loadRepositoryFileTree.

private RepositoryFileTree loadRepositoryFileTree(String path, String filter, int depth, boolean showHidden, boolean includeAcls, FILES_TYPE_FILTER types) {
    RepositoryRequest repoRequest = new RepositoryRequest();
    repoRequest.setPath(Utils.isEmpty(path) ? "/" : path);
    repoRequest.setChildNodeFilter(filter == null ? "*" : filter);
    repoRequest.setDepth(depth);
    repoRequest.setShowHidden(showHidden);
    repoRequest.setIncludeAcls(includeAcls);
    repoRequest.setTypes(types == null ? FILES_TYPE_FILTER.FILES_FOLDERS : types);
    RepositoryFileTree fileTree = pur.getTree(repoRequest);
    return fileTree;
}
Also used : RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 5 with RepositoryFileTree

use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree 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);
    return pur.getTree(repoRequest);
}
Also used : RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest)

Aggregations

RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)35 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)25 Test (org.junit.Test)14 RepositoryRequest (org.pentaho.platform.api.repository2.unified.RepositoryRequest)13 ArrayList (java.util.ArrayList)10 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)7 Matchers.anyString (org.mockito.Matchers.anyString)6 StringObjectId (org.pentaho.di.repository.StringObjectId)6 RepositoryObjectType (org.pentaho.di.repository.RepositoryObjectType)5 KettleException (org.pentaho.di.core.exception.KettleException)4 ObjectId (org.pentaho.di.repository.ObjectId)4 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)4 ITenant (org.pentaho.platform.api.mt.ITenant)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 File (java.io.File)3 Serializable (java.io.Serializable)3 Date (java.util.Date)3 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)3 RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)3 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)3