use of org.olat.core.util.tree.Visitor in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_11_0_0 method hasAssessableSTCourseNode.
private List<STCourseNode> hasAssessableSTCourseNode(ICourse course) {
List<STCourseNode> assessableSTNodes = new ArrayList<>();
CourseNode rootNode = course.getRunStructure().getRootNode();
new TreeVisitor(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof STCourseNode) {
STCourseNode stNode = (STCourseNode) node;
ScoreCalculator calculator = stNode.getScoreCalculator();
if (StringHelper.containsNonWhitespace(calculator.getPassedExpression())) {
assessableSTNodes.add(stNode);
} else if (StringHelper.containsNonWhitespace(calculator.getScoreExpression())) {
assessableSTNodes.add(stNode);
}
}
}
}, rootNode, true).visitAll();
return assessableSTNodes;
}
use of org.olat.core.util.tree.Visitor in project OpenOLAT by OpenOLAT.
the class PublishProcess method calculatePublishSet.
/**
* @param nodesIdsToPublish
* @param resultingCourseRun
* @param editorModelDeletedNodes
* @param editorModelInsertedNodes
* @param editorModelModifiedNodes
*/
private void calculatePublishSet(List<String> nodesIdsToPublish) {
/*
* START NEW STYLE PUBLISH ................................................. -
* visit each node (breadth first) - if node is selected to be published ->
* publish and take into account if the node exists already in the
* runstructure (keep ident or not). And also if node should get deleted add
* it to a list of nodes to be deleted. This is needed for a later clean-up
* and archive. ............................. - if node is not selected to
* be published, but exists already in the runstructure it must be added to
* the tmp-runstructure as it is in the existing runstructure.
* ..................................................
*/
// start point for node publish visitor
CourseEditorTreeNode editorRoot = (CourseEditorTreeNode) editorTreeModel.getRootNode();
// the active runstructure and the new created runstructure
Structure existingCourseRun = course.getRunStructure();
// breadth first!
boolean visitChildrenFirst = false;
/*
* the tree is visited and the book keeping lists are filled. the visitor
* itself does not delete or modify neither runstructure nor editor tree
* model. The whole complexity of published is encapsulated in the visitor.
*/
Visitor nodePublishV = new NodePublishVisitor(editorRoot, nodesIdsToPublish, existingCourseRun);
TreeVisitor tv = new TreeVisitor(nodePublishV, editorRoot, visitChildrenFirst);
tv.visitAll();
}
use of org.olat.core.util.tree.Visitor 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.Visitor in project openolat by klemens.
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;
}
use of org.olat.core.util.tree.Visitor in project openolat by klemens.
the class UserFoldersTest method myFolders.
/**
* Test retrieve the folder which the user subscribe in a course.
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void myFolders() throws IOException, URISyntaxException {
final Identity id = JunitTestHelper.createAndPersistIdentityAsUser("my-" + UUID.randomUUID().toString());
dbInstance.commitAndCloseSession();
// load my forums
RestConnection conn = new RestConnection();
assertTrue(conn.login(id.getName(), "A6B7C8"));
// subscribed to nothing
URI uri = UriBuilder.fromUri(getContextURI()).path("users").path(id.getKey().toString()).path("folders").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
FolderVOes folders = conn.parse(body, FolderVOes.class);
Assert.assertNotNull(folders);
Assert.assertNotNull(folders.getFolders());
Assert.assertEquals(0, folders.getFolders().length);
// subscribe to the forum
IdentityEnvironment ienv = new IdentityEnvironment(id, new Roles(false, false, false, false, false, false, false));
new CourseTreeVisitor(myCourse, ienv).visit(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof BCCourseNode) {
BCCourseNode folderNode = (BCCourseNode) node;
String relPath = BCCourseNode.getFoldernodePathRelToFolderBase(myCourse.getCourseEnvironment(), folderNode);
String businessPath = "[RepositoryEntry:" + myCourseRe.getKey() + "][CourseNode:" + folderNode.getIdent() + "]";
SubscriptionContext folderSubContext = new SubscriptionContext("CourseModule", myCourse.getResourceableId(), folderNode.getIdent());
PublisherData folderPdata = new PublisherData("FolderModule", relPath, businessPath);
NotificationsManager.getInstance().subscribe(id, folderSubContext, folderPdata);
}
}
}, new VisibleTreeFilter());
dbInstance.commitAndCloseSession();
// retrieve my folders
HttpGet method2 = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response2 = conn.execute(method2);
assertEquals(200, response2.getStatusLine().getStatusCode());
InputStream body2 = response2.getEntity().getContent();
FolderVOes folders2 = conn.parse(body2, FolderVOes.class);
Assert.assertNotNull(folders2);
Assert.assertNotNull(folders2.getFolders());
Assert.assertEquals(1, folders2.getFolders().length);
}
Aggregations