Search in sources :

Example 91 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.

the class BCCourseNodeIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext repositoryResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    if (isLogDebugEnabled())
        logDebug("Index Briefcase...");
    BCCourseNode bcNode = (BCCourseNode) courseNode;
    SearchResourceContext courseNodeResourceContext = createSearchResourceContext(repositoryResourceContext, bcNode, TYPE);
    Document document = CourseNodeDocument.createDocument(courseNodeResourceContext, bcNode);
    indexWriter.addDocument(document);
    VFSContainer bcContainer = null;
    if (bcNode.getModuleConfiguration().getBooleanSafe(BCCourseNodeEditController.CONFIG_AUTO_FOLDER)) {
        bcContainer = BCCourseNode.getNodeFolderContainer(bcNode, course.getCourseEnvironment());
    } else {
        String subpath = courseNode.getModuleConfiguration().getStringValue(BCCourseNodeEditController.CONFIG_SUBPATH);
        if (subpath != null) {
            VFSItem item = course.getCourseEnvironment().getCourseFolderContainer().resolve(subpath);
            if (item instanceof VFSContainer) {
                bcContainer = new NamedContainerImpl(courseNode.getShortTitle(), (VFSContainer) item);
            }
        }
    }
    if (bcContainer != null) {
        doIndexVFSContainer(courseNodeResourceContext, bcContainer, indexWriter, "", FolderIndexerAccess.FULL_ACCESS);
    }
}
Also used : BCCourseNode(org.olat.course.nodes.BCCourseNode) SearchResourceContext(org.olat.search.service.SearchResourceContext) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.apache.lucene.document.Document) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl)

Example 92 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.

the class SPCourseNodeIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext courseResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    if (log.isDebug())
        log.debug("Index SinglePage...");
    SearchResourceContext courseNodeResourceContext = createSearchResourceContext(courseResourceContext, courseNode, TYPE);
    Document nodeDocument = CourseNodeDocument.createDocument(courseNodeResourceContext, courseNode);
    indexWriter.addDocument(nodeDocument);
    // The root of the configured single page. Depends on the configuration
    // whether to follow relative links or not. When relative links are
    // followed, the root is the course folder root, if not, it is folder
    // where the configured file is in
    VFSContainer rootContainer;
    // The filename of the configured file relative to the rootContainer
    String chosenFile;
    // Read the course node configuration
    VFSContainer courseFolderContainer = course.getCourseEnvironment().getCourseFolderContainer();
    boolean allowRelativeLinks = courseNode.getModuleConfiguration().getBooleanSafe(SPEditController.CONFIG_KEY_ALLOW_RELATIVE_LINKS);
    String fileName = (String) courseNode.getModuleConfiguration().get(SPEditController.CONFIG_KEY_FILE);
    // *** IF YOU CHANGE THIS LOGIC, do also change it in SinglePageController! ***
    if (allowRelativeLinks) {
        // Case 1: relative links are allowed. The root is the root of the
        // course, the file name is relative to the root
        rootContainer = courseFolderContainer;
        chosenFile = fileName;
    } else {
        // Case 2: relative links are NOT allowed. We have to calculate the
        // new root and remove the relative path to the course folder form
        // the file.
        String startURI = ((fileName.charAt(0) == '/') ? fileName.substring(1) : fileName);
        int sla = startURI.lastIndexOf('/');
        if (sla != -1) {
            // Some subfolder path is detected, create basecontainer from it
            String root = startURI.substring(0, sla);
            startURI = startURI.substring(sla + 1);
            // Create new root folder from the relative folder path
            VFSContainer newroot = (VFSContainer) courseFolderContainer.resolve(root);
            newroot.setParentContainer(null);
            rootContainer = newroot;
        } else {
            // No subpath detected, just use course base container
            rootContainer = courseFolderContainer;
        }
        chosenFile = startURI;
    }
    VFSLeaf leaf = (VFSLeaf) rootContainer.resolve(chosenFile);
    if (leaf != null) {
        String filePath = getPathFor(leaf);
        // Use inherited method from LeafIndexer for the actual indexing of the content
        SearchResourceContext fileContext = new SearchResourceContext(courseNodeResourceContext);
        doIndexVFSLeafByMySelf(fileContext, leaf, indexWriter, filePath);
        if (!indexOnlyChosenFile) {
            if (log.isDebug())
                log.debug("Index sub pages in SP.");
            Set<String> alreadyIndexFileNames = new HashSet<String>();
            alreadyIndexFileNames.add(chosenFile);
            // Check if page has links to subpages and index those as well
            indexSubPages(courseNodeResourceContext, rootContainer, indexWriter, leaf, alreadyIndexFileNames, 0, filePath);
        } else if (log.isDebug()) {
            log.debug("Index only chosen file in SP.");
        }
    } else if (log.isDebug()) {
        log.debug("Can not found choosen file in SP => Nothing indexed.");
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) SearchResourceContext(org.olat.search.service.SearchResourceContext) VFSContainer(org.olat.core.util.vfs.VFSContainer) Document(org.apache.lucene.document.Document) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument) HashSet(java.util.HashSet)

Example 93 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.

the class DialogCourseNodeIndexer method doIndexFile.

/**
 * Index a file of dialog-module.
 * @param filename
 * @param forumKey
 * @param leafResourceContext
 * @param indexWriter
 * @throws IOException
 * @throws InterruptedException
 */
private void doIndexFile(DialogElement element, SearchResourceContext leafResourceContext, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    DialogElementsManager dialogElmsMgr = CoreSpringFactory.getImpl(DialogElementsManager.class);
    VFSContainer dialogContainer = dialogElmsMgr.getDialogContainer(element);
    VFSLeaf leaf = (VFSLeaf) dialogContainer.getItems(new VFSLeafFilter()).get(0);
    if (isLogDebugEnabled())
        logDebug("Analyse VFSLeaf=" + leaf.getName());
    try {
        if (CoreSpringFactory.getImpl(FileDocumentFactory.class).isFileSupported(leaf)) {
            leafResourceContext.setFilePath(element.getFilename());
            leafResourceContext.setDocumentType(TYPE_FILE);
            Document document = CoreSpringFactory.getImpl(FileDocumentFactory.class).createDocument(leafResourceContext, leaf);
            indexWriter.addDocument(document);
        } else {
            if (isLogDebugEnabled())
                logDebug("Documenttype not supported. file=" + leaf.getName());
        }
    } catch (DocumentAccessException e) {
        if (isLogDebugEnabled())
            logDebug("Can not access document." + e.getMessage());
    } catch (IOException ioEx) {
        logWarn("IOException: Can not index leaf=" + leaf.getName(), ioEx);
    } catch (InterruptedException iex) {
        throw new InterruptedException(iex.getMessage());
    } catch (Exception ex) {
        logWarn("Exception: Can not index leaf=" + leaf.getName(), ex);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) IOException(java.io.IOException) DialogElementsManager(org.olat.course.nodes.dialog.DialogElementsManager) Document(org.apache.lucene.document.Document) ForumMessageDocument(org.olat.search.service.document.ForumMessageDocument) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument) FileDocumentFactory(org.olat.search.service.document.file.FileDocumentFactory) IOException(java.io.IOException) DocumentAccessException(org.olat.search.service.document.file.DocumentAccessException) VFSLeafFilter(org.olat.core.util.vfs.filters.VFSLeafFilter) DocumentAccessException(org.olat.search.service.document.file.DocumentAccessException)

Example 94 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.

the class ImsCPRepositoryIndexer method doIndex.

/**
 * @see org.olat.repository.handlers.RepositoryHandler#supportsDownload()
 */
@Override
public void doIndex(SearchResourceContext resourceContext, Object parentObject, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    RepositoryEntry repositoryEntry = (RepositoryEntry) parentObject;
    if (isLogDebugEnabled())
        logDebug("Analyse IMS CP RepositoryEntry...");
    resourceContext.setDocumentType(TYPE);
    if (repositoryEntry != null) {
        File cpRoot = FileResourceManager.getInstance().unzipFileResource(repositoryEntry.getOlatResource());
        if (cpRoot != null) {
            SearchResourceContext cpContext = new SearchResourceContext(resourceContext);
            VFSContainer rootContainer = new LocalFolderImpl(cpRoot);
            doIndexVFSContainer(cpContext, rootContainer, indexWriter, "", FolderIndexerAccess.FULL_ACCESS);
        }
    }
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) VFSContainer(org.olat.core.util.vfs.VFSContainer) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 95 with VFSContainer

use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.

the class SharedFolderRepositoryIndexer method doIndex.

/**
 * @see org.olat.repository.handlers.RepositoryHandler#supportsDownload()
 */
@Override
public void doIndex(SearchResourceContext resourceContext, Object parentObject, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    RepositoryEntry repositoryEntry = (RepositoryEntry) parentObject;
    if (isLogDebugEnabled())
        logDebug("Analyse Shared Folder RepositoryEntry...");
    resourceContext.setDocumentType(TYPE);
    VFSContainer sfContainer = SharedFolderManager.getInstance().getSharedFolder(repositoryEntry.getOlatResource());
    // only index if no lockfile found. see OLAT-5724
    if (sfContainer != null && sfContainer.resolve(NO_FOLDER_INDEXING_LOCKFILE) == null) {
        SearchResourceContext folderContext = new SearchResourceContext(resourceContext);
        doIndexVFSContainer(folderContext, sfContainer, indexWriter, "", FolderIndexerAccess.FULL_ACCESS);
    }
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) VFSContainer(org.olat.core.util.vfs.VFSContainer) RepositoryEntry(org.olat.repository.RepositoryEntry)

Aggregations

VFSContainer (org.olat.core.util.vfs.VFSContainer)962 VFSItem (org.olat.core.util.vfs.VFSItem)364 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)338 File (java.io.File)170 Test (org.junit.Test)136 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)86 Identity (org.olat.core.id.Identity)86 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)76 RepositoryEntry (org.olat.repository.RepositoryEntry)76 IOException (java.io.IOException)74 InputStream (java.io.InputStream)64 ArrayList (java.util.ArrayList)64 Date (java.util.Date)60 URI (java.net.URI)56 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)42 OutputStream (java.io.OutputStream)40 HttpResponse (org.apache.http.HttpResponse)38 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)34 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)34 BlogFileResource (org.olat.fileresource.types.BlogFileResource)34