Search in sources :

Example 16 with BCCourseNode

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

the class BCWebService method getVFSWebService.

/**
 * Return the FX implementation to manage a folder.
 * @param courseId
 * @param nodeId
 * @param request
 * @return
 */
@Path("{nodeId}/files")
public VFSWebservice getVFSWebService(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @Context HttpServletRequest request) {
    boolean author = isAuthor(request);
    ICourse course = CoursesWebService.loadCourse(courseId);
    if (course == null) {
        throw new WebApplicationException(Response.serverError().status(Status.NOT_FOUND).build());
    } else if (!author && !CourseWebService.isCourseAccessible(course, false, request)) {
        throw new WebApplicationException(Response.serverError().status(Status.UNAUTHORIZED).build());
    }
    CourseNode node;
    if (author) {
        node = course.getEditorTreeModel().getCourseNode(nodeId);
    } else {
        node = course.getRunStructure().getNode(nodeId);
    }
    if (node == null) {
        throw new WebApplicationException(Response.serverError().status(Status.NOT_FOUND).build());
    } else if (!(node instanceof BCCourseNode)) {
        throw new WebApplicationException(Response.serverError().status(Status.NOT_ACCEPTABLE).build());
    }
    BCCourseNode bcNode = (BCCourseNode) node;
    UserRequest ureq = getUserRequest(request);
    VFSContainer container = BCCourseNode.getSecurisedNodeFolderContainer(bcNode, course.getCourseEnvironment(), ureq.getUserSession().getIdentityEnvironment());
    return new VFSWebservice(container);
}
Also used : BCCourseNode(org.olat.course.nodes.BCCourseNode) WebApplicationException(javax.ws.rs.WebApplicationException) VFSContainer(org.olat.core.util.vfs.VFSContainer) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) VFSWebservice(org.olat.core.util.vfs.restapi.VFSWebservice) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) Path(javax.ws.rs.Path)

Example 17 with BCCourseNode

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

the class BCWebService method getFolder.

/**
 * Retrieves metadata of the course node
 * @response.representation.200.qname {http://www.example.com}folderVO
 * @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_FOLDERVO}
 * @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 getFolder(@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 BCCourseNode)) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    UserRequest ureq = getUserRequest(httpRequest);
    boolean accessible = (new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment())).isAccessible(courseNode, new VisibleTreeFilter());
    if (accessible) {
        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());
            }
        }
        FolderVO folderVo = createFolderVO(ureq.getUserSession().getIdentityEnvironment(), course, (BCCourseNode) courseNode, subscribed);
        return Response.ok(folderVo).build();
    } else {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
}
Also used : FolderVO(org.olat.restapi.support.vo.FolderVO) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) ICourse(org.olat.course.ICourse) BCCourseNode(org.olat.course.nodes.BCCourseNode) Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) CourseNode(org.olat.course.nodes.CourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 18 with BCCourseNode

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

the class CourseEditorEnvImpl method checkFolderNodes.

private List<StatusDescription> checkFolderNodes(INode rootNode, ICourse course, List<StatusDescription> descriptions) {
    List<StatusDescription> descriptionsI = descriptions;
    Visitor visitor = new Visitor() {

        @Override
        public void visit(INode node) {
            CourseEditorTreeNode courseNode = (CourseEditorTreeNode) course.getEditorTreeModel().getNodeById(node.getIdent());
            if (!courseNode.isDeleted() && courseNode.getCourseNode() instanceof BCCourseNode) {
                BCCourseNode bcNode = (BCCourseNode) courseNode.getCourseNode();
                if (bcNode.isSharedFolder()) {
                    String translPackage = Util.getPackageName(BCCourseNodeEditController.class);
                    StatusDescription status = new StatusDescription(StatusDescription.ERROR, "warning.no.sharedfolder", "warning.no.sharedfolder", null, translPackage);
                    status.setDescriptionForUnit(bcNode.getIdent());
                    // set which pane is affected by error
                    status.setActivateableViewIdentifier(BCCourseNodeEditController.PANE_TAB_FOLDER);
                    descriptionsI.add(status);
                }
            }
        }
    };
    TreeVisitor v = new TreeVisitor(visitor, rootNode, false);
    v.visitAll();
    return descriptionsI;
}
Also used : TreeVisitor(org.olat.core.util.tree.TreeVisitor) INode(org.olat.core.util.nodes.INode) BCCourseNode(org.olat.course.nodes.BCCourseNode) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode)

Example 19 with BCCourseNode

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

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);
    }
}
Also used : OfferAccess(org.olat.resource.accesscontrol.OfferAccess) ArrayList(java.util.ArrayList) CatalogEntry(org.olat.repository.CatalogEntry) FOCourseNode(org.olat.course.nodes.FOCourseNode) PublishProcess(org.olat.course.editor.PublishProcess) StatusDescription(org.olat.course.editor.StatusDescription) RepositoryManager(org.olat.repository.RepositoryManager) FOCourseNode(org.olat.course.nodes.FOCourseNode) ENCourseNode(org.olat.course.nodes.ENCourseNode) CourseNode(org.olat.course.nodes.CourseNode) COCourseNode(org.olat.course.nodes.COCourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) SPCourseNode(org.olat.course.nodes.SPCourseNode) COCourseNode(org.olat.course.nodes.COCourseNode) Condition(org.olat.course.condition.Condition) CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) BusinessGroup(org.olat.group.BusinessGroup) SPCourseNode(org.olat.course.nodes.SPCourseNode) CourseAccessAndProperties(org.olat.course.editor.CourseAccessAndProperties) PublishSetInformations(org.olat.course.editor.PublishSetInformations) CatalogManager(org.olat.repository.manager.CatalogManager) BCCourseNode(org.olat.course.nodes.BCCourseNode) BusinessGroupService(org.olat.group.BusinessGroupService) CollaborationTools(org.olat.collaboration.CollaborationTools) ACService(org.olat.resource.accesscontrol.ACService)

Example 20 with BCCourseNode

use of org.olat.course.nodes.BCCourseNode in project OpenOLAT by OpenOLAT.

the class CoursesInfosWebService method collect.

private CourseInfoVO collect(final Identity identity, final Roles roles, final RepositoryEntry entry, final Set<Long> forumNotified, final Map<Long, Set<String>> courseNotified) {
    CourseInfoVO info = new CourseInfoVO();
    info.setRepoEntryKey(entry.getKey());
    info.setSoftKey(entry.getSoftkey());
    info.setDisplayName(entry.getDisplayname());
    ACService acManager = CoreSpringFactory.getImpl(ACService.class);
    AccessResult result = acManager.isAccessible(entry, identity, false);
    if (result.isAccessible()) {
        try {
            final ICourse course = CourseFactory.loadCourse(entry);
            final List<FolderVO> folders = new ArrayList<FolderVO>();
            final List<ForumVO> forums = new ArrayList<ForumVO>();
            final IdentityEnvironment ienv = new IdentityEnvironment(identity, roles);
            new CourseTreeVisitor(course, ienv).visit(new Visitor() {

                @Override
                public void visit(INode node) {
                    if (node instanceof BCCourseNode) {
                        BCCourseNode bcNode = (BCCourseNode) node;
                        folders.add(BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId())));
                    } else if (node instanceof FOCourseNode) {
                        FOCourseNode forumNode = (FOCourseNode) node;
                        forums.add(ForumCourseNodeWebService.createForumVO(course, forumNode, forumNotified));
                    }
                }
            }, new VisibleTreeFilter());
            info.setKey(course.getResourceableId());
            info.setTitle(course.getCourseTitle());
            info.setFolders(folders.toArray(new FolderVO[folders.size()]));
            info.setForums(forums.toArray(new ForumVO[forums.size()]));
        } catch (Exception e) {
            log.error("", e);
        }
    }
    return info;
}
Also used : ForumVO(org.olat.modules.fo.restapi.ForumVO) INode(org.olat.core.util.nodes.INode) 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) FOCourseNode(org.olat.course.nodes.FOCourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) ACService(org.olat.resource.accesscontrol.ACService) AccessResult(org.olat.resource.accesscontrol.AccessResult) CourseInfoVO(org.olat.restapi.support.vo.CourseInfoVO) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

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