Search in sources :

Example 31 with VFSLeaf

use of org.olat.core.util.vfs.VFSLeaf 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 32 with VFSLeaf

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

the class BulkAssessmentTask method processReturnFile.

private void processReturnFile(AssessableCourseNode courseNode, BulkAssessmentRow row, UserCourseEnvironment uce, File assessedFolder) {
    String assessedId = row.getAssessedId();
    Identity identity = uce.getIdentityEnvironment().getIdentity();
    VFSContainer returnBox = getReturnBox(uce, courseNode, identity);
    if (returnBox != null) {
        for (String returnFilename : row.getReturnFiles()) {
            File returnFile = new File(assessedFolder, returnFilename);
            VFSItem currentReturnLeaf = returnBox.resolve(returnFilename);
            if (currentReturnLeaf != null) {
                // remove the current file (delete make a version if it is enabled)
                currentReturnLeaf.delete();
            }
            VFSLeaf returnLeaf = returnBox.createChildLeaf(returnFilename);
            if (returnFile.exists()) {
                try {
                    InputStream inStream = new FileInputStream(returnFile);
                    VFSManager.copyContent(inStream, returnLeaf);
                } catch (FileNotFoundException e) {
                    log.error("Cannot copy return file " + returnFilename + " from " + assessedId, e);
                }
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) FileNotFoundException(java.io.FileNotFoundException) VFSItem(org.olat.core.util.vfs.VFSItem) Identity(org.olat.core.id.Identity) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 33 with VFSLeaf

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

the class CertificatesManagerImpl method addPdfTemplate.

private boolean addPdfTemplate(String name, File file, CertificateTemplateImpl template) {
    String dir = templatesStorage.generateDir();
    VFSContainer templateDir = templatesStorage.getContainer(dir);
    VFSLeaf templateLeaf;
    String renamedName = VFSManager.rename(templateDir, name);
    if (renamedName != null) {
        templateLeaf = templateDir.createChildLeaf(renamedName);
    } else {
        templateLeaf = templateDir.createChildLeaf(name);
    }
    try (InputStream inStream = Files.newInputStream(file.toPath())) {
        if (VFSManager.copyContent(inStream, templateLeaf)) {
            template.setName(name);
            template.setPath(dir + templateLeaf.getName());
            return true;
        }
    } catch (IOException ex) {
        log.error("", ex);
    }
    return false;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) IOException(java.io.IOException)

Example 34 with VFSLeaf

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

the class CertificationWebService method getCertificateInfo.

@HEAD
@Path("{identityKey}")
@Produces({ "application/pdf" })
public Response getCertificateInfo(@PathParam("identityKey") Long identityKey, @PathParam("resourceKey") Long resourceKey, @Context HttpServletRequest request) {
    if (!isAdmin(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    CertificatesManager certificatesManager = CoreSpringFactory.getImpl(CertificatesManager.class);
    BaseSecurity baseSecurity = CoreSpringFactory.getImpl(BaseSecurity.class);
    Identity identity = baseSecurity.loadIdentityByKey(identityKey);
    if (identity == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    OLATResourceable courseOres = OresHelper.createOLATResourceableInstance("CourseModule", resourceKey);
    OLATResourceManager resourceManager = CoreSpringFactory.getImpl(OLATResourceManager.class);
    OLATResource resource = resourceManager.findResourceable(courseOres);
    if (resource == null) {
        resource = resourceManager.findResourceById(resourceKey);
    }
    if (resource == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    Certificate certificate = certificatesManager.getLastCertificate(identity, resource.getKey());
    if (certificate == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    VFSLeaf certificateFile = certificatesManager.getCertificateLeaf(certificate);
    if (certificateFile == null || !certificateFile.exists()) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    return Response.ok().build();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OLATResourceable(org.olat.core.id.OLATResourceable) CertificatesManager(org.olat.course.certificate.CertificatesManager) OLATResourceManager(org.olat.resource.OLATResourceManager) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity) Certificate(org.olat.course.certificate.Certificate) Path(javax.ws.rs.Path) HEAD(javax.ws.rs.HEAD) Produces(javax.ws.rs.Produces)

Example 35 with VFSLeaf

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

the class CollaborationTools method archiveWiki.

private void archiveWiki(String archivFilePath) {
    VFSContainer wikiContainer = WikiManager.getInstance().getWikiRootContainer(ores);
    VFSLeaf wikiZip = WikiToZipUtils.getWikiAsZip(wikiContainer);
    String exportFileName = "del_wiki_" + ores.getResourceableId() + ".zip";
    File archiveDir = new File(archivFilePath);
    if (!archiveDir.exists()) {
        archiveDir.mkdir();
    }
    String fullFilePath = archivFilePath + File.separator + exportFileName;
    try {
        FileUtils.bcopy(wikiZip.getInputStream(), new File(fullFilePath), "archive wiki");
    } catch (FileNotFoundException e) {
        log.warn("Can not archive wiki repoEntry=" + ores.getResourceableId());
    } catch (IOException ioe) {
        log.warn("Can not archive wiki repoEntry=" + ores.getResourceableId());
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File)

Aggregations

VFSLeaf (org.olat.core.util.vfs.VFSLeaf)642 VFSContainer (org.olat.core.util.vfs.VFSContainer)338 VFSItem (org.olat.core.util.vfs.VFSItem)280 File (java.io.File)114 InputStream (java.io.InputStream)96 IOException (java.io.IOException)92 Test (org.junit.Test)86 ArrayList (java.util.ArrayList)72 OutputStream (java.io.OutputStream)60 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)58 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)58 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)58 Identity (org.olat.core.id.Identity)54 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)52 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)46 URL (java.net.URL)40 Date (java.util.Date)40 RepositoryEntry (org.olat.repository.RepositoryEntry)36 URI (java.net.URI)34 MediaResource (org.olat.core.gui.media.MediaResource)34