Search in sources :

Example 21 with VFSLeaf

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

the class VersionsFileManager method pruneVersionHistory.

private void pruneVersionHistory(VFSContainer container, long maxHistoryLength, ProgressDelegate progress, int count) {
    List<VFSItem> children = container.getItems(new SystemItemFilter());
    for (VFSItem child : children) {
        if (child instanceof VFSContainer) {
            if (progress != null)
                progress.setActual(++count);
            pruneVersionHistory((VFSContainer) child, maxHistoryLength, progress, count);
        }
        if (child instanceof VFSLeaf) {
            VFSLeaf versionsLeaf = (VFSLeaf) child;
            pruneVersionHistory(versionsLeaf, maxHistoryLength, progress);
        }
    }
}
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)

Example 22 with VFSLeaf

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

the class VersionsFileManager method getCanonicalVersionXmlFile.

/**
 * Get the canonical path to the file's meta file.
 *
 * @param bcPath
 * @return String
 */
private VFSLeaf getCanonicalVersionXmlFile(VFSItem item, boolean create) {
    File f = getOriginFile(item);
    if (!f.exists()) {
        return null;
    }
    String relPath = getRelPath(item);
    if (relPath == null) {
        // cannot handle
        return null;
    }
    File fVersion = new File(getRootVersionsFile(), relPath + ".xml");
    File fParentVersion = fVersion.getParentFile();
    if (!fParentVersion.exists() && create) {
        fParentVersion.mkdirs();
    }
    if (fVersion.exists()) {
        LocalFolderImpl localVersionContainer = new LocalFolderImpl(fParentVersion);
        return (VFSLeaf) localVersionContainer.resolve(fVersion.getName());
    } else if (create) {
        LocalFolderImpl localVersionContainer = new LocalFolderImpl(fParentVersion);
        VersionsFileImpl versions = new VersionsFileImpl();
        versions.setVersioned(isVersioned(item));
        versions.setRevisionNr(getNextRevisionNr(versions));
        VFSLeaf fVersions = localVersionContainer.createChildLeaf(fVersion.getName());
        XStreamHelper.writeObject(mystream, fVersions, versions);
        return fVersions;
    }
    return null;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 23 with VFSLeaf

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

the class VersionsFileManager method restore.

@Override
public boolean restore(VFSContainer container, VFSRevision revision) {
    String filename = revision.getName();
    VFSItem restoredItem = container.resolve(filename);
    if (restoredItem == null) {
        restoredItem = container.createChildLeaf(filename);
    }
    if (restoredItem instanceof VFSLeaf) {
        VFSLeaf restoredLeaf = (VFSLeaf) restoredItem;
        InputStream inStream = revision.getInputStream();
        if (VFSManager.copyContent(inStream, restoredLeaf)) {
            VFSLeaf versionFile = getCanonicalVersionXmlFile(restoredLeaf, true);
            Versions versions = readVersions(restoredLeaf, versionFile);
            if (versions instanceof VersionsFileImpl) {
                versions.getRevisions().remove(revision);
                ((VersionsFileImpl) versions).setRevisionNr(getNextRevisionNr(versions));
            }
            XStreamHelper.writeObject(mystream, versionFile, versions);
            return true;
        }
    }
    return false;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) InputStream(java.io.InputStream) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 24 with VFSLeaf

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

the class VersionsFileManager method delete.

@Override
public boolean delete(OrphanVersion orphan) {
    VFSLeaf versionLeaf = orphan.getVersionsLeaf();
    // already deleted
    if (versionLeaf == null)
        return true;
    Versions versions = orphan.getVersions();
    for (VFSRevision versionToDelete : versions.getRevisions()) {
        RevisionFileImpl versionImpl = (RevisionFileImpl) versionToDelete;
        versionImpl.setContainer(orphan.getVersionsLeaf().getParentContainer());
        VFSLeaf fileToDelete = versionImpl.getFile();
        if (fileToDelete != null) {
            fileToDelete.delete();
        }
    }
    versionLeaf.delete();
    return true;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf)

Example 25 with VFSLeaf

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

the class VersionsFileManager method getDeletedFiles.

@Override
public List<Versions> getDeletedFiles(VFSContainer container) {
    List<Versions> deletedRevisions = new ArrayList<Versions>();
    VFSContainer versionContainer = getCanonicalVersionFolder(container, false);
    if (versionContainer != null) {
        Set<String> currentNames = new HashSet<String>();
        for (VFSItem item : container.getItems(new VFSLeafFilter())) {
            currentNames.add(item.getName() + ".xml");
        }
        List<VFSItem> versionItems = versionContainer.getItems(new VFSItemSuffixFilter(new String[] { "xml" }));
        for (VFSItem versionItem : versionItems) {
            String name = versionItem.getName();
            if (versionItem instanceof VFSLeaf && !currentNames.contains(name) && isVersionsXmlFile((VFSLeaf) versionItem)) {
                Versions versions = readVersions(null, (VFSLeaf) versionItem);
                if (versions != null) {
                    List<VFSRevision> revisions = versions.getRevisions();
                    if (!revisions.isEmpty()) {
                        deletedRevisions.add(versions);
                    }
                }
            }
        }
    }
    return deletedRevisions;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSItemSuffixFilter(org.olat.core.util.vfs.filters.VFSItemSuffixFilter) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) HashSet(java.util.HashSet) VFSLeafFilter(org.olat.core.util.vfs.filters.VFSLeafFilter)

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