Search in sources :

Example 46 with TreeVisitor

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

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 47 with TreeVisitor

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

the class ModifyCourseEvent method archiveCourse.

/**
 * visit all nodes in the specified course and make them archiving any data
 * into the identity's export directory.
 *
 * @param res
 * @param charset
 * @param locale
 * @param identity
 */
public static void archiveCourse(Identity archiveOnBehalfOf, ICourse course, String charset, Locale locale, File exportDirectory, boolean isOLATAdmin, boolean... oresRights) {
    // archive course results overview
    List<Identity> users = ScoreAccountingHelper.loadUsers(course.getCourseEnvironment());
    List<AssessableCourseNode> nodes = ScoreAccountingHelper.loadAssessableNodes(course.getCourseEnvironment());
    String fileName = ExportUtil.createFileNameWithTimeStamp(course.getCourseTitle(), "zip");
    try (OutputStream out = new FileOutputStream(new File(exportDirectory, fileName));
        ZipOutputStream zout = new ZipOutputStream(out)) {
        ScoreAccountingHelper.createCourseResultsOverview(users, nodes, course, locale, zout);
    } catch (IOException e) {
        log.error("", e);
    }
    // archive all nodes content
    Visitor archiveV = new NodeArchiveVisitor(locale, course, exportDirectory, charset);
    TreeVisitor tv = new TreeVisitor(archiveV, course.getRunStructure().getRootNode(), true);
    tv.visitAll();
    // archive all course log files
    // OLATadmin gets all logfiles independent of the visibility configuration
    boolean isOresOwner = (oresRights.length > 0) ? oresRights[0] : false;
    boolean isOresInstitutionalManager = (oresRights.length > 1) ? oresRights[1] : false;
    boolean aLogV = isOresOwner || isOresInstitutionalManager || isOLATAdmin;
    boolean uLogV = isOLATAdmin;
    boolean sLogV = isOresOwner || isOresInstitutionalManager || isOLATAdmin;
    // make an intermediate commit here to make sure long running course log export doesn't
    // cause db connection timeout to be triggered
    // @TODO transactions/backgroundjob:
    // rework when backgroundjob infrastructure exists
    DBFactory.getInstance().intermediateCommit();
    AsyncExportManager.getInstance().asyncArchiveCourseLogFiles(archiveOnBehalfOf, new Runnable() {

        @Override
        public void run() {
        // that's fine, I dont need to do anything here
        }
    }, course.getResourceableId(), exportDirectory.getPath(), null, null, aLogV, uLogV, sLogV, charset, null, null);
    course.getCourseEnvironment().getCourseGroupManager().archiveCourseGroups(exportDirectory);
    CoreSpringFactory.getImpl(ChatLogHelper.class).archive(course, exportDirectory);
}
Also used : ChatLogHelper(org.olat.instantMessaging.manager.ChatLogHelper) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) TreeVisitor(org.olat.core.util.tree.TreeVisitor) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) Identity(org.olat.core.id.Identity) File(java.io.File)

Example 48 with TreeVisitor

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

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

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

Aggregations

TreeVisitor (org.olat.core.util.tree.TreeVisitor)52 Visitor (org.olat.core.util.tree.Visitor)42 INode (org.olat.core.util.nodes.INode)30 CourseNode (org.olat.course.nodes.CourseNode)24 ArrayList (java.util.ArrayList)14 CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)14 Identity (org.olat.core.id.Identity)10 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)10 ICourse (org.olat.course.ICourse)7 File (java.io.File)6 HashMap (java.util.HashMap)6 List (java.util.List)6 BCCourseNode (org.olat.course.nodes.BCCourseNode)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)5 STCourseNode (org.olat.course.nodes.STCourseNode)5 ScormCourseNode (org.olat.course.nodes.ScormCourseNode)5 TACourseNode (org.olat.course.nodes.TACourseNode)5 IOException (java.io.IOException)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 CorruptedCourseException (org.olat.course.CorruptedCourseException)4