Search in sources :

Example 21 with RepositoryFileTree

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

the class PurRepositoryUnitTest method testRootIsNotVisible.

@Test
public void testRootIsNotVisible() 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);
    RepositoryFile mockRootFolder = mock(RepositoryFile.class);
    when(mockRootFolder.getId()).thenReturn("/");
    when(mockRootFolder.getPath()).thenReturn("/");
    // 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);
    purRepository.connect("TEST_USER", "TEST_PASSWORD");
    RepositoryDirectoryInterface rootDir = purRepository.getRootDir();
    assertFalse(rootDir.isVisible());
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 22 with RepositoryFileTree

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

the class PurRepositoryUnitTest method testEtcIsNotThereInGetChildren.

@Test
public void testEtcIsNotThereInGetChildren() 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);
    // 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("/etc");
    when(mockFile.getId()).thenReturn(testFileId);
    when(mockRepositoryTree.getFile()).thenReturn(mockRootFolder);
    when(mockRootFolder.getId()).thenReturn("/");
    when(mockRootFolder.getPath()).thenReturn("/");
    List<RepositoryFile> rootChildren = new ArrayList<>(Collections.singletonList(mockFile));
    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);
    purRepository.connect("TEST_USER", "TEST_PASSWORD");
    List<RepositoryDirectoryInterface> children = purRepository.getRootDir().getChildren();
    assertThat(children, empty());
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) 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) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) 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 RepositoryFileTree

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

the class PurRepositoryUnitTest method testRevisionsEnabled.

@Test
public void testRevisionsEnabled() 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);
    RepositoryServiceRegistry registry = mock(RepositoryServiceRegistry.class);
    UnifiedRepositoryLockService lockService = new UnifiedRepositoryLockService(mockRepo);
    when(registry.getService(ILockService.class)).thenReturn(lockService);
    when(result.repositoryServiceRegistry()).thenReturn(registry);
    PurRepositoryMeta mockMeta = mock(PurRepositoryMeta.class);
    purRepository.init(mockMeta);
    purRepository.setPurRepositoryConnector(connector);
    // purRepository.setTest( mockRepo );
    ObjectId objectId = mock(ObjectId.class);
    RepositoryFile mockFileVersioningEnabled = mock(RepositoryFile.class);
    RepositoryFile mockFileVersioningNotEnabled = mock(RepositoryFile.class);
    RepositoryFileTree mockRepositoryTreeChildVersioningEnabled = mock(RepositoryFileTree.class);
    RepositoryFileTree mockRepositoryTreeChildVersioningNotEnabled = mock(RepositoryFileTree.class);
    RepositoryFile publicFolder = mock(RepositoryFile.class);
    RepositoryFileTree publicFolderTree = mock(RepositoryFileTree.class);
    RepositoryFile mockRootFolder = mock(RepositoryFile.class);
    RepositoryObjectType repositoryObjectType = RepositoryObjectType.TRANSFORMATION;
    RepositoryFileTree mockRepositoryTree = mock(RepositoryFileTree.class);
    String testId = "TEST_ID";
    String testFileId = "TEST_FILE_ID";
    List<RepositoryFileTree> children = Arrays.asList(mockRepositoryTreeChildVersioningEnabled, mockRepositoryTreeChildVersioningNotEnabled);
    when(objectId.getId()).thenReturn(testId);
    when(mockRepo.getFileById(testId)).thenReturn(mockFileVersioningEnabled);
    when(mockFileVersioningEnabled.getPath()).thenReturn("/public/path.ktr");
    when(mockFileVersioningEnabled.getId()).thenReturn(testFileId);
    when(mockFileVersioningEnabled.getName()).thenReturn("path.ktr");
    when(mockFileVersioningNotEnabled.getPath()).thenReturn("/public/path2.ktr");
    when(mockFileVersioningNotEnabled.getId()).thenReturn(testFileId + "2");
    when(mockFileVersioningNotEnabled.getName()).thenReturn("path2.ktr");
    when(publicFolder.getPath()).thenReturn("/public");
    when(publicFolder.getName()).thenReturn("public");
    when(publicFolder.getId()).thenReturn(testFileId + "3");
    when(publicFolder.isFolder()).thenReturn(true);
    when(publicFolderTree.getFile()).thenReturn(publicFolder);
    when(mockRepositoryTreeChildVersioningEnabled.getFile()).thenReturn(mockFileVersioningEnabled);
    when(mockRepositoryTreeChildVersioningEnabled.getVersionCommentEnabled()).thenReturn(true);
    when(mockRepositoryTreeChildVersioningEnabled.getVersioningEnabled()).thenReturn(true);
    when(mockRepositoryTreeChildVersioningNotEnabled.getFile()).thenReturn(mockFileVersioningNotEnabled);
    when(mockRepositoryTreeChildVersioningNotEnabled.getVersionCommentEnabled()).thenReturn(false);
    when(mockRepositoryTreeChildVersioningNotEnabled.getVersioningEnabled()).thenReturn(false);
    when(mockRepo.getTree(anyString(), anyInt(), anyString(), anyBoolean())).thenReturn(mockRepositoryTree);
    when(mockRepo.getTree(any(RepositoryRequest.class))).thenReturn(mockRepositoryTree);
    when(mockRepo.getTree(argThat(new ArgumentMatcher<RepositoryRequest>() {

        @Override
        public boolean matches(Object argument) {
            return ((RepositoryRequest) argument).getPath().equals("/public");
        }
    }))).thenReturn(publicFolderTree);
    when(mockRepositoryTree.getFile()).thenReturn(mockRootFolder);
    when(mockRepositoryTree.getChildren()).thenReturn(new ArrayList<>(Arrays.asList(publicFolderTree)));
    when(publicFolderTree.getChildren()).thenReturn(children);
    when(mockRootFolder.getId()).thenReturn("/");
    when(mockRootFolder.getPath()).thenReturn("/");
    when(mockRepo.getFile("/")).thenReturn(mockRootFolder);
    when(mockRepo.getFile("/public")).thenReturn(publicFolder);
    purRepository.connect("TEST_USER", "TEST_PASSWORD");
    List<RepositoryElementMetaInterface> repositoryObjects = purRepository.findDirectory("/public").getRepositoryObjects();
    assertThat(repositoryObjects.size(), is(2));
    // Test Enabled
    RepositoryElementMetaInterface element = repositoryObjects.get(0);
    assertThat(element, is(instanceOf(EERepositoryObject.class)));
    EERepositoryObject eeElement = (EERepositoryObject) element;
    assertThat(eeElement.getVersioningEnabled(), is(true));
    assertThat(eeElement.getVersionCommentEnabled(), is(true));
    // Test Not Enabled
    RepositoryElementMetaInterface element2 = repositoryObjects.get(1);
    assertThat(element2, is(instanceOf(EERepositoryObject.class)));
    EERepositoryObject eeElement2 = (EERepositoryObject) element;
    assertThat(eeElement2.getVersioningEnabled(), is(true));
    assertThat(eeElement2.getVersionCommentEnabled(), is(true));
}
Also used : EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) ArgumentMatcher(org.mockito.ArgumentMatcher) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface) Test(org.junit.Test)

Example 24 with RepositoryFileTree

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

the class PurRepository method initRepositoryDirectoryTree.

private RepositoryDirectoryInterface initRepositoryDirectoryTree(RepositoryFileTree repoTree) throws KettleException {
    RepositoryFile rootFolder = repoTree.getFile();
    RepositoryDirectory rootDir = new RepositoryDirectory();
    rootDir.setObjectId(new StringObjectId(rootFolder.getId().toString()));
    fillRepositoryDirectoryFromTree(rootDir, repoTree);
    // Example: /etc
    RepositoryDirectory etcDir = rootDir.findDirectory(ClientRepositoryPaths.getEtcFolderPath());
    RepositoryDirectory newRoot = new RepositoryDirectory();
    newRoot.setObjectId(rootDir.getObjectId());
    newRoot.setVisible(false);
    for (int i = 0; i < rootDir.getNrSubdirectories(); i++) {
        RepositoryDirectory childDir = rootDir.getSubdirectory(i);
        // Don't show /etc
        boolean isEtcChild = childDir.equals(etcDir);
        if (isEtcChild) {
            continue;
        }
        newRoot.addSubdirectory(childDir);
    }
    return newRoot;
}
Also used : RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) StringObjectId(org.pentaho.di.repository.StringObjectId) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint)

Example 25 with RepositoryFileTree

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

the class PurRepository method loadRepositoryDirectoryTree.

@Override
public RepositoryDirectoryInterface loadRepositoryDirectoryTree(String path, String filter, int depth, boolean showHidden, boolean includeEmptyFolder, boolean includeAcls) throws KettleException {
    // First check for possibility of speedy algorithm
    if (filter == null && "/".equals(path) && includeEmptyFolder) {
        return initRepositoryDirectoryTree(loadRepositoryFileTreeFolders("/", -1, includeAcls, showHidden));
    }
    // load count levels from root to destination path to load folder tree
    int fromRootToDest = StringUtils.countMatches(path, "/");
    // create new root directory "/"
    RepositoryDirectory dir = new RepositoryDirectory();
    // fetch folder tree from root "/" to destination path for populate folder
    RepositoryFileTree rootDirTree = loadRepositoryFileTree("/", "*", fromRootToDest, showHidden, includeAcls, FILES_TYPE_FILTER.FOLDERS);
    // populate directory by folder tree
    fillRepositoryDirectoryFromTree(dir, rootDirTree);
    RepositoryDirectoryInterface destinationDir = dir.findDirectory(path);
    // search for goal path and filter
    RepositoryFileTree repoTree = loadRepositoryFileTree(path, filter, depth, showHidden, includeAcls, FILES_TYPE_FILTER.FILES_FOLDERS);
    // populate the directory with founded files and subdirectories with files
    fillRepositoryDirectoryFromTree(destinationDir, repoTree);
    if (includeEmptyFolder) {
        RepositoryDirectoryInterface folders = initRepositoryDirectoryTree(loadRepositoryFileTree(path, null, depth, showHidden, includeAcls, FILES_TYPE_FILTER.FOLDERS));
        return copyFrom(folders, destinationDir);
    } else {
        return destinationDir;
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

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