use of org.olat.course.nodes.FOCourseNode in project OpenOLAT by OpenOLAT.
the class CourseCreationHelper method finalizeWorkflow.
/**
* Finalizes the course creation workflow via wizard.
* @param ureq
*/
public void finalizeWorkflow(final UserRequest ureq) {
// --------------------------
// 1. insert the course nodes
// --------------------------
// single page node
CourseNode singlePageNode = null;
if (courseConfig.isCreateSinglePage()) {
singlePageNode = CourseExtensionHelper.createSinglePageNode(course, translator.translate("cce.informationpage"), translator.translate("cce.informationpage.descr"));
if (singlePageNode instanceof SPCourseNode) {
final String relPath = CourseEditorHelper.createUniqueRelFilePathFromShortTitle(singlePageNode, course.getCourseFolderContainer());
HTMLDocumentHelper.createHtmlDocument(course, relPath, courseConfig.getSinglePageText(translator));
((SPCourseNode) singlePageNode).getModuleConfiguration().set(SPEditController.CONFIG_KEY_FILE, relPath);
}
}
// enrollment node
CourseNode enCourseNode = null;
if (courseConfig.isCreateEnrollment()) {
enCourseNode = CourseExtensionHelper.createEnrollmentNode(course, translator.translate("cce.enrollment"), translator.translate("cce.enrollment.descr"));
}
// download folder node
CourseNode downloadFolderNode = null;
if (courseConfig.isCreateDownloadFolder()) {
downloadFolderNode = CourseExtensionHelper.createDownloadFolderNode(course, translator.translate("cce.downloadfolder"), translator.translate("cce.downloadfolder.descr"));
}
// forum node
CourseNode forumNode = null;
if (courseConfig.isCreateForum()) {
forumNode = CourseExtensionHelper.createForumNode(course, translator.translate("cce.forum"), translator.translate("cce.forum.descr"));
}
// contact form node
CourseNode contactNode = null;
if (courseConfig.isCreateContactForm()) {
contactNode = CourseExtensionHelper.createContactFormNode(course, translator.translate("cce.contactform"), translator.translate("cce.contactform.descr"));
if (contactNode instanceof COCourseNode) {
final List<String> emails = new ArrayList<String>();
String subject = translator.translate("cce.contactform.subject") + " " + courseConfig.getCourseTitle();
String email = ureq.getIdentity().getUser().getProperty(UserConstants.EMAIL, ureq.getLocale());
if (StringHelper.containsNonWhitespace(email)) {
emails.add(email);
}
COCourseNode cocn = (COCourseNode) contactNode;
cocn.getModuleConfiguration().set(COEditController.CONFIG_KEY_EMAILTOADRESSES, emails);
cocn.getModuleConfiguration().set(COEditController.CONFIG_KEY_MSUBJECT_DEFAULT, subject);
}
}
// enrollment node
if (courseConfig.isCreateEnrollment()) {
// --------------------------
// 2. setup enrollment
// --------------------------
final String groupBaseName = createGroupBaseName();
final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
// get default context for learning groups
// create n learning groups with m allowed members
String comma = "";
String tmpGroupList = "";
String groupNamesList = "";
for (int i = 0; i < courseConfig.getGroupCount(); i++) {
// create group
String name = groupBaseName + " " + (i + 1);
BusinessGroup learningGroup = bgs.createBusinessGroup(ureq.getIdentity(), name, null, 0, courseConfig.getSubscriberCount(), courseConfig.getEnableWaitlist(), courseConfig.getEnableFollowup(), addedEntry);
// enable the contact collaboration tool
CollaborationTools ct = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(learningGroup);
ct.setToolEnabled(CollaborationTools.TOOL_CONTACT, true);
// append to current learning group list
groupNamesList = tmpGroupList + comma + learningGroup.getName();
enCourseNode.getModuleConfiguration().set(ENCourseNode.CONFIG_GROUPNAME, groupNamesList);
if (i == 0) {
comma = ",";
}
tmpGroupList = (String) enCourseNode.getModuleConfiguration().get(ENCourseNode.CONFIG_GROUPNAME);
}
// set signout property
enCourseNode.getModuleConfiguration().set(ENCourseNode.CONF_CANCEL_ENROLL_ENABLED, courseConfig.getEnableSignout());
// access limits on chosen course elements
if (courseConfig.getEnableAccessLimit()) {
if (courseConfig.isEnableAclContactForm()) {
if (contactNode instanceof COCourseNode) {
Condition c = ((COCourseNode) contactNode).getPreConditionVisibility();
c.setEasyModeGroupAccess(groupNamesList);
((COCourseNode) contactNode).setNoAccessExplanation(translator.translate("noaccessexplain"));
// calculate expression from easy mode form
String condString = c.getConditionFromEasyModeConfiguration();
c.setConditionExpression(condString);
c.setExpertMode(false);
}
}
if (courseConfig.isEnableAclSinglePage()) {
if (singlePageNode instanceof SPCourseNode) {
Condition c = ((SPCourseNode) singlePageNode).getPreConditionVisibility();
c.setEasyModeGroupAccess(groupNamesList);
((SPCourseNode) singlePageNode).setNoAccessExplanation(translator.translate("noaccessexplain"));
// calculate expression from easy mode form
String condString = c.getConditionFromEasyModeConfiguration();
c.setConditionExpression(condString);
c.setExpertMode(false);
}
}
if (courseConfig.isEnableAclForum()) {
if (forumNode instanceof FOCourseNode) {
Condition c = ((FOCourseNode) forumNode).getPreConditionVisibility();
c.setEasyModeGroupAccess(groupNamesList);
((FOCourseNode) forumNode).setNoAccessExplanation(translator.translate("noaccessexplain"));
// calculate expression from easy mode form
String condString = c.getConditionFromEasyModeConfiguration();
c.setConditionExpression(condString);
c.setExpertMode(false);
}
}
if (courseConfig.isEnableAclDownloadFolder()) {
if (downloadFolderNode instanceof BCCourseNode) {
Condition c = ((BCCourseNode) downloadFolderNode).getPreConditionVisibility();
c.setEasyModeGroupAccess(groupNamesList);
((BCCourseNode) downloadFolderNode).setNoAccessExplanation(translator.translate("noaccessexplain"));
// calculate expression from easy mode form
String condString = c.getConditionFromEasyModeConfiguration();
c.setConditionExpression(condString);
c.setExpertMode(false);
}
}
}
}
// --------------------------
if (courseConfig.getPublish()) {
CourseAccessAndProperties accessAndProps = courseConfig.getAccessAndProperties();
RepositoryManager manager = RepositoryManager.getInstance();
addedEntry = manager.setAccessAndProperties(accessAndProps.getRepositoryEntry(), accessAndProps.getAccess(), accessAndProps.isMembersOnly(), accessAndProps.isCanCopy(), accessAndProps.isCanReference(), accessAndProps.isCanDownload());
addedEntry = manager.setLeaveSetting(addedEntry, accessAndProps.getSetting());
List<OfferAccess> offerAccess = accessAndProps.getOfferAccess();
ACService acService = CoreSpringFactory.getImpl(ACService.class);
for (OfferAccess newLink : offerAccess) {
acService.saveOfferAccess(newLink);
}
}
course = CourseFactory.openCourseEditSession(course.getResourceableId());
course.getRunStructure().getRootNode().setShortTitle(addedEntry.getDisplayname());
course.getRunStructure().getRootNode().setLongTitle(addedEntry.getDisplayname());
CourseFactory.saveCourse(course.getResourceableId());
final CourseEditorTreeModel cetm = course.getEditorTreeModel();
final CourseNode rootNode = cetm.getCourseNode(course.getRunStructure().getRootNode().getIdent());
rootNode.setShortTitle(addedEntry.getDisplayname());
rootNode.setLongTitle(addedEntry.getDisplayname());
course.getEditorTreeModel().nodeConfigChanged(course.getRunStructure().getRootNode());
CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
// --------------------------
// 3.2 publish the course
// --------------------------
// fetch publish process
final PublishProcess pp = PublishProcess.getInstance(course, cetm, ureq.getLocale());
final StatusDescription[] sds;
// create publish node list
List<String> nodeIds = new ArrayList<String>();
nodeIds.add(cetm.getRootNode().getIdent());
for (int i = 0; i < cetm.getRootNode().getChildCount(); i++) {
nodeIds.add(cetm.getRootNode().getChildAt(i).getIdent());
}
pp.createPublishSetFor(nodeIds);
PublishSetInformations set = pp.testPublishSet(ureq.getLocale());
sds = set.getWarnings();
boolean isValid = sds.length == 0;
if (!isValid) {
// no error and no warnings -> return immediate
log.error("Course Publishing failed", new AssertionError());
}
pp.applyPublishSet(ureq.getIdentity(), ureq.getLocale(), true);
CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
// save catalog entry
if (getConfiguration().getSelectedCatalogEntry() != null) {
CatalogManager cm = CoreSpringFactory.getImpl(CatalogManager.class);
CatalogEntry newEntry = cm.createCatalogEntry();
newEntry.setRepositoryEntry(addedEntry);
newEntry.setName(addedEntry.getDisplayname());
newEntry.setDescription(addedEntry.getDescription());
newEntry.setType(CatalogEntry.TYPE_LEAF);
newEntry.setOwnerGroup(BaseSecurityManager.getInstance().createAndPersistSecurityGroup());
// save entry
cm.addCatalogEntry(getConfiguration().getSelectedCatalogEntry(), newEntry);
}
}
use of org.olat.course.nodes.FOCourseNode in project OpenOLAT by OpenOLAT.
the class UserMgmtTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
if (setuped)
return;
// create identities
owner1 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-zero");
assertNotNull(owner1);
id1 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-one-" + UUID.randomUUID().toString());
id2 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-two");
dbInstance.intermediateCommit();
id2.getUser().setProperty("telMobile", "39847592");
id2.getUser().setProperty("gender", "female");
id2.getUser().setProperty("birthDay", "20091212");
dbInstance.updateObject(id2.getUser());
dbInstance.intermediateCommit();
id3 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-three");
OlatRootFolderImpl id3HomeFolder = new OlatRootFolderImpl(FolderConfig.getUserHome(id3.getName()), null);
VFSContainer id3PublicFolder = (VFSContainer) id3HomeFolder.resolve("public");
if (id3PublicFolder == null) {
id3PublicFolder = id3HomeFolder.createChildContainer("public");
}
VFSItem portrait = id3PublicFolder.resolve("portrait.jpg");
if (portrait == null) {
URL portraitUrl = CoursesElementsTest.class.getResource("portrait.jpg");
File ioPortrait = new File(portraitUrl.toURI());
FileUtils.copyFileToDirectory(ioPortrait, ((LocalImpl) id3PublicFolder).getBasefile(), false);
}
OLATResourceManager rm = OLATResourceManager.getInstance();
// create course and persist as OLATResourceImpl
OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitcourse", System.currentTimeMillis());
OLATResource course = rm.createOLATResourceInstance(resourceable);
dbInstance.saveObject(course);
dbInstance.intermediateCommit();
// create learn group
// 1) context one: learning groups
RepositoryEntry c1 = JunitTestHelper.createAndPersistRepositoryEntry();
// create groups without waiting list
g1externalId = UUID.randomUUID().toString();
g1 = businessGroupService.createBusinessGroup(null, "user-rest-g1", null, g1externalId, "all", 0, 10, false, false, c1);
g2 = businessGroupService.createBusinessGroup(null, "user-rest-g2", null, 0, 10, false, false, c1);
// members g1
businessGroupRelationDao.addRole(id1, g1, GroupRoles.coach.name());
businessGroupRelationDao.addRole(id2, g1, GroupRoles.participant.name());
// members g2
businessGroupRelationDao.addRole(id2, g2, GroupRoles.coach.name());
businessGroupRelationDao.addRole(id1, g2, GroupRoles.participant.name());
// 2) context two: right groups
RepositoryEntry c2 = JunitTestHelper.createAndPersistRepositoryEntry();
// groups
g3ExternalId = UUID.randomUUID().toString();
g3 = businessGroupService.createBusinessGroup(null, "user-rest-g3", null, g3ExternalId, "all", -1, -1, false, false, c2);
g4 = businessGroupService.createBusinessGroup(null, "user-rest-g4", null, -1, -1, false, false, c2);
// members
businessGroupRelationDao.addRole(id1, g3, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id2, g4, GroupRoles.participant.name());
dbInstance.closeSession();
// add some collaboration tools
CollaborationTools g1CTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g1);
g1CTSMngr.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
// create the forum
Forum g1Forum = g1CTSMngr.getForum();
Message m1 = ForumManager.getInstance().createMessage(g1Forum, id1, false);
m1.setTitle("Thread-1");
m1.setBody("Body of Thread-1");
ForumManager.getInstance().addTopMessage(m1);
dbInstance.commitAndCloseSession();
// add some folder tool
CollaborationTools g2CTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
g2CTSMngr.setToolEnabled(CollaborationTools.TOOL_FOLDER, true);
OlatRootFolderImpl g2Folder = new OlatRootFolderImpl(g2CTSMngr.getFolderRelPath(), null);
g2Folder.getBasefile().mkdirs();
VFSItem groupPortrait = g2Folder.resolve("portrait.jpg");
if (groupPortrait == null) {
URL portraitUrl = UserMgmtTest.class.getResource("portrait.jpg");
File ioPortrait = new File(portraitUrl.toURI());
FileUtils.copyFileToDirectory(ioPortrait, g2Folder.getBasefile(), false);
}
dbInstance.commitAndCloseSession();
// prepare some courses
Identity author = JunitTestHelper.createAndPersistIdentityAsUser("auth-" + UUID.randomUUID().toString());
RepositoryEntry entry = JunitTestHelper.deployDemoCourse(author);
if (!repositoryService.hasRole(id1, entry, GroupRoles.participant.name())) {
repositoryService.addRole(id1, entry, GroupRoles.participant.name());
}
demoCourse = CourseFactory.loadCourse(entry);
TreeVisitor visitor = new TreeVisitor(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof FOCourseNode) {
if (demoForumNode == null) {
demoForumNode = (FOCourseNode) node;
Forum courseForum = demoForumNode.loadOrCreateForum(demoCourse.getCourseEnvironment());
Message message1 = ForumManager.getInstance().createMessage(courseForum, id1, false);
message1.setTitle("Thread-1");
message1.setBody("Body of Thread-1");
ForumManager.getInstance().addTopMessage(message1);
}
} else if (node instanceof BCCourseNode) {
if (demoBCCourseNode == null) {
demoBCCourseNode = (BCCourseNode) node;
OlatNamedContainerImpl container = BCCourseNode.getNodeFolderContainer(demoBCCourseNode, demoCourse.getCourseEnvironment());
VFSItem example = container.resolve("singlepage.html");
if (example == null) {
try {
InputStream htmlUrl = UserMgmtTest.class.getResourceAsStream("singlepage.html");
VFSLeaf htmlLeaf = container.createChildLeaf("singlepage.html");
IOUtils.copy(htmlUrl, htmlLeaf.getOutputStream(false));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}, demoCourse.getRunStructure().getRootNode(), false);
visitor.visitAll();
dbInstance.commitAndCloseSession();
setuped = true;
}
use of org.olat.course.nodes.FOCourseNode in project openolat by klemens.
the class UserMgmtTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
if (setuped)
return;
// create identities
owner1 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-zero");
assertNotNull(owner1);
id1 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-one-" + UUID.randomUUID().toString());
id2 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-two");
dbInstance.intermediateCommit();
id2.getUser().setProperty("telMobile", "39847592");
id2.getUser().setProperty("gender", "female");
id2.getUser().setProperty("birthDay", "20091212");
dbInstance.updateObject(id2.getUser());
dbInstance.intermediateCommit();
id3 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-three");
OlatRootFolderImpl id3HomeFolder = new OlatRootFolderImpl(FolderConfig.getUserHome(id3.getName()), null);
VFSContainer id3PublicFolder = (VFSContainer) id3HomeFolder.resolve("public");
if (id3PublicFolder == null) {
id3PublicFolder = id3HomeFolder.createChildContainer("public");
}
VFSItem portrait = id3PublicFolder.resolve("portrait.jpg");
if (portrait == null) {
URL portraitUrl = CoursesElementsTest.class.getResource("portrait.jpg");
File ioPortrait = new File(portraitUrl.toURI());
FileUtils.copyFileToDirectory(ioPortrait, ((LocalImpl) id3PublicFolder).getBasefile(), false);
}
OLATResourceManager rm = OLATResourceManager.getInstance();
// create course and persist as OLATResourceImpl
OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitcourse", System.currentTimeMillis());
OLATResource course = rm.createOLATResourceInstance(resourceable);
dbInstance.saveObject(course);
dbInstance.intermediateCommit();
// create learn group
// 1) context one: learning groups
RepositoryEntry c1 = JunitTestHelper.createAndPersistRepositoryEntry();
// create groups without waiting list
g1externalId = UUID.randomUUID().toString();
g1 = businessGroupService.createBusinessGroup(null, "user-rest-g1", null, g1externalId, "all", 0, 10, false, false, c1);
g2 = businessGroupService.createBusinessGroup(null, "user-rest-g2", null, 0, 10, false, false, c1);
// members g1
businessGroupRelationDao.addRole(id1, g1, GroupRoles.coach.name());
businessGroupRelationDao.addRole(id2, g1, GroupRoles.participant.name());
// members g2
businessGroupRelationDao.addRole(id2, g2, GroupRoles.coach.name());
businessGroupRelationDao.addRole(id1, g2, GroupRoles.participant.name());
// 2) context two: right groups
RepositoryEntry c2 = JunitTestHelper.createAndPersistRepositoryEntry();
// groups
g3ExternalId = UUID.randomUUID().toString();
g3 = businessGroupService.createBusinessGroup(null, "user-rest-g3", null, g3ExternalId, "all", -1, -1, false, false, c2);
g4 = businessGroupService.createBusinessGroup(null, "user-rest-g4", null, -1, -1, false, false, c2);
// members
businessGroupRelationDao.addRole(id1, g3, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id2, g4, GroupRoles.participant.name());
dbInstance.closeSession();
// add some collaboration tools
CollaborationTools g1CTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g1);
g1CTSMngr.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
// create the forum
Forum g1Forum = g1CTSMngr.getForum();
Message m1 = ForumManager.getInstance().createMessage(g1Forum, id1, false);
m1.setTitle("Thread-1");
m1.setBody("Body of Thread-1");
ForumManager.getInstance().addTopMessage(m1);
dbInstance.commitAndCloseSession();
// add some folder tool
CollaborationTools g2CTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
g2CTSMngr.setToolEnabled(CollaborationTools.TOOL_FOLDER, true);
OlatRootFolderImpl g2Folder = new OlatRootFolderImpl(g2CTSMngr.getFolderRelPath(), null);
g2Folder.getBasefile().mkdirs();
VFSItem groupPortrait = g2Folder.resolve("portrait.jpg");
if (groupPortrait == null) {
URL portraitUrl = UserMgmtTest.class.getResource("portrait.jpg");
File ioPortrait = new File(portraitUrl.toURI());
FileUtils.copyFileToDirectory(ioPortrait, g2Folder.getBasefile(), false);
}
dbInstance.commitAndCloseSession();
// prepare some courses
Identity author = JunitTestHelper.createAndPersistIdentityAsUser("auth-" + UUID.randomUUID().toString());
RepositoryEntry entry = JunitTestHelper.deployDemoCourse(author);
if (!repositoryService.hasRole(id1, entry, GroupRoles.participant.name())) {
repositoryService.addRole(id1, entry, GroupRoles.participant.name());
}
demoCourse = CourseFactory.loadCourse(entry);
TreeVisitor visitor = new TreeVisitor(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof FOCourseNode) {
if (demoForumNode == null) {
demoForumNode = (FOCourseNode) node;
Forum courseForum = demoForumNode.loadOrCreateForum(demoCourse.getCourseEnvironment());
Message message1 = ForumManager.getInstance().createMessage(courseForum, id1, false);
message1.setTitle("Thread-1");
message1.setBody("Body of Thread-1");
ForumManager.getInstance().addTopMessage(message1);
}
} else if (node instanceof BCCourseNode) {
if (demoBCCourseNode == null) {
demoBCCourseNode = (BCCourseNode) node;
OlatNamedContainerImpl container = BCCourseNode.getNodeFolderContainer(demoBCCourseNode, demoCourse.getCourseEnvironment());
VFSItem example = container.resolve("singlepage.html");
if (example == null) {
try {
InputStream htmlUrl = UserMgmtTest.class.getResourceAsStream("singlepage.html");
VFSLeaf htmlLeaf = container.createChildLeaf("singlepage.html");
IOUtils.copy(htmlUrl, htmlLeaf.getOutputStream(false));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}, demoCourse.getRunStructure().getRootNode(), false);
visitor.visitAll();
dbInstance.commitAndCloseSession();
setuped = true;
}
use of org.olat.course.nodes.FOCourseNode in project openolat by klemens.
the class ForumCourseNodeWebService method getForums.
/**
* Retrieves metadata of the published course node
* @response.representation.200.qname {http://www.example.com}forumVOes
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The course node metadatas
* @response.representation.200.example {@link org.olat.modules.fo.restapi.Examples#SAMPLE_FORUMVOes}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course or parentNode not found
* @param courseId The course resourceable's id
* @param httpRequest The HTTP request
* @return The persisted structure element (fully populated)
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getForums(@PathParam("courseId") Long courseId, @Context HttpServletRequest httpRequest) {
final ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!CourseWebService.isCourseAccessible(course, false, httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
UserRequest ureq = getUserRequest(httpRequest);
final Set<Long> subcribedForums = new HashSet<Long>();
NotificationsManager man = NotificationsManager.getInstance();
List<String> notiTypes = Collections.singletonList("Forum");
List<Subscriber> subs = man.getSubscribers(ureq.getIdentity(), notiTypes);
for (Subscriber sub : subs) {
Long forumKey = Long.parseLong(sub.getPublisher().getData());
subcribedForums.add(forumKey);
}
final List<ForumVO> forumVOs = new ArrayList<ForumVO>();
new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment()).visit(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof FOCourseNode) {
FOCourseNode forumNode = (FOCourseNode) node;
ForumVO forum = createForumVO(course, forumNode, subcribedForums);
forumVOs.add(forum);
}
}
}, new VisibleTreeFilter());
ForumVOes voes = new ForumVOes();
voes.setForums(forumVOs.toArray(new ForumVO[forumVOs.size()]));
voes.setTotalCount(forumVOs.size());
return Response.ok(voes).build();
}
use of org.olat.course.nodes.FOCourseNode in project openolat by klemens.
the class ForumCourseNodeWebService method getForum.
/**
* Retrieves metadata of the published course node
* @response.representation.200.qname {http://www.example.com}forumVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The course node metadatas
* @response.representation.200.example {@link org.olat.modules.fo.restapi.Examples#SAMPLE_FORUMVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course or parentNode not found
* @param courseId The course resourceable's id
* @param nodeId The node's id
* @param httpRequest The HTTP request
* @return The persisted structure element (fully populated)
*/
@GET
@Path("{nodeId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getForum(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @Context HttpServletRequest httpRequest) {
ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!CourseWebService.isCourseAccessible(course, false, httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
CourseNode courseNode = course.getRunStructure().getNode(nodeId);
if (courseNode == null || !(courseNode instanceof FOCourseNode)) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
UserRequest ureq = getUserRequest(httpRequest);
CourseTreeVisitor courseVisitor = new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment());
if (courseVisitor.isAccessible(courseNode, new VisibleTreeFilter())) {
FOCourseNode forumNode = (FOCourseNode) courseNode;
Set<Long> subscriptions = new HashSet<Long>();
NotificationsManager man = NotificationsManager.getInstance();
List<String> notiTypes = Collections.singletonList("Forum");
List<Subscriber> subs = man.getSubscribers(ureq.getIdentity(), notiTypes);
for (Subscriber sub : subs) {
Long forumKey = Long.parseLong(sub.getPublisher().getData());
subscriptions.add(forumKey);
}
ForumVO forumVo = createForumVO(course, forumNode, subscriptions);
return Response.ok(forumVo).build();
} else {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
}
Aggregations