use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class MergedCourseContainer method init.
protected void init(PersistingCourseImpl persistingCourse) {
super.init();
RepositoryEntry courseRe = persistingCourse.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
courseReadOnly = !overrideReadOnly && (courseRe.getRepositoryEntryStatus().isClosed() || courseRe.getRepositoryEntryStatus().isUnpublished());
if (courseReadOnly) {
setLocalSecurityCallback(new ReadOnlyCallback());
}
if (identityEnv == null || identityEnv.getRoles().isOLATAdmin()) {
VFSContainer courseContainer = persistingCourse.getIsolatedCourseFolder();
if (courseReadOnly) {
courseContainer.setLocalSecurityCallback(new ReadOnlyCallback());
}
addContainersChildren(courseContainer, true);
} else {
RepositoryEntry re = persistingCourse.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
RepositoryEntrySecurity reSecurity = RepositoryManager.getInstance().isAllowed(identityEnv.getIdentity(), identityEnv.getRoles(), re);
if (reSecurity.isEntryAdmin()) {
VFSContainer courseContainer = persistingCourse.getIsolatedCourseFolder();
if (courseReadOnly) {
courseContainer.setLocalSecurityCallback(new ReadOnlyCallback());
}
addContainersChildren(courseContainer, true);
}
}
initSharedFolder(persistingCourse);
// add all course building blocks of type BC to a virtual folder
MergeSource nodesContainer = new MergeSource(null, "_courseelementdata");
if (identityEnv == null) {
CourseNode rootNode = persistingCourse.getRunStructure().getRootNode();
addFoldersForAdmin(persistingCourse, nodesContainer, rootNode);
} else {
TreeEvaluation treeEval = new TreeEvaluation();
GenericTreeModel treeModel = new GenericTreeModel();
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(identityEnv, persistingCourse.getCourseEnvironment());
CourseNode rootCn = userCourseEnv.getCourseEnvironment().getRunStructure().getRootNode();
NodeEvaluation rootNodeEval = rootCn.eval(userCourseEnv.getConditionInterpreter(), treeEval, new VisibleTreeFilter());
TreeNode treeRoot = rootNodeEval.getTreeNode();
treeModel.setRootNode(treeRoot);
addFolders(persistingCourse, nodesContainer, treeRoot);
}
if (nodesContainer.getItems().size() > 0) {
addContainer(nodesContainer);
}
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class MergedCourseContainer method addFoldersForAdmin.
/**
* Internal method to recursively add all course building blocks of type
* BC to a given VFS container. This should only be used for an author view,
* it does not test for security.
*
* @param course
* @param nodesContainer
* @param courseNode
* @return container for the current course node
*/
private void addFoldersForAdmin(PersistingCourseImpl course, MergeSource nodesContainer, CourseNode courseNode) {
for (int i = 0; i < courseNode.getChildCount(); i++) {
CourseNode child = (CourseNode) courseNode.getChildAt(i);
String folderName = RequestUtil.normalizeFilename(child.getShortTitle());
if (child instanceof BCCourseNode) {
final BCCourseNode bcNode = (BCCourseNode) child;
// add folder not to merge source. Use name and node id to have unique name
VFSContainer rootFolder = getBCContainer(course, bcNode, null, true);
if (courseReadOnly) {
rootFolder.setLocalSecurityCallback(new ReadOnlyCallback());
}
folderName = getFolderName(nodesContainer, bcNode, folderName);
if (rootFolder != null) {
// Create a container for this node content and wrap it with a merge source which is attached to tree
VFSContainer nodeContentContainer = new NamedContainerImpl(folderName, rootFolder);
MergeSource courseNodeContainer = new MergeSource(nodesContainer, folderName);
courseNodeContainer.addContainersChildren(nodeContentContainer, true);
nodesContainer.addContainer(courseNodeContainer);
// Do recursion for all children
addFoldersForAdmin(course, courseNodeContainer, child);
}
} else if (child instanceof PFCourseNode) {
final PFCourseNode pfNode = (PFCourseNode) child;
// add folder not to merge source. Use name and node id to have unique name
PFManager pfManager = CoreSpringFactory.getImpl(PFManager.class);
folderName = getFolderName(nodesContainer, pfNode, folderName);
MergeSource courseNodeContainer = new MergeSource(nodesContainer, folderName);
VFSContainer rootFolder = pfManager.provideAdminContainer(pfNode, course.getCourseEnvironment());
VFSContainer nodeContentContainer = new NamedContainerImpl(folderName, rootFolder);
courseNodeContainer.addContainersChildren(nodeContentContainer, true);
nodesContainer.addContainer(courseNodeContainer);
// Do recursion for all children
addFoldersForAdmin(course, courseNodeContainer, child);
} else {
// For non-folder course nodes, add merge source (no files to show) ...
MergeSource courseNodeContainer = new MergeSource(null, folderName);
// , then do recursion for all children ...
addFoldersForAdmin(course, courseNodeContainer, child);
// ... but only add this container if it contains any children with at least one BC course node
if (!courseNodeContainer.getItems().isEmpty()) {
nodesContainer.addContainer(courseNodeContainer);
}
}
}
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class VFSUtil method calculateSubRoot.
/**
* calculates a new vfscontainer and a filename where the container's base is where the file resides.<br>
* e.g.<br>
* container: /usr/local/olat/courses/123/coursefolder and filename: docs/bla/blu.doc<br>
* -> container /usr/local/olat/courses/123/coursefolder/docs/bla and filename: blu.doc
*
* @param oldRoot
* @param fileName
* @return
*/
public static ContainerAndFile calculateSubRoot(VFSContainer oldRoot, String fileUri) {
VFSContainer newC;
String newFile;
int sla = fileUri.lastIndexOf('/');
if (sla != -1) {
String root = fileUri.substring(0, sla);
newFile = fileUri.substring(sla + 1);
newC = (VFSContainer) oldRoot.resolve(root);
} else {
newC = oldRoot;
newFile = fileUri;
}
return new ContainerAndFile(newC, newFile);
}
use of org.olat.core.util.vfs.VFSContainer 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);
}
}
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method orphans.
@Override
public List<OrphanVersion> orphans() {
List<OrphanVersion> orphans = new ArrayList<OrphanVersion>();
VFSContainer versionsContainer = getRootVersionsContainer();
crawlForOrphans(versionsContainer, orphans);
return orphans;
}
Aggregations