Search in sources :

Example 26 with BCCourseNode

use of org.olat.course.nodes.BCCourseNode 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;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) INode(org.olat.core.util.nodes.INode) Message(org.olat.modules.fo.Message) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) OLATResourceable(org.olat.core.id.OLATResourceable) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) OLATResource(org.olat.resource.OLATResource) FOCourseNode(org.olat.course.nodes.FOCourseNode) RepositoryEntry(org.olat.repository.RepositoryEntry) IOException(java.io.IOException) URL(java.net.URL) Forum(org.olat.modules.fo.Forum) TreeVisitor(org.olat.core.util.tree.TreeVisitor) OlatNamedContainerImpl(org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) BCCourseNode(org.olat.course.nodes.BCCourseNode) CollaborationTools(org.olat.collaboration.CollaborationTools) OLATResourceManager(org.olat.resource.OLATResourceManager) Identity(org.olat.core.id.Identity) File(java.io.File) Before(org.junit.Before)

Example 27 with BCCourseNode

use of org.olat.course.nodes.BCCourseNode in project openolat by klemens.

the class UserFoldersWebService method getFolders.

/**
 * Retrieves a list of folders on a user base. All folders of groups
 * where the user is participant/tutor + all folders in course where
 * the user is a participant (owner, tutor or participant)
 * @response.representation.200.qname {http://www.example.com}folderVOes
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The folders
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_FOLDERVOes}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param identityKey The key of the user (IdentityImpl)
 * @param httpRequest The HTTP request
 * @return The folders
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getFolders(@Context HttpServletRequest httpRequest) {
    Roles roles;
    Identity ureqIdentity = getIdentity(httpRequest);
    if (ureqIdentity == null) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    } else if (!identity.getKey().equals(ureqIdentity.getKey())) {
        if (isAdmin(httpRequest)) {
            ureqIdentity = identity;
            roles = BaseSecurityManager.getInstance().getRoles(identity);
        } else {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
    } else {
        roles = getRoles(httpRequest);
    }
    final Map<Long, Long> groupNotified = new HashMap<Long, Long>();
    final Map<Long, Collection<String>> courseNotified = new HashMap<Long, Collection<String>>();
    NotificationsManager man = NotificationsManager.getInstance();
    {
        // collect subscriptions
        List<String> notiTypes = Collections.singletonList("FolderModule");
        List<Subscriber> subs = man.getSubscribers(ureqIdentity, notiTypes);
        for (Subscriber sub : subs) {
            String resName = sub.getPublisher().getResName();
            if ("BusinessGroup".equals(resName)) {
                Long groupKey = sub.getPublisher().getResId();
                groupNotified.put(groupKey, sub.getPublisher().getResId());
            } else if ("CourseModule".equals(resName)) {
                Long courseKey = sub.getPublisher().getResId();
                if (!courseNotified.containsKey(courseKey)) {
                    courseNotified.put(courseKey, new ArrayList<String>());
                }
                courseNotified.get(courseKey).add(sub.getPublisher().getSubidentifier());
            }
        }
    }
    final List<FolderVO> folderVOs = new ArrayList<FolderVO>();
    final IdentityEnvironment ienv = new IdentityEnvironment(ureqIdentity, roles);
    for (Map.Entry<Long, Collection<String>> e : courseNotified.entrySet()) {
        final Long courseKey = e.getKey();
        final Collection<String> nodeKeys = e.getValue();
        final ICourse course = CourseFactory.loadCourse(courseKey);
        new CourseTreeVisitor(course, ienv).visit(new Visitor() {

            @Override
            public void visit(INode node) {
                if (node instanceof BCCourseNode) {
                    BCCourseNode bcNode = (BCCourseNode) node;
                    if (nodeKeys.contains(bcNode.getIdent())) {
                        FolderVO folder = BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId()));
                        folderVOs.add(folder);
                    }
                }
            }
        }, new VisibleTreeFilter());
    }
    /*
		RepositoryManager rm = RepositoryManager.getInstance();
		ACService acManager = CoreSpringFactory.getImpl(ACService.class);
		SearchRepositoryEntryParameters repoParams = new SearchRepositoryEntryParameters(retrievedUser, roles, "CourseModule");
		repoParams.setOnlyExplicitMember(true);
		List<RepositoryEntry> entries = rm.genericANDQueryWithRolesRestriction(repoParams, 0, -1, true);
		for(RepositoryEntry entry:entries) {
			AccessResult result = acManager.isAccessible(entry, retrievedUser, false);
			if(result.isAccessible()) {
				try {
					final ICourse course = CourseFactory.loadCourse(entry.getOlatResource());
					final IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles);
					
					new CourseTreeVisitor(course,  ienv).visit(new Visitor() {
						@Override
						public void visit(INode node) {
							if(node instanceof BCCourseNode) {
								BCCourseNode bcNode = (BCCourseNode)node;
								FolderVO folder = BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId()));
								folderVOs.add(folder);
							}
						}
					});
				} catch (Exception e) {
					log.error("", e);
				}
			}
		}*/
    // start found forums in groups
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    SearchBusinessGroupParams params = new SearchBusinessGroupParams(ureqIdentity, true, true);
    params.addTools(CollaborationTools.TOOL_FOLDER);
    List<BusinessGroup> groups = bgs.findBusinessGroups(params, null, 0, -1);
    for (BusinessGroup group : groups) {
        CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group);
        VFSContainer container = tools.getSecuredFolder(group, null, ureqIdentity, false);
        FolderVO folderVo = new FolderVO();
        folderVo.setName(group.getName());
        folderVo.setGroupKey(group.getKey());
        folderVo.setSubscribed(groupNotified.containsKey(group.getKey()));
        folderVo.setRead(container.getLocalSecurityCallback().canRead());
        folderVo.setList(container.getLocalSecurityCallback().canList());
        folderVo.setWrite(container.getLocalSecurityCallback().canWrite());
        folderVo.setDelete(container.getLocalSecurityCallback().canDelete());
        folderVOs.add(folderVo);
    }
    FolderVOes voes = new FolderVOes();
    voes.setFolders(folderVOs.toArray(new FolderVO[folderVOs.size()]));
    voes.setTotalCount(folderVOs.size());
    return Response.ok(voes).build();
}
Also used : INode(org.olat.core.util.nodes.INode) FolderVOes(org.olat.restapi.support.vo.FolderVOes) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) HashMap(java.util.HashMap) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) Subscriber(org.olat.core.commons.services.notifications.Subscriber) List(java.util.List) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) FolderVO(org.olat.restapi.support.vo.FolderVO) BusinessGroup(org.olat.group.BusinessGroup) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) VFSContainer(org.olat.core.util.vfs.VFSContainer) Roles(org.olat.core.id.Roles) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) BCCourseNode(org.olat.course.nodes.BCCourseNode) BusinessGroupService(org.olat.group.BusinessGroupService) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) CollaborationTools(org.olat.collaboration.CollaborationTools) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 28 with BCCourseNode

use of org.olat.course.nodes.BCCourseNode 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;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) INode(org.olat.core.util.nodes.INode) Message(org.olat.modules.fo.Message) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) OLATResourceable(org.olat.core.id.OLATResourceable) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) OLATResource(org.olat.resource.OLATResource) FOCourseNode(org.olat.course.nodes.FOCourseNode) RepositoryEntry(org.olat.repository.RepositoryEntry) IOException(java.io.IOException) URL(java.net.URL) Forum(org.olat.modules.fo.Forum) TreeVisitor(org.olat.core.util.tree.TreeVisitor) OlatNamedContainerImpl(org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) BCCourseNode(org.olat.course.nodes.BCCourseNode) CollaborationTools(org.olat.collaboration.CollaborationTools) OLATResourceManager(org.olat.resource.OLATResourceManager) Identity(org.olat.core.id.Identity) File(java.io.File) Before(org.junit.Before)

Example 29 with BCCourseNode

use of org.olat.course.nodes.BCCourseNode in project openolat by klemens.

the class MergedCourseContainer method addFoldersForAdmin.

/**
 * 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
 * @return container for the current course node
 */
private void addFoldersForAdmin(PersistingCourseImpl course, MergeSource nodesContainer, CourseNode courseNode) {
    for (int i = 0; i < courseNode.getChildCount(); i++) {
        CourseNode child = (CourseNode) courseNode.getChildAt(i);
        String folderName = RequestUtil.normalizeFilename(child.getShortTitle());
        if (child instanceof BCCourseNode) {
            final BCCourseNode bcNode = (BCCourseNode) child;
            // add folder not to merge source. Use name and node id to have unique name
            VFSContainer rootFolder = getBCContainer(course, bcNode, null, true);
            if (courseReadOnly) {
                rootFolder.setLocalSecurityCallback(new ReadOnlyCallback());
            }
            folderName = getFolderName(nodesContainer, bcNode, folderName);
            if (rootFolder != null) {
                // Create a container for this node content and wrap it with a merge source which is attached to tree
                VFSContainer nodeContentContainer = new NamedContainerImpl(folderName, rootFolder);
                MergeSource courseNodeContainer = new MergeSource(nodesContainer, folderName);
                courseNodeContainer.addContainersChildren(nodeContentContainer, true);
                nodesContainer.addContainer(courseNodeContainer);
                // Do recursion for all children
                addFoldersForAdmin(course, courseNodeContainer, child);
            }
        } else if (child instanceof PFCourseNode) {
            final PFCourseNode pfNode = (PFCourseNode) child;
            // add folder not to merge source. Use name and node id to have unique name
            PFManager pfManager = CoreSpringFactory.getImpl(PFManager.class);
            folderName = getFolderName(nodesContainer, pfNode, folderName);
            MergeSource courseNodeContainer = new MergeSource(nodesContainer, folderName);
            VFSContainer rootFolder = pfManager.provideAdminContainer(pfNode, course.getCourseEnvironment());
            VFSContainer nodeContentContainer = new NamedContainerImpl(folderName, rootFolder);
            courseNodeContainer.addContainersChildren(nodeContentContainer, true);
            nodesContainer.addContainer(courseNodeContainer);
            // Do recursion for all children
            addFoldersForAdmin(course, courseNodeContainer, child);
        } else {
            // For non-folder course nodes, add merge source (no files to show) ...
            MergeSource courseNodeContainer = new MergeSource(null, folderName);
            // , then do recursion for all children ...
            addFoldersForAdmin(course, courseNodeContainer, child);
            // ... but only add this container if it contains any children with at least one BC course node
            if (!courseNodeContainer.getItems().isEmpty()) {
                nodesContainer.addContainer(courseNodeContainer);
            }
        }
    }
}
Also used : PFCourseNode(org.olat.course.nodes.PFCourseNode) PFManager(org.olat.course.nodes.pf.manager.PFManager) BCCourseNode(org.olat.course.nodes.BCCourseNode) MergeSource(org.olat.core.util.vfs.MergeSource) ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) VFSContainer(org.olat.core.util.vfs.VFSContainer) PFCourseNode(org.olat.course.nodes.PFCourseNode) CourseNode(org.olat.course.nodes.CourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl)

Example 30 with BCCourseNode

use of org.olat.course.nodes.BCCourseNode in project openolat by klemens.

the class BCWebService method getFolders.

/**
 * Retrieves metadata of the course node
 * @response.representation.200.qname {http://www.example.com}folderVOes
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The course node metadatas
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_FOLDERVOes}
 * @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
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getFolders(@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();
    }
    final UserRequest ureq = getUserRequest(httpRequest);
    RepositoryEntry entry = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
    ACService acManager = CoreSpringFactory.getImpl(ACService.class);
    AccessResult result = acManager.isAccessible(entry, ureq.getIdentity(), false);
    if (!result.isAccessible()) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    final Set<String> subscribed = new HashSet<String>();
    NotificationsManager man = NotificationsManager.getInstance();
    List<String> notiTypes = Collections.singletonList("FolderModule");
    List<Subscriber> subs = man.getSubscribers(ureq.getIdentity(), notiTypes);
    for (Subscriber sub : subs) {
        Long courseKey = sub.getPublisher().getResId();
        if (courseId.equals(courseKey)) {
            subscribed.add(sub.getPublisher().getSubidentifier());
            break;
        }
    }
    final List<FolderVO> folderVOs = new ArrayList<FolderVO>();
    new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment()).visit(new Visitor() {

        @Override
        public void visit(INode node) {
            if (node instanceof BCCourseNode) {
                BCCourseNode bcNode = (BCCourseNode) node;
                FolderVO folder = createFolderVO(ureq.getUserSession().getIdentityEnvironment(), course, bcNode, subscribed);
                folderVOs.add(folder);
            }
        }
    }, new VisibleTreeFilter());
    FolderVOes voes = new FolderVOes();
    voes.setFolders(folderVOs.toArray(new FolderVO[folderVOs.size()]));
    voes.setTotalCount(folderVOs.size());
    return Response.ok(voes).build();
}
Also used : INode(org.olat.core.util.nodes.INode) FolderVOes(org.olat.restapi.support.vo.FolderVOes) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) FolderVO(org.olat.restapi.support.vo.FolderVO) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) BCCourseNode(org.olat.course.nodes.BCCourseNode) Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) ACService(org.olat.resource.accesscontrol.ACService) AccessResult(org.olat.resource.accesscontrol.AccessResult) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) HashSet(java.util.HashSet) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

BCCourseNode (org.olat.course.nodes.BCCourseNode)30 INode (org.olat.core.util.nodes.INode)14 Visitor (org.olat.core.util.tree.Visitor)14 VFSContainer (org.olat.core.util.vfs.VFSContainer)14 ICourse (org.olat.course.ICourse)14 CourseNode (org.olat.course.nodes.CourseNode)12 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)10 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)10 ArrayList (java.util.ArrayList)8 Identity (org.olat.core.id.Identity)8 FOCourseNode (org.olat.course.nodes.FOCourseNode)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 FolderVO (org.olat.restapi.support.vo.FolderVO)8 GET (javax.ws.rs.GET)6 Produces (javax.ws.rs.Produces)6 HttpResponse (org.apache.http.HttpResponse)6 HttpGet (org.apache.http.client.methods.HttpGet)6 Test (org.junit.Test)6 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)6 Subscriber (org.olat.core.commons.services.notifications.Subscriber)6