use of org.olat.modules.fo.manager.ForumManager in project openolat by klemens.
the class ForumNodeForumCallback method createForum.
private Forum createForum(final CourseEnvironment courseEnv) {
final ForumManager fom = CoreSpringFactory.getImpl(ForumManager.class);
// creates resourceable from FOCourseNode.class and the current node id as key
OLATResourceable courseNodeResourceable = OresHelper.createOLATResourceableInstance(FOCourseNode.class, new Long(getIdent()));
// o_clusterOK by:ld
return CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(courseNodeResourceable, new SyncerCallback<Forum>() {
@Override
public Forum execute() {
Forum forum;
CoursePropertyManager cpm = courseEnv.getCoursePropertyManager();
Property forumKeyProperty = cpm.findCourseNodeProperty(FOCourseNode.this, null, null, FORUM_KEY);
if (forumKeyProperty == null) {
// First call of forum, create new forum and save forum key as property
forum = fom.addAForum();
Long forumKey = forum.getKey();
forumKeyProperty = cpm.createCourseNodePropertyInstance(FOCourseNode.this, null, null, FORUM_KEY, null, forumKey, null, null);
cpm.saveProperty(forumKeyProperty);
} else {
// Forum does already exist, load forum with key from properties
Long 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 " + courseEnv.getCourseResourceableId() + " for node " + getIdent() + " as defined in course node property but forum manager could not load forum.", null);
}
}
return forum;
}
});
}
use of org.olat.modules.fo.manager.ForumManager in project openolat by klemens.
the class ForumArtefactHandler method prefillArtefactAccordingToSource.
/**
* @see org.olat.portfolio.EPAbstractHandler#prefillArtefactAccordingToSource(org.olat.portfolio.model.artefacts.AbstractArtefact, java.lang.Object)
*/
@Override
public void prefillArtefactAccordingToSource(AbstractArtefact artefact, Object source) {
super.prefillArtefactAccordingToSource(artefact, source);
if (source instanceof OLATResourceable) {
OLATResourceable ores = (OLATResourceable) source;
ForumManager fMgr = ForumManager.getInstance();
Message fm = fMgr.loadMessage(ores.getResourceableId());
String thread = fm.getThreadtop() != null ? fm.getThreadtop().getTitle() + " - " : "";
artefact.setTitle(thread + fm.getTitle());
VFSContainer msgContainer = fMgr.getMessageContainer(fm.getForum().getKey(), fm.getKey());
if (msgContainer != null) {
List<VFSItem> foAttach = msgContainer.getItems();
if (foAttach.size() != 0) {
artefact.setFileSourceContainer(msgContainer);
}
}
artefact.setSignature(70);
artefact.setFulltextContent(fm.getBody());
}
}
use of org.olat.modules.fo.manager.ForumManager in project openolat by klemens.
the class ForumCourseNodeWebService method addMessage.
/**
* Internal helper method to add a message to a forum.
* @param courseId
* @param nodeId
* @param parentMessageId can be null (will lead to new thread)
* @param title
* @param body
* @param identityName
* @param isSticky only necessary when adding new thread
* @param request
* @return
*/
private Response addMessage(Long courseId, String nodeId, Long parentMessageId, String title, String body, String identityName, Boolean isSticky, HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
BaseSecurity securityManager = BaseSecurityManager.getInstance();
Identity identity;
if (identityName != null) {
identity = securityManager.findIdentityByName(identityName);
} else {
identity = RestSecurityHelper.getIdentity(request);
}
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
// load forum
ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!isAuthorEditor(course, request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
CourseNode courseNode = getParentNode(course, nodeId);
if (courseNode == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
Property forumKeyProp = cpm.findCourseNodeProperty(courseNode, null, null, FOCourseNode.FORUM_KEY);
Forum forum = null;
ForumManager fom = ForumManager.getInstance();
if (forumKeyProp != null) {
// Forum does already exist, load forum with key from properties
Long forumKey = forumKeyProp.getLongValue();
forum = fom.loadForum(forumKey);
}
if (forum == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
MessageVO vo;
if (parentMessageId == null || parentMessageId == 0L) {
// creating the thread (a message without a parent message)
Message newThread = fom.createMessage(forum, identity, false);
if (isSticky != null && isSticky.booleanValue()) {
// set sticky
org.olat.modules.fo.Status status = new org.olat.modules.fo.Status();
status.setSticky(true);
newThread.setStatusCode(org.olat.modules.fo.Status.getStatusCode(status));
}
newThread.setTitle(title);
newThread.setBody(body);
// open a new thread
fom.addTopMessage(newThread);
vo = new MessageVO(newThread);
} else {
// adding response message (a message with a parent message)
Message threadMessage = fom.loadMessage(parentMessageId);
if (threadMessage == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
// create new message
Message message = fom.createMessage(forum, identity, false);
message.setTitle(title);
message.setBody(body);
fom.replyToMessage(message, threadMessage);
vo = new MessageVO(message);
}
return Response.ok(vo).build();
}
use of org.olat.modules.fo.manager.ForumManager in project openolat by klemens.
the class ForumImportWebService method getForumWebservice.
/**
* Web service to manage a forum
* @param forumKey The key of the forum
* @return
*/
@Path("{forumKey}")
public ForumWebService getForumWebservice(@PathParam("forumKey") Long forumKey) {
ForumManager fom = ForumManager.getInstance();
Forum forum = fom.loadForum(forumKey);
return new ForumWebService(forum);
}
use of org.olat.modules.fo.manager.ForumManager in project openolat by klemens.
the class CollaborationTools method getForum.
public Forum getForum() {
final ForumManager fom = ForumManager.getInstance();
final NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(ores);
Property forumProperty = npm.findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
Forum forum;
if (forumProperty != null) {
forum = fom.loadForum(forumProperty.getLongValue());
} else {
forum = coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerCallback<Forum>() {
@Override
public Forum execute() {
Forum aforum;
Long forumKey;
Property forumKeyProperty = npm.findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
if (forumKeyProperty == null) {
// First call of forum, create new forum and save
aforum = fom.addAForum();
forumKey = aforum.getKey();
if (log.isDebug()) {
log.debug("created new forum in collab tools: foid::" + forumKey.longValue() + " for ores::" + ores.getResourceableTypeName() + "/" + ores.getResourceableId());
}
forumKeyProperty = npm.createPropertyInstance(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM, null, forumKey, null, null);
npm.saveProperty(forumKeyProperty);
} else {
// Forum does already exist, load forum with key from properties
forumKey = forumKeyProperty.getLongValue();
aforum = fom.loadForum(forumKey);
if (aforum == null) {
throw new AssertException("Unable to load forum with key " + forumKey.longValue() + " for ores " + ores.getResourceableTypeName() + " with key " + ores.getResourceableId());
}
if (log.isDebug()) {
log.debug("loading forum in collab tools from properties: foid::" + forumKey.longValue() + " for ores::" + ores.getResourceableTypeName() + "/" + ores.getResourceableId());
}
}
return aforum;
}
});
}
return forum;
}
Aggregations