Search in sources :

Example 11 with RepositoryFileTree

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

the class MockUnifiedRepository method getTree.

@Override
public RepositoryFileTree getTree(final String path, final int depth, final String filter, final boolean showHidden) {
    FileRecord r = root.getFileRecord(path);
    RepositoryFile rootFile = r.getFile();
    if ((!showHidden && rootFile.isHidden()) || rootFile.isAclNode()) {
        return null;
    }
    List<RepositoryFileTree> children;
    if (depth != 0) {
        children = new ArrayList<RepositoryFileTree>();
        if (rootFile.isFolder()) {
            List<RepositoryFile> childrenTmp = getChildren(rootFile.getId(), filter);
            for (RepositoryFile child : childrenTmp) {
                RepositoryFileTree repositoryFileTree = getTree(child.getPath(), depth - 1, filter, showHidden);
                if (repositoryFileTree != null) {
                    children.add(repositoryFileTree);
                }
            }
        }
        Collections.sort(children);
    } else {
        children = null;
    }
    return new RepositoryFileTree(rootFile, children);
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 12 with RepositoryFileTree

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

the class JcrRepositoryFileDao method getTree.

/**
 * {@inheritDoc}
 */
@Override
@Deprecated
public RepositoryFileTree getTree(final String relPath, final int depth, final String filter, final boolean showHidden) {
    Assert.hasText(relPath);
    final RepositoryRequest repositoryRequest = new RepositoryRequest(relPath, showHidden, depth, filter);
    return (RepositoryFileTree) jcrTemplate.execute(new JcrCallback() {

        @Override
        public Object doInJcr(final Session session) throws RepositoryException, IOException {
            PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
            String absPath = pathConversionHelper.relToAbs(relPath);
            return JcrRepositoryFileUtils.getTree(session, pentahoJcrConstants, pathConversionHelper, lockHelper, absPath, repositoryRequest, accessVoterManager);
        }
    });
}
Also used : RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) JcrCallback(org.springframework.extensions.jcr.JcrCallback) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) Session(javax.jcr.Session)

Example 13 with RepositoryFileTree

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

the class JcrRepositoryFileUtils method checkNodeForTree.

/**
 * This method is called twice by <code>getTreeNode</code>. It's job is to determine whether the current child node
 * should be added to the list of children for the node being processed. It is a separate method simply because it is
 * too much code to appear twice in the above <code>getTreeNode</code> method. It also makes the recursive call back
 * to getTreeByNode to process the next lower level of folder node (it must process the lower levels to know if the
 * folder should be added). Finally, it returns the foundFiltered boolean to let the caller know if a file was found
 * that satisfied the childNodeFilter.
 */
static void checkNodeForTree(final Node childNode, List<RepositoryFileTree> children, final Session session, final PentahoJcrConstants pentahoJcrConstants, final IPathConversionHelper pathConversionHelper, final String childNodeFilter, final ILockHelper lockHelper, final int depth, final boolean showHidden, final IRepositoryAccessVoterManager accessVoterManager, RepositoryRequest.FILES_TYPE_FILTER types, MutableBoolean foundFiltered, boolean isRootFiltered, final boolean includeSystemFolders, final String rootPath) throws RepositoryException {
    RepositoryFile file = nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper, childNode);
    if (isSupportedNodeType(pentahoJcrConstants, childNode)) {
        RepositoryFileAcl fileAcl;
        try {
            fileAcl = JcrRepositoryFileAclUtils.getAcl(session, pentahoJcrConstants, file.getId());
        } catch (AccessDeniedException e) {
            return;
        }
        if (accessVoterManager.hasAccess(file, RepositoryFilePermission.READ, fileAcl, PentahoSessionHolder.getSession())) {
            MutableBoolean foundFilteredAtomic = new MutableBoolean(!isPentahoFolder(pentahoJcrConstants, childNode));
            RepositoryFileTree repositoryFileTree = getTreeByNode(session, pentahoJcrConstants, pathConversionHelper, lockHelper, childNode, depth - 1, childNodeFilter, showHidden, accessVoterManager, types, foundFilteredAtomic, includeSystemFolders, rootPath);
            if (repositoryFileTree != null && (foundFilteredAtomic.booleanValue() || isRootFiltered)) {
                foundFiltered.setValue(true);
                children.add(repositoryFileTree);
            }
        }
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 14 with RepositoryFileTree

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

the class GeneratedContentCleaner method execute.

/*
   * This method performs the actual work of the GeneratedContentCleaner by calling deleteFile with 'true' passed down
   * for the 'permanent' flag.
   * 
   * (non-Javadoc)
   * 
   * @see org.pentaho.platform.api.action.IAction#execute()
   */
public void execute() throws Exception {
    // scan the repository for all files with a RESERVEDMAPKEY_LINEAGE_ID
    // we need to find and delete hidden generated files too (like .css and .png)
    RepositoryFileTree tree = repository.getTree(ClientRepositoryPaths.getRootFolderPath(), -1, null, true);
    ArrayList<RepositoryFile> generatedContentList = new ArrayList<RepositoryFile>();
    findGeneratedContent(generatedContentList, tree);
    for (RepositoryFile deleteMe : generatedContentList) {
        repository.deleteFile(deleteMe.getId(), true, GeneratedContentCleaner.class.getName());
        logger.info("GeneratedContentCleaner deleting: " + deleteMe.getPath());
    }
}
Also used : ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 15 with RepositoryFileTree

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

the class RepositoryFileTreeAdapter method unmarshal.

@Override
public RepositoryFileTree unmarshal(final RepositoryFileTreeDto v) {
    List<RepositoryFileTree> children = null;
    if (v.children != null) {
        children = new ArrayList<RepositoryFileTree>();
        for (RepositoryFileTreeDto child : v.children) {
            children.add(unmarshal(child));
        }
    }
    RepositoryFileTree repositoryFileTree = new RepositoryFileTree(RepositoryFileAdapter.toFile(v.file), children);
    if (v.file.getVersioningEnabled() != null) {
        repositoryFileTree.setVersioningEnabled(v.file.getVersioningEnabled());
    }
    if (v.file.getVersionCommentEnabled() != null) {
        repositoryFileTree.setVersionCommentEnabled(v.file.getVersionCommentEnabled());
    }
    return repositoryFileTree;
}
Also used : 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