Search in sources :

Example 1 with TreeVisitor

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

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

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

the class EditorMainController method doCreateAlternateBuildingBlock.

/**
 * The following operation are done:
 * <ul>
 * 	<li>create a new instance of the replacement type
 * 	<li>add the new element below the original element
 * 	<li>copy the element title, description and the generic configuration options
 * 	<li>copy the access, visibility and scoring rules (easy and expert)
 * 	<li>optionally copy some other configuration if this is possible at all
 * 	<li>move all child elements from the original to the replacement element
 * 	<li>mark the original element as deleted
 * </ul>
 *
 * @param chosenNode
 * @param selectAlternative
 */
private void doCreateAlternateBuildingBlock(UserRequest ureq, ICourse course, CourseNode chosenNode, String selectAlternative) {
    if (!StringHelper.containsNonWhitespace(selectAlternative))
        return;
    // create the alternative node
    CourseNodeConfiguration newConfig = CourseNodeFactory.getInstance().getCourseNodeConfiguration(selectAlternative);
    CourseNode newNode = newConfig.getInstance();
    // copy configurations
    chosenNode.copyConfigurationTo(newNode, course);
    // insert the node
    CourseEditorTreeNode cetn = (CourseEditorTreeNode) cetm.getNodeById(chosenNode.getIdent());
    CourseEditorTreeNode parentNode = (CourseEditorTreeNode) cetn.getParent();
    int position = cetn.getPosition() + 1;
    CourseEditorTreeNode newCetn = course.getEditorTreeModel().insertCourseNodeAt(newNode, parentNode.getCourseNode(), position);
    doInsert(ureq, newNode);
    // copy the children
    while (cetn.getChildCount() > 0) {
        CourseEditorTreeNode childNode = (CourseEditorTreeNode) cetn.getChildAt(0);
        newCetn.addChild(childNode);
    }
    // set all dirty
    TreeVisitor tv = new TreeVisitor(new Visitor() {

        public void visit(INode node) {
            ((CourseEditorTreeNode) node).setDirty(true);
        }
    }, newCetn, true);
    tv.visitAll();
    // mark as deleted
    doDelete(course, chosenNode.getIdent());
    // save
    CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
}
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) CourseNodeConfiguration(org.olat.course.nodes.CourseNodeConfiguration) CourseNode(org.olat.course.nodes.CourseNode)

Example 3 with TreeVisitor

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

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

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

the class HomeCalendarManager method isCourseCalendarEnabled.

private boolean isCourseCalendarEnabled(ICourse course) {
    if (course.getCourseConfig().isCalendarEnabled()) {
        return true;
    }
    CourseNode rootNode = course.getRunStructure().getRootNode();
    CalCourseNodeVisitor v = new CalCourseNodeVisitor();
    new TreeVisitor(v, rootNode, true).visitAll();
    return v.isFound();
}
Also used : TreeVisitor(org.olat.core.util.tree.TreeVisitor) CourseNode(org.olat.course.nodes.CourseNode) CalCourseNode(org.olat.course.nodes.CalCourseNode)

Example 5 with TreeVisitor

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

the class ForumArchiveManager method formatThread.

/**
 * @param mn
 * @param forumFormatter
 * @param metaInfo
 * @return
 */
private String formatThread(MessageNode mn, ForumFormatter forumFormatter, Long forumId) {
    forumFormatter.setForumKey(forumId);
    StringBuilder formattedThread = new StringBuilder();
    forumFormatter.openThread();
    TreeVisitor tv = new TreeVisitor(forumFormatter, mn, false);
    tv.visitAll();
    return formattedThread.append(formattedThread.append(forumFormatter.closeThread())).toString();
}
Also used : TreeVisitor(org.olat.core.util.tree.TreeVisitor)

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