Search in sources :

Example 96 with INode

use of org.olat.core.util.nodes.INode in project openolat by klemens.

the class AssessmentHelper method getAssessableNodes.

/**
 * Get all assessable nodes including the root node (if assessable)
 *
 * @param editorModel
 * @param excludeNode Node that should be excluded in the list, e.g. the
 *          current node or null if all assessable nodes should be used
 * @return List of assessable course nodes
 */
public static List<CourseNode> getAssessableNodes(final CourseEditorTreeModel editorModel, final CourseNode excludeNode) {
    CourseEditorTreeNode rootNode = (CourseEditorTreeNode) editorModel.getRootNode();
    final List<CourseNode> nodes = new ArrayList<CourseNode>();
    // visitor class: takes all assessable nodes if not the exclude node and
    // puts
    // them into the nodes list
    Visitor visitor = new Visitor() {

        @Override
        public void visit(INode node) {
            CourseEditorTreeNode editorNode = (CourseEditorTreeNode) node;
            CourseNode courseNode = editorModel.getCourseNode(node.getIdent());
            if (!editorNode.isDeleted() && (courseNode != excludeNode)) {
                if (checkIfNodeIsAssessable(courseNode)) {
                    nodes.add(courseNode);
                }
            }
        }
    };
    // not visit beginning at the root node
    TreeVisitor tv = new TreeVisitor(visitor, rootNode, false);
    tv.visitAll();
    return nodes;
}
Also used : TreeVisitor(org.olat.core.util.tree.TreeVisitor) INode(org.olat.core.util.nodes.INode) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) ArrayList(java.util.ArrayList) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) CourseNode(org.olat.course.nodes.CourseNode) ProjectBrokerCourseNode(org.olat.course.nodes.ProjectBrokerCourseNode) STCourseNode(org.olat.course.nodes.STCourseNode) ScormCourseNode(org.olat.course.nodes.ScormCourseNode)

Example 97 with INode

use of org.olat.core.util.nodes.INode 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)

Example 98 with INode

use of org.olat.core.util.nodes.INode in project openolat by klemens.

the class CourseRuntimeController method initTools.

private void initTools(Dropdown tools, ICourse course, final UserCourseEnvironmentImpl uce) {
    // 1) administrative tools
    if (reSecurity.isEntryAdmin() || reSecurity.isCourseCoach() || reSecurity.isGroupCoach() || hasCourseRight(CourseRights.RIGHT_COURSEEDITOR) || hasCourseRight(CourseRights.RIGHT_MEMBERMANAGEMENT) || hasCourseRight(CourseRights.RIGHT_GROUPMANAGEMENT) || hasCourseRight(CourseRights.RIGHT_ARCHIVING) || hasCourseRight(CourseRights.RIGHT_STATISTICS) || hasCourseRight(CourseRights.RIGHT_DB) || hasCourseRight(CourseRights.RIGHT_ASSESSMENT) || hasCourseRight(CourseRights.RIGHT_ASSESSMENT_MODE)) {
        tools.setI18nKey("header.tools");
        tools.setElementCssClass("o_sel_course_tools");
        if (uce != null && (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_COURSEEDITOR))) {
            boolean managed = RepositoryEntryManagedFlag.isManaged(getRepositoryEntry(), RepositoryEntryManagedFlag.editcontent);
            boolean readOnly = uce.isCourseReadOnly();
            editLink = LinkFactory.createToolLink("edit.cmd", translate("command.openeditor"), this, "o_icon_courseeditor");
            editLink.setElementCssClass("o_sel_course_editor");
            editLink.setEnabled(!corrupted && !managed);
            editLink.setVisible(!readOnly);
            tools.addComponent(editLink);
            folderLink = LinkFactory.createToolLink("cfd", translate("command.coursefolder"), this, "o_icon_coursefolder");
            folderLink.setElementCssClass("o_sel_course_folder");
            tools.addComponent(folderLink);
            tools.addComponent(new Spacer(""));
        }
        if (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_GROUPMANAGEMENT) || hasCourseRight(CourseRights.RIGHT_MEMBERMANAGEMENT)) {
            membersLink = LinkFactory.createToolLink("unifiedusermngt", translate("command.opensimplegroupmngt"), this, "o_icon_membersmanagement");
            membersLink.setElementCssClass("o_sel_course_members");
            tools.addComponent(membersLink);
        }
        if (reSecurity.isEntryAdmin() || reSecurity.isCourseCoach() || reSecurity.isGroupCoach() || hasCourseRight(CourseRights.RIGHT_ASSESSMENT)) {
            assessmentLink = LinkFactory.createToolLink("assessment", translate("command.openassessment"), this, "o_icon_assessment_tool");
            assessmentLink.setElementCssClass("o_sel_course_assessment_tool");
            tools.addComponent(assessmentLink);
        }
        if (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_ARCHIVING)) {
            archiverLink = LinkFactory.createToolLink("archiver", translate("command.openarchiver"), this, "o_icon_archive_tool");
            tools.addComponent(archiverLink);
        }
        tools.addComponent(new Spacer(""));
        if (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_STATISTICS)) {
            courseStatisticLink = LinkFactory.createToolLink("statistic", translate("command.openstatistic"), this, "o_icon_statistics_tool");
            tools.addComponent(courseStatisticLink);
        }
        if (uce != null && (reSecurity.isEntryAdmin() || reSecurity.isCourseCoach() || reSecurity.isGroupCoach() || hasCourseRight(CourseRights.RIGHT_STATISTICS))) {
            final AtomicInteger testNodes = new AtomicInteger();
            final AtomicInteger surveyNodes = new AtomicInteger();
            new TreeVisitor(new Visitor() {

                @Override
                public void visit(INode node) {
                    if (((CourseNode) node).isStatisticNodeResultAvailable(uce, QTIType.test, QTIType.onyx)) {
                        testNodes.incrementAndGet();
                    } else if (((CourseNode) node).isStatisticNodeResultAvailable(uce, QTIType.survey)) {
                        surveyNodes.incrementAndGet();
                    }
                }
            }, course.getRunStructure().getRootNode(), true).visitAll();
            if (testNodes.intValue() > 0) {
                testStatisticLink = LinkFactory.createToolLink("qtistatistic", translate("command.openteststatistic"), this, "o_icon_statistics_tool");
                tools.addComponent(testStatisticLink);
            }
            if (surveyNodes.intValue() > 0) {
                surveyStatisticLink = LinkFactory.createToolLink("qtistatistic", translate("command.opensurveystatistic"), this, "o_icon_statistics_tool");
                tools.addComponent(surveyStatisticLink);
            }
        }
        tools.addComponent(new Spacer(""));
        if (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_COURSEEDITOR)) {
            areaLink = LinkFactory.createToolLink("careas", translate("command.courseareas"), this, "o_icon_courseareas");
            areaLink.setElementCssClass("o_sel_course_areas");
            tools.addComponent(areaLink);
        }
        if (courseDBManager.isEnabled() && (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_DB))) {
            dbLink = LinkFactory.createToolLink("customDb", translate("command.opendb"), this, "o_icon_coursedb");
            tools.addComponent(dbLink);
        }
        ordersLink = LinkFactory.createToolLink("bookings", translate("details.orders"), this, "o_sel_repo_booking");
        ordersLink.setIconLeftCSS("o_icon o_icon-fw o_icon_booking");
        ordersLink.setElementCssClass("o_sel_course_ac_tool");
        boolean booking = acService.isResourceAccessControled(getRepositoryEntry().getOlatResource(), null);
        ordersLink.setVisible(!corrupted && booking);
        tools.addComponent(ordersLink);
    }
}
Also used : TreeVisitor(org.olat.core.util.tree.TreeVisitor) INode(org.olat.core.util.nodes.INode) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Spacer(org.olat.core.gui.components.dropdown.Dropdown.Spacer) ENCourseNode(org.olat.course.nodes.ENCourseNode) CourseNode(org.olat.course.nodes.CourseNode)

Example 99 with INode

use of org.olat.core.util.nodes.INode in project openolat by klemens.

the class CourseRuntimeController method isAllowedToLeave.

private boolean isAllowedToLeave(UserCourseEnvironmentImpl uce) {
    if (uce.getParticipatingGroups().size() > 0) {
        CourseNode rootNode = uce.getCourseEnvironment().getRunStructure().getRootNode();
        OLATResource courseResource = uce.getCourseEnvironment().getCourseGroupManager().getCourseResource();
        AtomicBoolean bool = new AtomicBoolean(false);
        new TreeVisitor(new Visitor() {

            @Override
            public void visit(INode node) {
                if (!bool.get() && node instanceof ENCourseNode) {
                    try {
                        ENCourseNode enNode = (ENCourseNode) node;
                        boolean cancelEnrollEnabled = enNode.getModuleConfiguration().getBooleanSafe(ENCourseNode.CONF_CANCEL_ENROLL_ENABLED);
                        if (!cancelEnrollEnabled && enNode.isUsedForEnrollment(uce.getParticipatingGroups(), courseResource)) {
                            bool.set(true);
                        }
                    } catch (Exception e) {
                        logError("", e);
                    }
                }
            }
        }, rootNode, true).visitAll();
        if (bool.get()) {
            // is in a enrollment group
            return false;
        }
    }
    return (uce.isParticipant() || !uce.getParticipatingGroups().isEmpty());
}
Also used : TreeVisitor(org.olat.core.util.tree.TreeVisitor) ENCourseNode(org.olat.course.nodes.ENCourseNode) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) INode(org.olat.core.util.nodes.INode) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) OLATResource(org.olat.resource.OLATResource) ENCourseNode(org.olat.course.nodes.ENCourseNode) CourseNode(org.olat.course.nodes.CourseNode) OLATSecurityException(org.olat.core.logging.OLATSecurityException)

Example 100 with INode

use of org.olat.core.util.nodes.INode in project openolat by klemens.

the class NavigationHandler method addSubTreeModel.

private void addSubTreeModel(TreeNode parent, TreeModel modelToAppend) {
    // ignore root and directly add children.
    // need to clone children so that are not detached from their original
    // parent (which is the cp treemodel)
    // parent.addChild(modelToAppend.getRootNode());
    TreeNode root = modelToAppend.getRootNode();
    int chdCnt = root.getChildCount();
    // full cloning of ETH webclass energie takes about 4/100 of a second
    for (int i = chdCnt; i > 0; i--) {
        INode chd = root.getChildAt(i - 1);
        INode chdc = (INode) XStreamHelper.xstreamClone(chd);
        if (chdc instanceof GenericTreeNode) {
            ((GenericTreeNode) chdc).setIdent(chd.getIdent());
        }
        // always insert before already existing course building block children
        parent.insert(chdc, 0);
    }
    copyIdent(parent, root);
}
Also used : INode(org.olat.core.util.nodes.INode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode)

Aggregations

INode (org.olat.core.util.nodes.INode)106 Visitor (org.olat.core.util.tree.Visitor)44 CourseNode (org.olat.course.nodes.CourseNode)44 ICourse (org.olat.course.ICourse)40 TreeVisitor (org.olat.core.util.tree.TreeVisitor)30 ArrayList (java.util.ArrayList)28 Identity (org.olat.core.id.Identity)26 CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)24 TreeNode (org.olat.core.gui.components.tree.TreeNode)18 RepositoryEntry (org.olat.repository.RepositoryEntry)18 Test (org.junit.Test)16 BCCourseNode (org.olat.course.nodes.BCCourseNode)14 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)14 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)14 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)12 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)12 CourseEditorTreeModel (org.olat.course.tree.CourseEditorTreeModel)12 HashMap (java.util.HashMap)10 FOCourseNode (org.olat.course.nodes.FOCourseNode)10 GET (javax.ws.rs.GET)8