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