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);
}
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());
}
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;
}
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();
}
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();
}
Aggregations