Search in sources :

Example 26 with SystemItemFilter

use of org.olat.core.util.vfs.filters.SystemItemFilter in project openolat by klemens.

the class BCCourseNode method createPeekViewRunController.

/**
 * @see org.olat.course.nodes.GenericCourseNode#createPeekViewRunController(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.WindowControl,
 *      org.olat.course.run.userview.UserCourseEnvironment,
 *      org.olat.course.run.userview.NodeEvaluation)
 */
@Override
public Controller createPeekViewRunController(UserRequest ureq, WindowControl wControl, UserCourseEnvironment userCourseEnv, NodeEvaluation ne) {
    if (ne.isAtLeastOneAccessible()) {
        updateModuleConfigDefaults(false);
        // Create a folder peekview controller that shows the latest two entries
        VFSContainer rootFolder = null;
        if (getModuleConfiguration().getBooleanSafe(BCCourseNodeEditController.CONFIG_AUTO_FOLDER)) {
            rootFolder = getNodeFolderContainer(this, userCourseEnv.getCourseEnvironment());
        } else {
            String subPath = getModuleConfiguration().getStringValue(BCCourseNodeEditController.CONFIG_SUBPATH, "");
            VFSItem item = userCourseEnv.getCourseEnvironment().getCourseFolderContainer().resolve(subPath);
            if (item instanceof VFSContainer) {
                rootFolder = (VFSContainer) item;
            }
        }
        if (rootFolder == null) {
            return super.createPeekViewRunController(ureq, wControl, userCourseEnv, ne);
        }
        rootFolder.setDefaultItemFilter(new SystemItemFilter());
        return new BCPeekviewController(ureq, wControl, rootFolder, getIdent(), 4);
    } else {
        // use standard peekview
        return super.createPeekViewRunController(ureq, wControl, userCourseEnv, ne);
    }
}
Also used : BCPeekviewController(org.olat.course.nodes.bc.BCPeekviewController) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter)

Example 27 with SystemItemFilter

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

the class SharedFolderWebService method getFiles.

public Response getFiles(Long repoEntryKey, List<PathSegment> path, UriInfo uriInfo, HttpServletRequest httpRequest, Request request) {
    RepositoryEntry re = repositoryManager.lookupRepositoryEntry(repoEntryKey);
    if (re == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    VFSContainer container = SharedFolderManager.getInstance().getNamedSharedFolder(re, true);
    if (container == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    if (!repositoryManager.isAllowedToLaunch(RestSecurityHelper.getIdentity(httpRequest), RestSecurityHelper.getRoles(httpRequest), re)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    VFSLeaf leaf = null;
    for (PathSegment seg : path) {
        VFSItem item = container.resolve(seg.getPath());
        if (item instanceof VFSLeaf) {
            leaf = (VFSLeaf) item;
            break;
        } else if (item instanceof VFSContainer) {
            container = (VFSContainer) item;
        }
    }
    if (leaf != null) {
        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();
    }
    List<VFSItem> items = container.getItems(new SystemItemFilter());
    int count = 0;
    LinkVO[] links = new LinkVO[items.size()];
    for (VFSItem item : items) {
        UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
        UriBuilder repoUri = baseUriBuilder.path(SharedFolderWebService.class).path(repoEntryKey.toString()).path("files");
        for (PathSegment pathSegment : path) {
            repoUri.path(pathSegment.getPath());
        }
        String uri = repoUri.path(item.getName()).build().toString();
        links[count++] = new LinkVO("self", uri, item.getName());
    }
    return Response.ok(links).build();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) RepositoryEntry(org.olat.repository.RepositoryEntry) PathSegment(javax.ws.rs.core.PathSegment) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) Date(java.util.Date) Response(javax.ws.rs.core.Response) LinkVO(org.olat.restapi.support.vo.LinkVO) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 28 with SystemItemFilter

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

the class ForumWebService method getAttachments.

private FileVO[] getAttachments(Message mess, UriInfo uriInfo) {
    VFSContainer container = fom.getMessageContainer(mess.getForum().getKey(), mess.getKey());
    List<FileVO> attachments = new ArrayList<FileVO>();
    for (VFSItem item : container.getItems(new SystemItemFilter())) {
        UriBuilder attachmentUri = uriInfo.getBaseUriBuilder().path("repo").path("forums").path(mess.getForum().getKey().toString()).path("posts").path(mess.getKey().toString()).path("attachments").path(format(item.getName()));
        String uri = attachmentUri.build().toString();
        if (item instanceof VFSLeaf) {
            attachments.add(new FileVO("self", uri, item.getName(), ((VFSLeaf) item).getSize()));
        } else {
            attachments.add(new FileVO("self", uri, item.getName()));
        }
    }
    FileVO[] attachmentArr = new FileVO[attachments.size()];
    attachmentArr = attachments.toArray(attachmentArr);
    return attachmentArr;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) FileVO(org.olat.restapi.support.vo.FileVO) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 29 with SystemItemFilter

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

the class VersionsFileManager method countDirectories.

private int countDirectories(VFSContainer container) {
    // itself
    int count = 1;
    List<VFSItem> children = container.getItems(new SystemItemFilter());
    for (VFSItem child : children) {
        if (child instanceof VFSContainer) {
            count += countDirectories((VFSContainer) child);
        }
    }
    return count;
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter)

Example 30 with SystemItemFilter

use of org.olat.core.util.vfs.filters.SystemItemFilter in project openolat by klemens.

the class AssignmentEditController method persistUploadedFiles.

private void persistUploadedFiles() {
    if (tempUploadFolder == null)
        return;
    VFSContainer container = portfolioFileStorage.getAssignmentContainer(assignment);
    if (container != null) {
        List<VFSItem> tmpFList = tempUploadFolder.getItems(new SystemItemFilter());
        for (VFSItem file : tmpFList) {
            try {
                VFSLeaf leaf = (VFSLeaf) file;
                VFSLeaf storedFile = container.createChildLeaf(leaf.getName());
                FileUtils.bcopy(leaf.getInputStream(), storedFile.getOutputStream(false), "");
            } catch (Exception e) {
                logError("", e);
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter)

Aggregations

SystemItemFilter (org.olat.core.util.vfs.filters.SystemItemFilter)36 VFSItem (org.olat.core.util.vfs.VFSItem)34 VFSContainer (org.olat.core.util.vfs.VFSContainer)30 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)24 Date (java.util.Date)10 OutputStream (java.io.OutputStream)8 PathSegment (javax.ws.rs.core.PathSegment)8 UriBuilder (javax.ws.rs.core.UriBuilder)8 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 Response (javax.ws.rs.core.Response)6 Test (org.junit.Test)6 RepositoryEntry (org.olat.repository.RepositoryEntry)4 FileVO (org.olat.restapi.support.vo.FileVO)4 LinkVO (org.olat.restapi.support.vo.LinkVO)4 File (java.io.File)2 Collator (java.text.Collator)2 HashSet (java.util.HashSet)2