Search in sources :

Example 1 with SearchContext

use of org.alfresco.jlan.server.filesys.SearchContext in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testDirListing.

// testScenarioMetadataExtractionForMac
public void testDirListing() throws Exception {
    logger.debug("testDirListing");
    ServerConfiguration scfg = new ServerConfiguration("testServer");
    TestServer testServer = new TestServer("testServer", scfg);
    SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
    DiskSharedDevice share = getDiskSharedDevice();
    TreeConnection testConnection = testServer.getTreeConnection(share);
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    final String FOLDER_NAME = "parentFolder" + System.currentTimeMillis();
    final String HIDDEN_FOLDER_NAME = "hiddenFolder" + System.currentTimeMillis();
    RetryingTransactionCallback<NodeRef> createNodesCB = new RetryingTransactionCallback<NodeRef>() {

        @Override
        public NodeRef execute() throws Throwable {
            NodeRef companyHome = repositoryHelper.getCompanyHome();
            NodeRef parentNode = nodeService.createNode(companyHome, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, FOLDER_NAME), ContentModel.TYPE_FOLDER).getChildRef();
            nodeService.setProperty(parentNode, ContentModel.PROP_NAME, FOLDER_NAME);
            NodeRef hiddenNode = nodeService.createNode(parentNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, HIDDEN_FOLDER_NAME), ForumModel.TYPE_FORUM).getChildRef();
            nodeService.setProperty(hiddenNode, ContentModel.PROP_NAME, HIDDEN_FOLDER_NAME);
            return parentNode;
        }
    };
    final NodeRef parentFolder = tran.doInTransaction(createNodesCB);
    List<String> excludedTypes = new ArrayList<String>();
    excludedTypes.add(ForumModel.TYPE_FORUM.toString());
    cifsHelper.setExcludedTypes(excludedTypes);
    SearchContext result = driver.startSearch(testSession, testConnection, "\\" + FOLDER_NAME + "\\*", 0);
    while (result.hasMoreFiles()) {
        if (result.nextFileName().equals(HIDDEN_FOLDER_NAME)) {
            fail("Exluded types mustn't be shown in cifs");
        }
    }
    RetryingTransactionCallback<Void> deleteNodeCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            nodeService.deleteNode(parentFolder);
            return null;
        }
    };
    tran.doInTransaction(deleteNodeCB, false, true);
}
Also used : SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) ArrayList(java.util.ArrayList) SearchContext(org.alfresco.jlan.server.filesys.SearchContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 2 with SearchContext

use of org.alfresco.jlan.server.filesys.SearchContext in project alfresco-repository by Alfresco.

the class LegacyFileStateDriver method startSearch.

@Override
public SearchContext startSearch(SrvSession sess, TreeConnection tree, String searchPath, int attrib) throws FileNotFoundException {
    InFlightCorrector t = new InFlightCorrectorImpl(tree);
    SearchContext ctx = diskInterface.startSearch(sess, tree, searchPath, attrib);
    if (ctx instanceof InFlightCorrectable) {
        InFlightCorrectable thingable = (InFlightCorrectable) ctx;
        thingable.setInFlightCorrector(t);
    }
    return ctx;
}
Also used : SearchContext(org.alfresco.jlan.server.filesys.SearchContext)

Example 3 with SearchContext

use of org.alfresco.jlan.server.filesys.SearchContext in project alfresco-repository by Alfresco.

the class ContentDiskDriver method startSearch.

/**
 * Start a new search on the filesystem using the specified searchPath that may contain
 * wildcards.
 *
 * @param sess Server session
 * @param tree Tree connection
 * @param searchPath File(s) to search for, may include wildcards.
 * @param attributes Attributes of the file(s) to search for, see class SMBFileAttribute.
 * @return SearchContext
 * @exception java.io.FileNotFoundException If the search could not be started.
 */
public SearchContext startSearch(SrvSession sess, TreeConnection tree, String searchPath, int attributes) throws FileNotFoundException {
    // Access the device context
    if (logger.isDebugEnabled()) {
        logger.debug("startSearch: " + searchPath);
    }
    ContentContext ctx = (ContentContext) tree.getContext();
    try {
        String searchFileSpec = searchPath;
        NodeRef searchRootNodeRef = ctx.getRootNode();
        FileState searchFolderState = null;
        // Create the transaction
        beginReadTransaction(sess);
        // If the state table is available see if we can speed up the search using either cached
        // file information or find the folder node to be searched without having to walk the path
        String[] paths = FileName.splitPath(searchPath);
        if (ctx.hasStateCache()) {
            if (paths[0] != null && paths[0].length() >= 1) {
                // Find the node ref for the folder being searched
                NodeRef nodeRef = getNodeForPath(tree, paths[0]);
                // Get the file state for the folder being searched
                searchFolderState = getStateForPath(tree, paths[0]);
                if (searchFolderState == null) {
                    // Create a file state for the folder
                    searchFolderState = ctx.getStateCache().findFileState(paths[0], true);
                }
                if (searchFolderState.hasFilesystemObject() == false) {
                    // Set the associated node for the folder
                    searchFolderState.setFilesystemObject(nodeRef);
                }
                if (nodeRef != null) {
                    searchRootNodeRef = nodeRef;
                    searchFileSpec = paths[1];
                    if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_SEARCH))
                        logger.debug("Search using cached noderef for path " + searchPath);
                }
            }
        }
        if (searchFileSpec.equals("*.*"))
            searchFileSpec = "*";
        // Debug
        long startTime = 0L;
        if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_SEARCH))
            startTime = System.currentTimeMillis();
        // Perform the search
        List<NodeRef> results = cifsHelper.getNodeRefs(searchRootNodeRef, searchFileSpec);
        if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_SEARCH)) {
            long endTime = System.currentTimeMillis();
            if ((endTime - startTime) > 500)
                logger.debug("Search for searchPath=" + searchPath + ", searchSpec=" + searchFileSpec + ", searchRootNode=" + searchRootNodeRef + " took " + (endTime - startTime) + "ms results=" + results.size());
        }
        // Build the search context to store the results, use the cache lookup search for wildcard searches
        SearchContext searchCtx = null;
        if (searchFileSpec.equals("*")) {
            // Use a cache lookup search context
            CacheLookupSearchContext cacheContext = new CacheLookupSearchContext(cifsHelper, results, searchFileSpec, paths[0], ctx.getStateCache(), isLockedFilesAsOffline);
            searchCtx = cacheContext;
            if (searchFolderState != null && searchFolderState.hasFilesystemObject()) {
                // Get the '.' pseudo entry file details
                FileInfo finfo = cifsHelper.getFileInformation((NodeRef) searchFolderState.getFilesystemObject(), isReadOnly, isLockedFilesAsOffline);
                if (searchFolderState != null) {
                    if (searchFolderState.hasAccessDateTime())
                        finfo.setAccessDateTime(searchFolderState.getAccessDateTime());
                    if (searchFolderState.hasChangeDateTime())
                        finfo.setChangeDateTime(searchFolderState.getChangeDateTime());
                    if (searchFolderState.hasModifyDateTime())
                        finfo.setModifyDateTime(searchFolderState.getModifyDateTime());
                }
                // Set the '.' pseudo entry details
                cacheContext.setDotInfo(finfo);
                if (searchFolderState.getPath().equals(FileName.DOS_SEPERATOR_STR)) {
                    // Searching the root folder, re-use the search folder file information for the '..' pseudo entry
                    FileInfo dotDotInfo = new FileInfo();
                    dotDotInfo.copyFrom(finfo);
                    cacheContext.setDotDotInfo(dotDotInfo);
                } else {
                    // Get the parent folder path
                    String parentPath = searchFolderState.getPath();
                    if (parentPath.endsWith(FileName.DOS_SEPERATOR_STR) && parentPath.length() > 1)
                        parentPath = parentPath.substring(0, parentPath.length() - 1);
                    int pos = parentPath.lastIndexOf(FileName.DOS_SEPERATOR_STR);
                    if (pos != -1)
                        parentPath = parentPath.substring(0, pos + 1);
                    // Get the file state for the parent path, if available
                    FileState parentState = ctx.getStateCache().findFileState(parentPath);
                    NodeRef parentNode = null;
                    if (parentState != null)
                        parentNode = (NodeRef) parentState.getFilesystemObject();
                    if (parentState == null || parentNode == null)
                        parentNode = getNodeForPath(tree, parentPath);
                    // Get the file information for the parent folder
                    finfo = cifsHelper.getFileInformation(parentNode, isReadOnly, isLockedFilesAsOffline);
                    if (parentState != null) {
                        if (parentState.hasAccessDateTime())
                            finfo.setAccessDateTime(parentState.getAccessDateTime());
                        if (parentState.hasChangeDateTime())
                            finfo.setChangeDateTime(parentState.getChangeDateTime());
                        if (parentState.hasModifyDateTime())
                            finfo.setModifyDateTime(parentState.getModifyDateTime());
                    }
                    // Set the '..' pseudo entry details
                    cacheContext.setDotDotInfo(finfo);
                }
            }
        } else {
            if (ctx.hasStateCache())
                searchCtx = new CacheLookupSearchContext(cifsHelper, results, searchFileSpec, paths[0], ctx.getStateCache(), isLockedFilesAsOffline);
            else
                searchCtx = new ContentSearchContext(cifsHelper, results, searchFileSpec, paths[0], isLockedFilesAsOffline);
        }
        if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_SEARCH))
            logger.debug("Started search: search path=" + searchPath + " attributes=" + attributes + ", ctx=" + searchCtx);
        return searchCtx;
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
        if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_SEARCH))
            logger.debug("Start search - access denied, " + searchPath);
        throw new FileNotFoundException("Start search " + searchPath);
    } catch (RuntimeException ex) {
        if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_SEARCH))
            logger.debug("Start search", ex);
        throw new FileNotFoundException("Start search " + searchPath);
    }
}
Also used : FileState(org.alfresco.jlan.server.filesys.cache.FileState) FileNotFoundException(java.io.FileNotFoundException) SearchContext(org.alfresco.jlan.server.filesys.SearchContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) FileInfo(org.alfresco.jlan.server.filesys.FileInfo)

Aggregations

SearchContext (org.alfresco.jlan.server.filesys.SearchContext)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 SrvSession (org.alfresco.jlan.server.SrvSession)1 ServerConfiguration (org.alfresco.jlan.server.config.ServerConfiguration)1 DiskSharedDevice (org.alfresco.jlan.server.filesys.DiskSharedDevice)1 FileInfo (org.alfresco.jlan.server.filesys.FileInfo)1 TreeConnection (org.alfresco.jlan.server.filesys.TreeConnection)1 FileState (org.alfresco.jlan.server.filesys.cache.FileState)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)1