Search in sources :

Example 6 with RepositoryFile

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

use of org.pentaho.platform.api.repository2.unified.RepositoryFile 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 8 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile 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 9 with RepositoryFile

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

the class LazyUnifiedRepositoryDirectory method findDirectory.

@Override
public RepositoryDirectory findDirectory(ObjectId id_directory) {
    RepositoryFile file = repository.getFileById(id_directory.getId());
    if (file == null || !file.isFolder()) {
        return null;
    }
    if (isRoot() && RepositoryDirectory.DIRECTORY_SEPARATOR.equals(file.getPath())) {
        return this;
    }
    // Verifies if this is the parent directory of file and if so passes this as parent argument
    String parentPath = getParentPath(file.getPath());
    if (self.getPath().endsWith(RepositoryDirectory.DIRECTORY_SEPARATOR)) {
        if (parentPath.equals(self.getPath().substring(0, self.getPath().length() - 1))) {
            return new LazyUnifiedRepositoryDirectory(file, this, repository, registry);
        }
    } else {
        if (parentPath.equals(self.getPath())) {
            return new LazyUnifiedRepositoryDirectory(file, this, repository, registry);
        }
    }
    return new LazyUnifiedRepositoryDirectory(file, findDirectory(parentPath), repository, registry);
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 10 with RepositoryFile

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

the class LazyUnifiedRepositoryDirectory method getChildren.

@Override
public List<RepositoryDirectoryInterface> getChildren() {
    if (subdirectories == null) {
        subdirectories = new ArrayList<>();
        synchronized (subdirectories) {
            List<RepositoryFile> children = getAllURChildrenFiles();
            for (RepositoryFile child : children) {
                LazyUnifiedRepositoryDirectory dir = new LazyUnifiedRepositoryDirectory(child, this, repository, registry);
                dir.setObjectId(new StringObjectId(child.getId().toString()));
                this.addSubdirectory(dir);
            }
        }
    }
    return subdirectories;
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) StringObjectId(org.pentaho.di.repository.StringObjectId)

Aggregations

RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)455 Test (org.junit.Test)183 ITenant (org.pentaho.platform.api.mt.ITenant)87 Matchers.anyString (org.mockito.Matchers.anyString)86 ArrayList (java.util.ArrayList)85 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)83 Serializable (java.io.Serializable)56 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)53 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)49 KettleException (org.pentaho.di.core.exception.KettleException)40 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)40 ByteArrayInputStream (java.io.ByteArrayInputStream)39 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)39 IOException (java.io.IOException)37 File (java.io.File)34 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)34 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)33 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)33 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)32 KettleFileException (org.pentaho.di.core.exception.KettleFileException)32