From d27ea6f96fcaee18831d0a1de45592fdb06c7f36 Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Mon, 4 Jan 2016 09:46:01 +0100
Subject: [PATCH] OO-1824: reuse the persisting course in the merged course
 container

---
 src/main/java/org/olat/course/ICourse.java    | 11 ++-
 .../olat/course/MergedCourseContainer.java    | 89 ++++++++++---------
 .../org/olat/course/PersistingCourseImpl.java |  6 +-
 3 files changed, 61 insertions(+), 45 deletions(-)

diff --git a/src/main/java/org/olat/course/ICourse.java b/src/main/java/org/olat/course/ICourse.java
index 0ed4c97b658..5502208a498 100644
--- a/src/main/java/org/olat/course/ICourse.java
+++ b/src/main/java/org/olat/course/ICourse.java
@@ -86,11 +86,20 @@ public interface ICourse extends OLATResourceable {
 	
 	/**
 	 * Return the container to the coursefolder of this course.
-	 * (E.g. "COURSEBASEPATH/coursefolder/")
+	 * (E.g. "COURSEBASEPATH/coursefolder/"). This is for administration
+	 * use. There is no permission check.
+	 * 
 	 * @return the container to the coursefolder of this course
 	 */
 	public VFSContainer getCourseFolderContainer();
 	
+	/**
+	 * The course folder that the user specified by its identity environment
+	 * can see and use.
+	 * 
+	 * @param identityEnv
+	 * @return The aggreagted course folder
+	 */
 	public VFSContainer getCourseFolderContainer(IdentityEnvironment identityEnv);
 	
 	public OlatRootFolderImpl getCourseExportDataDir();
diff --git a/src/main/java/org/olat/course/MergedCourseContainer.java b/src/main/java/org/olat/course/MergedCourseContainer.java
index d51771e3cad..f26e35c8dc1 100644
--- a/src/main/java/org/olat/course/MergedCourseContainer.java
+++ b/src/main/java/org/olat/course/MergedCourseContainer.java
@@ -73,55 +73,60 @@ public class MergedCourseContainer extends MergeSource {
 	
 	@Override
 	protected void init() {
-		super.init();
 		ICourse course = CourseFactory.loadCourse(courseId);
 		if(course instanceof PersistingCourseImpl) {
-			PersistingCourseImpl persistingCourse = (PersistingCourseImpl)course;
-			if(identityEnv == null || identityEnv.getRoles().isOLATAdmin()) {
+			init((PersistingCourseImpl)course);
+		}
+	}
+	
+	protected void init(PersistingCourseImpl persistingCourse) {
+		super.init();
+
+		if(identityEnv == null || identityEnv.getRoles().isOLATAdmin()) {
+			addContainersChildren(persistingCourse.getIsolatedCourseFolder(), true);
+		} else {
+			RepositoryEntry re = persistingCourse.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
+			RepositoryEntrySecurity reSecurity = RepositoryManager.getInstance()
+					.isAllowed(identityEnv.getIdentity(), identityEnv.getRoles(), re);
+			if(reSecurity.isEntryAdmin()) {
 				addContainersChildren(persistingCourse.getIsolatedCourseFolder(), true);
-			} else {
-				RepositoryEntry re = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
-				RepositoryEntrySecurity reSecurity = RepositoryManager.getInstance()
-						.isAllowed(identityEnv.getIdentity(), identityEnv.getRoles(), re);
-				if(reSecurity.isEntryAdmin()) {
-					addContainersChildren(persistingCourse.getIsolatedCourseFolder(), true);
-				}
-			}
-			// grab any shared folder that is configured
-			OlatRootFolderImpl sharedFolder = null;
-			String sfSoftkey = persistingCourse.getCourseConfig().getSharedFolderSoftkey();
-			if (StringHelper.containsNonWhitespace(sfSoftkey) && !CourseConfig.VALUE_EMPTY_SHAREDFOLDER_SOFTKEY.equals(sfSoftkey)) {
-				OLATResource sharedResource = CoreSpringFactory.getImpl(RepositoryService.class)
-						.loadRepositoryEntryResourceBySoftKey(sfSoftkey);
-				if (sharedResource != null) {
-					sharedFolder = SharedFolderManager.getInstance().getSharedFolder(sharedResource);
-					if (sharedFolder != null) {
-						sharedFolder.setLocalSecurityCallback(new ReadOnlyCallback());
-						//add local course folder's children as read/write source and any sharedfolder as subfolder
-						addContainer(new NamedContainerImpl("_sharedfolder", sharedFolder));
-					}
-				}
 			}
+		}
 			
-			// add all course building blocks of type BC to a virtual folder
-			MergeSource nodesContainer = new MergeSource(null, "_courseelementdata");
-			if(identityEnv == null) {
-				CourseNode rootNode = course.getRunStructure().getRootNode();
-				addFolderBuildingBlocks(persistingCourse, nodesContainer, rootNode);
-			} else {
-				TreeEvaluation treeEval = new TreeEvaluation();
-				GenericTreeModel treeModel = new GenericTreeModel();
-				UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
-				CourseNode rootCn = userCourseEnv.getCourseEnvironment().getRunStructure().getRootNode();
-				NodeEvaluation rootNodeEval = rootCn.eval(userCourseEnv.getConditionInterpreter(), treeEval, new VisibleTreeFilter());
-				TreeNode treeRoot = rootNodeEval.getTreeNode();
-				treeModel.setRootNode(treeRoot);
-				addFolderBuildingBlocks(persistingCourse, nodesContainer, treeRoot);
+		// grab any shared folder that is configured
+		OlatRootFolderImpl sharedFolder = null;
+		String sfSoftkey = persistingCourse.getCourseConfig().getSharedFolderSoftkey();
+		if (StringHelper.containsNonWhitespace(sfSoftkey) && !CourseConfig.VALUE_EMPTY_SHAREDFOLDER_SOFTKEY.equals(sfSoftkey)) {
+			OLATResource sharedResource = CoreSpringFactory.getImpl(RepositoryService.class)
+					.loadRepositoryEntryResourceBySoftKey(sfSoftkey);
+			if (sharedResource != null) {
+				sharedFolder = SharedFolderManager.getInstance().getSharedFolder(sharedResource);
+				if (sharedFolder != null) {
+					sharedFolder.setLocalSecurityCallback(new ReadOnlyCallback());
+					//add local course folder's children as read/write source and any sharedfolder as subfolder
+					addContainer(new NamedContainerImpl("_sharedfolder", sharedFolder));
+				}
 			}
+		}
 			
-			if (nodesContainer.getItems().size() > 0) {
-				addContainer(nodesContainer);
-			}
+		// 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();
+			addFolderBuildingBlocks(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);
+			addFolderBuildingBlocks(persistingCourse, nodesContainer, treeRoot);
+		}
+		
+		if (nodesContainer.getItems().size() > 0) {
+			addContainer(nodesContainer);
 		}
 	}
 	
diff --git a/src/main/java/org/olat/course/PersistingCourseImpl.java b/src/main/java/org/olat/course/PersistingCourseImpl.java
index 6b6c0b09239..84847c2235a 100644
--- a/src/main/java/org/olat/course/PersistingCourseImpl.java
+++ b/src/main/java/org/olat/course/PersistingCourseImpl.java
@@ -159,6 +159,7 @@ public class PersistingCourseImpl implements ICourse, OLATResourceable, Serializ
 	/**
 	 * @see org.olat.course.ICourse#getCourseBasePath()
 	 */
+	@Override
 	public OlatRootFolderImpl getCourseBaseContainer() {
 		return courseRootContainer;
 	}
@@ -179,7 +180,7 @@ public class PersistingCourseImpl implements ICourse, OLATResourceable, Serializ
 	public VFSContainer getCourseFolderContainer() {
 		// add local course folder's children as read/write source and any sharedfolder as subfolder
 		MergedCourseContainer courseFolderContainer = new MergedCourseContainer(resourceableId, getCourseTitle());
-		courseFolderContainer.init();
+		courseFolderContainer.init(this);
 		return courseFolderContainer;
 	}
 
@@ -187,7 +188,7 @@ public class PersistingCourseImpl implements ICourse, OLATResourceable, Serializ
 	public VFSContainer getCourseFolderContainer(IdentityEnvironment identityEnv) {
 		// add local course folder's children as read/write source and any sharedfolder as subfolder
 		MergedCourseContainer courseFolderContainer = new MergedCourseContainer(resourceableId, getCourseTitle(), identityEnv);
-		courseFolderContainer.init();
+		courseFolderContainer.init(this);
 		return courseFolderContainer;
 	}
 	
@@ -202,6 +203,7 @@ public class PersistingCourseImpl implements ICourse, OLATResourceable, Serializ
 	/**
 	 * @see org.olat.course.ICourse#getCourseTitle()
 	 */
+	@Override
 	public String getCourseTitle() {	
 		if (courseTitle == null) {
 			synchronized (courseTitleSyncObj) { //o_clusterOK by:ld/se
-- 
GitLab