Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.course;
import org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl;
import org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.StringHelper;
import org.olat.core.util.vfs.MergeSource;
import org.olat.core.util.vfs.NamedContainerImpl;
import org.olat.core.util.vfs.callbacks.ReadOnlyCallback;
import org.olat.course.config.CourseConfig;
import org.olat.course.nodes.BCCourseNode;
import org.olat.course.nodes.CourseNode;
import org.olat.modules.sharedfolder.SharedFolderManager;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryManager;
/**
*
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*/
public class MergedCourseContainer extends MergeSource {
private static final OLog log = Tracing.createLoggerFor(MergedCourseContainer.class);
private Long courseId;
public MergedCourseContainer(Long courseId, String name) {
super(null, name);
this.courseId = courseId;
}
@Override
protected void init() {
super.init();
ICourse course = CourseFactory.loadCourse(courseId);
if(course instanceof PersistingCourseImpl) {
PersistingCourseImpl persistingCourse = (PersistingCourseImpl)course;
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)) {
RepositoryManager rm = RepositoryManager.getInstance();
RepositoryEntry re = rm.lookupRepositoryEntryBySoftkey(sfSoftkey, false);
if (re != null) {
sharedFolder = SharedFolderManager.getInstance().getSharedFolder(re.getOlatResource());
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");
addFolderBuildingBlocks(persistingCourse, nodesContainer, persistingCourse.getRunStructure().getRootNode());
if (nodesContainer.getItems().size() > 0) {
addContainer(nodesContainer);
}
}
}
/**
* 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
*/
private void addFolderBuildingBlocks(PersistingCourseImpl course, MergeSource nodesContainer, CourseNode courseNode) {
for (int i = 0; i < courseNode.getChildCount(); i++) {
CourseNode child = (CourseNode) courseNode.getChildAt(i);
if (child instanceof BCCourseNode) {
BCCourseNode bcNode = (BCCourseNode) child;
// add folder not to merge source. Use name and node id to have unique name
String path = BCCourseNode.getFoldernodePathRelToFolderBase(course.getCourseEnvironment(), bcNode);
OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(path, null);
String folderName = bcNode.getShortTitle() + " (" + bcNode.getIdent() + ")";
OlatNamedContainerImpl BCFolder = new OlatNamedContainerImpl(folderName, rootFolder);
nodesContainer.addContainer(BCFolder);
}
// recursion for all childrenØ
addFolderBuildingBlocks(course, nodesContainer, child);
}
}
private Object readResolve() {
try {
init();
return this;
} catch (Exception e) {
log.error("Cannot init the merged container of a course after deserialization", e);
return null;
}
}
}