Search in sources :

Example 36 with VFSContainer

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

the class VFSWebservice method resolveFile.

protected VFSItem resolveFile(List<PathSegment> path) {
    VFSContainer directory = container;
    VFSItem resolvedItem = directory;
    boolean notFound = false;
    // remove trailing segment if a trailing / is used
    if (path.size() > 0 && !StringHelper.containsNonWhitespace(path.get(path.size() - 1).getPath())) {
        path = path.subList(0, path.size() - 1);
    }
    a_a: for (PathSegment seg : path) {
        String segPath = seg.getPath();
        for (VFSItem item : directory.getItems(new SystemItemFilter())) {
            if (normalize(item.getName()).equals(segPath)) {
                if (item instanceof VFSLeaf) {
                    if (path.get(path.size() - 1) == seg) {
                        resolvedItem = item;
                        break a_a;
                    }
                } else if (item instanceof VFSContainer) {
                    resolvedItem = directory = (VFSContainer) item;
                    continue a_a;
                }
            }
        }
        notFound = true;
    }
    if (notFound) {
        return null;
    }
    return resolvedItem;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) PathSegment(javax.ws.rs.core.PathSegment) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter)

Example 37 with VFSContainer

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

the class VFSWebservice method get.

protected Response get(List<PathSegment> path, UriInfo uriInfo, Request request) {
    VFSItem vItem = resolveFile(path);
    if (vItem == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    } else if (vItem instanceof VFSContainer) {
        VFSContainer directory = (VFSContainer) vItem;
        List<VFSItem> items = directory.getItems(new SystemItemFilter());
        int count = 0;
        FileVO[] links = new FileVO[items.size()];
        for (VFSItem item : items) {
            UriBuilder builder = uriInfo.getAbsolutePathBuilder();
            String uri = builder.path(normalize(item.getName())).build().toString();
            if (item instanceof VFSLeaf) {
                links[count++] = new FileVO("self", uri, item.getName(), ((VFSLeaf) item).getSize());
            } else {
                links[count++] = new FileVO("self", uri, item.getName());
            }
        }
        return Response.ok(links).build();
    } else if (vItem instanceof VFSLeaf) {
        VFSLeaf leaf = (VFSLeaf) vItem;
        Date lastModified = new Date(leaf.getLastModified());
        Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
        if (response == null) {
            String mimeType = WebappHelper.getMimeType(leaf.getName());
            if (mimeType == null) {
                mimeType = MediaType.APPLICATION_OCTET_STREAM;
            }
            response = Response.ok(leaf.getInputStream(), mimeType).lastModified(lastModified).cacheControl(cc);
        }
        return response.build();
    }
    return Response.serverError().status(Status.BAD_REQUEST).build();
}
Also used : Response(javax.ws.rs.core.Response) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) FileVO(org.olat.restapi.support.vo.FileVO) VFSItem(org.olat.core.util.vfs.VFSItem) List(java.util.List) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) UriBuilder(javax.ws.rs.core.UriBuilder) Date(java.util.Date)

Example 38 with VFSContainer

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

the class VFSWebservice method getFMetadata.

protected Response getFMetadata(List<PathSegment> path, UriInfo uriInfo) {
    VFSItem vItem = resolveFile(path);
    if (vItem == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    } else if (vItem instanceof VFSContainer) {
        return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
    } else if (vItem instanceof VFSLeaf) {
        VFSLeaf leaf = (VFSLeaf) vItem;
        UriBuilder builder = uriInfo.getAbsolutePathBuilder();
        String uri = builder.build().toString();
        String[] uriArray = uri.split("metadata/");
        uri = uriArray[0] + uriArray[1];
        FileMetadataVO metaVo = new FileMetadataVO(uri, leaf);
        return Response.ok(metaVo).build();
    }
    return Response.serverError().status(Status.BAD_REQUEST).build();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) FileMetadataVO(org.olat.restapi.support.vo.FileMetadataVO) VFSItem(org.olat.core.util.vfs.VFSItem) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 39 with VFSContainer

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

the class VFSWebservice method resolveContainer.

protected VFSContainer resolveContainer(List<PathSegment> path, boolean create) {
    VFSContainer directory = container;
    boolean notFound = false;
    // remove trailing segment if a trailing / is used
    if (path.size() > 0 && !StringHelper.containsNonWhitespace(path.get(path.size() - 1).getPath())) {
        path = path.subList(0, path.size() - 1);
    }
    a_a: for (PathSegment seg : path) {
        String segPath = seg.getPath();
        for (VFSItem item : directory.getItems(new SystemItemFilter())) {
            if (item instanceof VFSLeaf) {
            // 
            } else if (item instanceof VFSContainer && normalize(item.getName()).equals(segPath)) {
                directory = (VFSContainer) item;
                continue a_a;
            }
        }
        if (create) {
            directory = directory.createChildContainer(segPath);
        } else if (path.get(path.size() - 1) == seg) {
            break a_a;
        } else {
            notFound = true;
        }
    }
    if (notFound) {
        return null;
    }
    return directory;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) PathSegment(javax.ws.rs.core.PathSegment) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter)

Example 40 with VFSContainer

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

the class CoursefolderWebDAVMergeSource method appendCourses.

private void appendCourses(List<RepositoryEntry> courseEntries, boolean editor, List<VFSContainer> containers, boolean useTerms, Map<String, VFSContainer> terms, VirtualContainer noTermContainer, VirtualContainer finishedContainer, boolean prependReference, UniqueNames container) {
    // Add all found repo entries to merge source
    int count = 0;
    for (RepositoryEntry re : courseEntries) {
        if (container.isDuplicate(re)) {
            continue;
        }
        String displayName = re.getDisplayname();
        if (prependReference && StringHelper.containsNonWhitespace(re.getExternalRef())) {
            displayName = re.getExternalRef() + " " + displayName;
        }
        String courseTitle = RequestUtil.normalizeFilename(displayName);
        if (finishedContainer != null && re.getRepositoryEntryStatus().isClosed()) {
            String name = container.getFinishedUniqueName(courseTitle);
            NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(name, re, editor ? null : identityEnv);
            finishedContainer.getItems().add(cfContainer);
        } else if (useTerms) {
            RepositoryEntryLifecycle lc = re.getLifecycle();
            if (lc != null && !lc.isPrivateCycle()) {
                // when a semester term info is found, add it to corresponding term folder
                String termSoftKey = lc.getSoftKey();
                VFSContainer termContainer = terms.get(termSoftKey);
                if (termContainer == null) {
                    // folder for this semester term does not yet exist, create one and add to map
                    String normalizedKey = RequestUtil.normalizeFilename(termSoftKey);
                    termContainer = new VirtualContainer(normalizedKey);
                    terms.put(termSoftKey, termContainer);
                    addContainerToList(termContainer, containers);
                }
                String name = container.getTermUniqueName(termSoftKey, courseTitle);
                NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(name, re, editor ? null : identityEnv);
                termContainer.getItems().add(cfContainer);
            } else {
                // no semester term found, add to no-term folder
                String name = container.getNoTermUniqueName(courseTitle);
                NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(name, re, editor ? null : identityEnv);
                noTermContainer.getItems().add(cfContainer);
            }
        } else {
            String name = container.getContainersUniqueName(courseTitle);
            NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(name, re, editor ? null : identityEnv);
            addContainerToList(cfContainer, containers);
        }
        if (++count % 5 == 0) {
            DBFactory.getInstance().commitAndCloseSession();
        }
    }
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) VFSContainer(org.olat.core.util.vfs.VFSContainer) RepositoryEntry(org.olat.repository.RepositoryEntry) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl) VirtualContainer(org.olat.core.util.vfs.VirtualContainer)

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