Search in sources :

Example 51 with Visitor

use of org.olat.core.util.tree.Visitor 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 52 with Visitor

use of org.olat.core.util.tree.Visitor 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 53 with Visitor

use of org.olat.core.util.tree.Visitor 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 54 with Visitor

use of org.olat.core.util.tree.Visitor 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 55 with Visitor

use of org.olat.core.util.tree.Visitor in project openolat by klemens.

the class StatisticCourseNodesController method buildTreeModel.

private TreeModel buildTreeModel(final UserRequest ureq, final UserCourseEnvironment userCourseEnv) {
    final GenericTreeModel gtm = new GenericTreeModel();
    final GenericTreeNode rootTreeNode = new GenericTreeNode();
    rootTreeNode.setTitle("start");
    gtm.setRootNode(rootTreeNode);
    ICourse course = CourseFactory.loadCourse(userCourseEnv.getCourseEnvironment().getCourseResourceableId());
    new TreeVisitor(new Visitor() {

        @Override
        public void visit(INode node) {
            CourseNode courseNode = (CourseNode) node;
            StatisticResourceResult result = courseNode.createStatisticNodeResult(ureq, getWindowControl(), userCourseEnv, options, types);
            if (result != null) {
                StatisticResourceNode courseNodeTreeNode = new StatisticResourceNode(courseNode, result);
                rootTreeNode.addChild(courseNodeTreeNode);
                TreeModel subTreeModel = result.getSubTreeModel();
                if (subTreeModel != null) {
                    TreeNode subRootNode = subTreeModel.getRootNode();
                    List<INode> subNodes = new ArrayList<>();
                    for (int i = 0; i < subRootNode.getChildCount(); i++) {
                        subNodes.add(subRootNode.getChildAt(i));
                    }
                    for (INode subNode : subNodes) {
                        courseNodeTreeNode.addChild(subNode);
                    }
                }
            }
        }
    }, course.getRunStructure().getRootNode(), true).visitAll();
    return gtm;
}
Also used : INode(org.olat.core.util.nodes.INode) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) TreeVisitor(org.olat.core.util.tree.TreeVisitor) TreeModel(org.olat.core.gui.components.tree.TreeModel) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) CourseNode(org.olat.course.nodes.CourseNode)

Aggregations

Visitor (org.olat.core.util.tree.Visitor)56 INode (org.olat.core.util.nodes.INode)44 TreeVisitor (org.olat.core.util.tree.TreeVisitor)42 ArrayList (java.util.ArrayList)24 ICourse (org.olat.course.ICourse)20 CourseNode (org.olat.course.nodes.CourseNode)20 Identity (org.olat.core.id.Identity)14 BCCourseNode (org.olat.course.nodes.BCCourseNode)14 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)14 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)14 CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)14 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)12 HashMap (java.util.HashMap)10 FOCourseNode (org.olat.course.nodes.FOCourseNode)10 File (java.io.File)8 List (java.util.List)8 GET (javax.ws.rs.GET)8 Produces (javax.ws.rs.Produces)8 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)8 Subscriber (org.olat.core.commons.services.notifications.Subscriber)8