Search in sources :

Example 6 with RepositoryFileTree

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

the class PurRepository method loadRepositoryDirectoryTree.

@Deprecated
@Override
public RepositoryDirectoryInterface loadRepositoryDirectoryTree(boolean eager) throws KettleException {
    // this method forces a reload of the repository directory tree structure
    // a new rootRef will be obtained - this is a SoftReference which will be used
    // by any calls to getRootDir()
    RepositoryDirectoryInterface rootDir;
    if (eager) {
        RepositoryFileTree rootFileTree = loadRepositoryFileTree(ClientRepositoryPaths.getRootFolderPath());
        rootDir = initRepositoryDirectoryTree(rootFileTree);
    } else {
        RepositoryFile root = pur.getFile("/");
        rootDir = new LazyUnifiedRepositoryDirectory(root, null, pur, purRepositoryServiceRegistry);
    }
    rootRef.setRef(rootDir);
    return rootDir;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 7 with RepositoryFileTree

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

the class PurRepository method fillRepositoryDirectoryFromTree.

private void fillRepositoryDirectoryFromTree(final RepositoryDirectoryInterface parentDir, final RepositoryFileTree treeNode) throws KettleException {
    try {
        List<RepositoryElementMetaInterface> fileChildren = new ArrayList<RepositoryElementMetaInterface>();
        List<RepositoryFileTree> children = treeNode.getChildren();
        if (children != null) {
            for (RepositoryFileTree child : children) {
                if (child.getFile().isFolder()) {
                    RepositoryDirectory dir = new RepositoryDirectory(parentDir, child.getFile().getName());
                    dir.setObjectId(new StringObjectId(child.getFile().getId().toString()));
                    parentDir.addSubdirectory(dir);
                    fillRepositoryDirectoryFromTree(dir, child);
                } else {
                    // a real file, like a Transformation or Job
                    RepositoryLock lock = unifiedRepositoryLockService.getLock(child.getFile());
                    RepositoryObjectType objectType = getObjectType(child.getFile().getName());
                    fileChildren.add(new EERepositoryObject(child, parentDir, null, objectType, null, lock, false));
                }
            }
            parentDir.setRepositoryObjects(fileChildren);
        }
    } catch (Exception e) {
        throw new KettleException("Unable to load directory structure from repository", e);
    }
}
Also used : EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) ArrayList(java.util.ArrayList) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) RepositoryLock(org.pentaho.di.repository.pur.model.RepositoryLock) StringObjectId(org.pentaho.di.repository.StringObjectId) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) UnifiedRepositoryCreateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException) UnifiedRepositoryUpdateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) KettleException(org.pentaho.di.core.exception.KettleException) IdNotFoundException(org.pentaho.di.core.exception.IdNotFoundException) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 8 with RepositoryFileTree

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

the class LocatorTestUtils method createFileTree.

private static RepositoryFileTree createFileTree(File root) {
    RepositoryFile repFile = new RepositoryFile(root.getPath(), root.getName(), root.isDirectory(), false, false, null, root.getAbsolutePath(), new Date(root.lastModified()), new Date(root.lastModified()), false, null, null, null, null, root.getName(), null, null, null, root.length(), "Admin", null);
    List<RepositoryFileTree> children = new ArrayList<RepositoryFileTree>();
    File[] files = root.listFiles();
    for (File file : files) {
        if (file.isHidden()) {
            continue;
        }
        if (file.isDirectory()) {
            RepositoryFileTree kid = createFileTree(file);
            children.add(kid);
        } else if (file.isFile()) {
            RepositoryFile kid = new RepositoryFile(file.getPath(), file.getName(), file.isDirectory(), false, false, null, file.getPath(), new Date(file.lastModified()), new Date(file.lastModified()), false, null, null, null, null, file.getName(), null, null, null, root.length(), "Admin", null);
            RepositoryFileTree kidTree = new RepositoryFileTree(kid, null);
            children.add(kidTree);
        }
    }
    RepositoryFileTree fileTree = new RepositoryFileTree(repFile, children);
    return fileTree;
}
Also used : ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Date(java.util.Date) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 9 with RepositoryFileTree

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

the class LocatorTestUtils method getTree.

/**
 * ************ end -- load job and trans methods for the mock diRepo ****************
 */
public static RepositoryFileTree getTree(RepositoryRequest req) {
    File root = new File(SOLUTION_PATH);
    RepositoryFileTree rft = createFileTree(root);
    return rft;
}
Also used : File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 10 with RepositoryFileTree

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

the class JcrRepositoryFileUtilsTest method testCheckNodeForTree.

@Test
public void testCheckNodeForTree() throws Exception {
    List<RepositoryFileTree> children = new ArrayList<>();
    IPathConversionHelper pathConversionHelper = new DefaultPathConversionHelper();
    ILockHelper lockHelperMock = mock(ILockHelper.class);
    IRepositoryAccessVoterManager repositoryAccessVoterManagerMock = mock(IRepositoryAccessVoterManager.class);
    MutableBoolean foundFiltered = new MutableBoolean();
    RepositoryFile fileMock = mock(RepositoryFile.class);
    when(fileMock.getId()).thenReturn(1);
    PowerMockito.mockStatic(JcrRepositoryFileUtils.class);
    PowerMockito.mockStatic(JcrRepositoryFileAclUtils.class);
    PowerMockito.doCallRealMethod().when(JcrRepositoryFileUtils.class, "checkNodeForTree", nodeMock, children, sessionMock, pJcrConstMock, pathConversionHelper, "childNodeFilter", lockHelperMock, 0, false, repositoryAccessVoterManagerMock, RepositoryRequest.FILES_TYPE_FILTER.FOLDERS, foundFiltered, true, false, "/");
    when(JcrRepositoryFileUtils.nodeToFile(sessionMock, pJcrConstMock, pathConversionHelper, lockHelperMock, nodeMock)).thenReturn(fileMock);
    when(JcrRepositoryFileUtils.isSupportedNodeType(pJcrConstMock, nodeMock)).thenReturn(true);
    when(JcrRepositoryFileAclUtils.getAcl(sessionMock, pJcrConstMock, 1)).thenThrow(new AccessDeniedException());
    try {
        JcrRepositoryFileUtils.checkNodeForTree(nodeMock, children, sessionMock, pJcrConstMock, pathConversionHelper, "childNodeFilter", lockHelperMock, 0, false, repositoryAccessVoterManagerMock, RepositoryRequest.FILES_TYPE_FILTER.FOLDERS, foundFiltered, true, false, "/");
    } catch (Exception e) {
        fail();
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) ArrayList(java.util.ArrayList) IRepositoryAccessVoterManager(org.pentaho.platform.api.repository2.unified.IRepositoryAccessVoterManager) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) AccessDeniedException(javax.jcr.AccessDeniedException) RepositoryException(javax.jcr.RepositoryException) ExpectedException(org.junit.rules.ExpectedException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

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