use of org.olat.core.util.vfs.MergeSource in project OpenOLAT by OpenOLAT.
the class MergedCourseContainer method addFolders.
private void addFolders(PersistingCourseImpl course, MergeSource nodesContainer, TreeNode courseNode) {
if (courseNode == null)
return;
for (int i = 0; i < courseNode.getChildCount(); i++) {
TreeNode child = (TreeNode) courseNode.getChildAt(i);
NodeEvaluation nodeEval;
if (child.getUserObject() instanceof NodeEvaluation) {
nodeEval = (NodeEvaluation) child.getUserObject();
} else {
continue;
}
if (nodeEval != null && nodeEval.getCourseNode() != null) {
CourseNode courseNodeChild = nodeEval.getCourseNode();
String folderName = RequestUtil.normalizeFilename(courseNodeChild.getShortTitle());
if (courseNodeChild instanceof BCCourseNode) {
final BCCourseNode bcNode = (BCCourseNode) courseNodeChild;
// add folder not to merge source. Use name and node id to have unique name
VFSContainer rootFolder = getBCContainer(course, bcNode, nodeEval, false);
boolean canDownload = nodeEval.isCapabilityAccessible("download");
if (canDownload && rootFolder != null) {
if (courseReadOnly) {
rootFolder.setLocalSecurityCallback(new ReadOnlyCallback());
} else if (nodeEval.isCapabilityAccessible("upload")) {
// inherit the security callback from the course as for author
} else {
rootFolder.setLocalSecurityCallback(new ReadOnlyCallback());
}
folderName = getFolderName(nodesContainer, bcNode, folderName);
// 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
addFolders(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 ...
addFolders(course, courseNodeContainer, child);
// ... but only add this container if it contains any children with at least one BC course node
if (courseNodeContainer.getItems().size() > 0) {
nodesContainer.addContainer(courseNodeContainer);
}
}
} else if (courseNodeChild instanceof PFCourseNode) {
final PFCourseNode pfNode = (PFCourseNode) courseNodeChild;
// 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);
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
VFSContainer rootFolder = pfManager.provideCoachOrParticipantContainer(pfNode, userCourseEnv, identityEnv.getIdentity(), courseReadOnly);
VFSContainer nodeContentContainer = new NamedContainerImpl(folderName, rootFolder);
courseNodeContainer.addContainersChildren(nodeContentContainer, true);
addFolders(course, courseNodeContainer, child);
nodesContainer.addContainer(courseNodeContainer);
} 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 ...
addFolders(course, courseNodeContainer, child);
// ... but only add this container if it contains any children with at least one BC course node
if (courseNodeContainer.getItems().size() > 0) {
nodesContainer.addContainer(courseNodeContainer);
}
}
}
}
}
use of org.olat.core.util.vfs.MergeSource in project openolat by klemens.
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.MergeSource in project openolat by klemens.
the class SimpleVersionConfig method versionEnabled.
public boolean versionEnabled(VFSContainer container) {
int versionsAllowed = getVersionAllowed();
if (versionsAllowed == 0) {
return false;
}
if (container instanceof NamedContainerImpl) {
container = ((NamedContainerImpl) container).getDelegate();
}
if (container instanceof MergeSource) {
container = ((MergeSource) container).getRootWriteContainer();
}
if (container instanceof LocalFolderImpl) {
try {
LocalFolderImpl folderImpl = (LocalFolderImpl) container;
String path = folderImpl.getBasefile().getCanonicalPath();
List<String> excludedRoots = getExcludedRoots();
for (String excludedRoot : excludedRoots) {
if (path.startsWith(excludedRoot)) {
return false;
}
}
String root = getCourseRoot();
if (path.startsWith(root)) {
for (String exclusion : EXCLUSIONS_IN_COURSE_PATH) {
if (path.indexOf(exclusion) > 0) {
return false;
}
}
}
return getVersionAllowed() != 0;
} catch (IOException e) {
// fail silently;
}
}
return false;
}
Aggregations