Search in sources :

Example 31 with Visitor

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

the class CourseEditorEnvImpl method listCycles.

/**
 * @see org.olat.course.editor.CourseEditorEnv#listCycles()
 */
@Override
public Set<String> listCycles() {
    /*
		 * convert nodeRefs datastructure to a directed graph 
		 */
    DirectedGraph dg = new DefaultDirectedGraph();
    DirectedEdgeFactory def = new EdgeFactories.DirectedEdgeFactory();
    /*
		 * add the course structure as directed graph, where 
		 */
    Visitor v = new Convert2DGVisitor(dg);
    (new TreeVisitor(v, cetm.getRootNode(), true)).visitAll();
    /*
		 * iterate over nodeRefs, add each not existing node id as vertex, for each
		 * key - child relation add an edge to the directed graph.
		 */
    Map<String, Set<String>> nodeSoftRefs = new HashMap<>();
    for (Iterator<String> iter = softRefs.keySet().iterator(); iter.hasNext(); ) {
        String nodeId = iter.next();
        List<ConditionExpression> conditionExprs = softRefs.get(nodeId);
        for (int i = 0; i < conditionExprs.size(); i++) {
            ConditionExpression ce = conditionExprs.get(i);
            Set<String> refs = ce.getSoftReferencesForCycleDetectorOf("courseNodeId");
            if (refs != null && refs.size() > 0) {
                if (nodeSoftRefs.containsKey(nodeId)) {
                    nodeSoftRefs.get(nodeId).addAll(refs);
                } else {
                    nodeSoftRefs.put(nodeId, refs);
                }
            }
        }
    }
    for (Iterator<String> keys = nodeSoftRefs.keySet().iterator(); keys.hasNext(); ) {
        // a node
        String key = keys.next();
        if (!dg.containsVertex(key)) {
            dg.addVertex(key);
        }
        // and its children
        Set<String> children = nodeSoftRefs.get(key);
        for (Iterator<String> childrenIt = children.iterator(); childrenIt.hasNext(); ) {
            String child = childrenIt.next();
            if (!dg.containsVertex(child)) {
                dg.addVertex(child);
            }
            // add edge, precondition: vertex key - child are already added to the graph
            Edge de = def.createEdge(key, child);
            dg.addEdge(de);
        }
    }
    /*
		 * find the id's participating in the cycle, and return the intersection
		 * with set of id's which actually produce references.
		 */
    CycleDetector cd = new CycleDetector(dg);
    Set<String> cycleIds = cd.findCycles();
    cycleIds.retainAll(nodeSoftRefs.keySet());
    return cycleIds;
}
Also used : Set(java.util.Set) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) DefaultDirectedGraph(org._3pq.jgrapht.graph.DefaultDirectedGraph) HashMap(java.util.HashMap) CycleDetector(org._3pq.jgrapht.alg.CycleDetector) TreeVisitor(org.olat.core.util.tree.TreeVisitor) DefaultDirectedGraph(org._3pq.jgrapht.graph.DefaultDirectedGraph) DirectedGraph(org._3pq.jgrapht.DirectedGraph) DirectedEdgeFactory(org._3pq.jgrapht.edge.EdgeFactories.DirectedEdgeFactory) ConditionExpression(org.olat.course.condition.interpreter.ConditionExpression) Edge(org._3pq.jgrapht.Edge)

Example 32 with Visitor

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

the class CourseEditorEnvImpl method validateCourse.

/**
 * @see org.olat.course.editor.CourseEditorEnv#validateCourse()
 */
@Override
public void validateCourse() {
    /*
		 * collect all condition error messages and soft references collect all
		 * configuration errors.
		 */
    String currentNodeWas = currentCourseNodeId;
    // reset all
    softRefs = new HashMap<String, List<ConditionExpression>>();
    Visitor v = new CollectConditionExpressionsVisitor();
    (new TreeVisitor(v, cetm.getRootNode(), true)).visitAll();
    // refresh,create status descriptions of the course
    statusDescs = new HashMap<String, List<StatusDescription>>();
    v = new CollectStatusDescriptionVisitor(this);
    (new TreeVisitor(v, cetm.getRootNode(), true)).visitAll();
    // 
    currentCourseNodeId = currentNodeWas;
}
Also used : TreeVisitor(org.olat.core.util.tree.TreeVisitor) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) ArrayList(java.util.ArrayList) List(java.util.List)

Example 33 with Visitor

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

the class CourseOptionsController method checkFolderNodes.

private boolean checkFolderNodes(INode rootNode, ICourse course) {
    hasFolderNode = false;
    Visitor visitor = new Visitor() {

        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()) {
                    hasFolderNode = true;
                }
            }
        }
    };
    TreeVisitor v = new TreeVisitor(visitor, rootNode, false);
    v.visitAll();
    return hasFolderNode;
}
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 34 with Visitor

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

the class ModifyCourseEvent method deleteCourse.

/**
 * Delete a course including its course folder and all references to resources
 * this course holds.
 *
 * @param res
 */
public static void deleteCourse(RepositoryEntry entry, OLATResource res) {
    final long start = System.currentTimeMillis();
    log.info("deleteCourse: starting to delete course. res=" + res);
    PersistingCourseImpl course = null;
    try {
        course = (PersistingCourseImpl) loadCourse(res);
    } catch (CorruptedCourseException e) {
        log.error("Try to delete a corrupted course, I make want I can.");
    }
    // call cleanupOnDelete for nodes
    if (course != null) {
        Visitor visitor = new NodeDeletionVisitor(course);
        TreeVisitor tv = new TreeVisitor(visitor, course.getRunStructure().getRootNode(), true);
        tv.visitAll();
    }
    // delete assessment notifications
    OLATResourceable assessmentOres = OresHelper.createOLATResourceableInstance(CourseModule.ORES_COURSE_ASSESSMENT, res.getResourceableId());
    NotificationsManager.getInstance().deletePublishersOf(assessmentOres);
    // delete all course notifications
    NotificationsManager.getInstance().deletePublishersOf(res);
    // delete calendar subscription
    clearCalenderSubscriptions(res, course);
    // the course folder which is deleted right after)
    if (course != null) {
        CourseConfigManagerImpl.getInstance().deleteConfigOf(course);
    }
    CoreSpringFactory.getImpl(TaskExecutorManager.class).delete(res);
    // delete course group- and rightmanagement
    CourseGroupManager courseGroupManager = PersistingCourseGroupManager.getInstance(res);
    courseGroupManager.deleteCourseGroupmanagement();
    // delete all remaining course properties
    CoursePropertyManager propertyManager = PersistingCoursePropertyManager.getInstance(res);
    propertyManager.deleteAllCourseProperties();
    // delete course calendar
    CoreSpringFactory.getImpl(ImportToCalendarManager.class).deleteCourseImportedCalendars(res);
    CoreSpringFactory.getImpl(CalendarManager.class).deleteCourseCalendar(res);
    // delete IM messages
    CoreSpringFactory.getImpl(InstantMessagingService.class).deleteMessages(res);
    // delete tasks
    CoreSpringFactory.getImpl(GTAManager.class).deleteAllTaskLists(entry);
    // cleanup cache
    removeFromCache(res.getResourceableId());
    // TODO: ld: broadcast event: DeleteCourseEvent
    // Everything is deleted, so we could get rid of course logging
    // with the change in user audit logging - which now all goes into a DB
    // we no longer do this though!
    // delete course directory
    VFSContainer fCourseBasePath = getCourseBaseContainer(res.getResourceableId());
    VFSStatus status = fCourseBasePath.deleteSilently();
    boolean deletionSuccessful = (status == VFSConstants.YES || status == VFSConstants.SUCCESS);
    log.info("deleteCourse: finished deletion. res=" + res + ", deletion successful: " + deletionSuccessful + ", duration: " + (System.currentTimeMillis() - start) + " ms.");
}
Also used : TaskExecutorManager(org.olat.core.commons.services.taskexecutor.TaskExecutorManager) CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) PersistingCourseGroupManager(org.olat.course.groupsandrights.PersistingCourseGroupManager) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) OLATResourceable(org.olat.core.id.OLATResourceable) VFSContainer(org.olat.core.util.vfs.VFSContainer) InstantMessagingService(org.olat.instantMessaging.InstantMessagingService) ImportToCalendarManager(org.olat.commons.calendar.manager.ImportToCalendarManager) TreeVisitor(org.olat.core.util.tree.TreeVisitor) ImportToCalendarManager(org.olat.commons.calendar.manager.ImportToCalendarManager) CalendarManager(org.olat.commons.calendar.CalendarManager) VFSStatus(org.olat.core.util.vfs.VFSStatus) GTAManager(org.olat.course.nodes.gta.GTAManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 35 with Visitor

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

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

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