final CoursePropertyManager cpm = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
final CourseNode thisCourseNode = this;
Forum theForum = null;
Codepoint.codepoint(FOCourseNode.class, "findCourseNodeProperty");
Property forumKeyProp = cpm.findCourseNodeProperty(thisCourseNode, null, null, FORUM_KEY);
//System.out.println("System.out.println - findCourseNodeProperty");
if(forumKeyProp!=null) {
// Forum does already exist, load forum with key from properties
Long forumKey = forumKeyProp.getLongValue();
theForum = fom.loadForum(forumKey);
if (theForum == null) { throw new OLATRuntimeException(FOCourseNode.class, "Tried to load forum with key " + forumKey.longValue() + " in course "
+ userCourseEnv.getCourseEnvironment().getCourseResourceableId() + " for node " + thisCourseNode.getIdent()
+ " as defined in course node property but forum manager could not load forum.", null); }
} else {
//creates resourceable from FOCourseNode.class and the current node id as key
OLATResourceable courseNodeResourceable = OresHelper.createOLATResourceableInstance(FOCourseNode.class, new Long(this.getIdent()));
Codepoint.codepoint(FOCourseNode.class, "beforeDoInSync");
//System.out.println("System.out.println - beforeDoInSync");
//o_clusterOK by:ld
theForum = CoordinatorManager.getCoordinator().getSyncer().doInSync(courseNodeResourceable, new SyncerCallback<Forum>(){
public Forum execute() {
Forum forum = null;
Long forumKey;
Codepoint.codepoint(FOCourseNode.class,"doInSync");
//System.out.println("Codepoint - doInSync");
Property forumKeyProperty = cpm.findCourseNodeProperty(thisCourseNode, null, null, FORUM_KEY);
if (forumKeyProperty == null) {
// First call of forum, create new forum and save forum key as property
forum = fom.addAForum();
forumKey = forum.getKey();
forumKeyProperty = cpm.createCourseNodePropertyInstance(thisCourseNode, null, null, FORUM_KEY, null, forumKey, null, null);
cpm.saveProperty(forumKeyProperty);
//System.out.println("Forum added");
} else {
// Forum does already exist, load forum with key from properties
forumKey = forumKeyProperty.getLongValue();
forum = fom.loadForum(forumKey);
if (forum == null) { throw new OLATRuntimeException(FOCourseNode.class, "Tried to load forum with key " + forumKey.longValue() + " in course "
+ userCourseEnv.getCourseEnvironment().getCourseResourceableId() + " for node " + thisCourseNode.getIdent()
+ " as defined in course node property but forum manager could not load forum.", null); }
}