use of org.olat.core.util.tree.Visitor in project openolat by klemens.
the class OLATUpgrade_11_0_0 method processCourseAssessmentData.
// select count(*) from o_property where name in ('SCORE','PASSED','ATTEMPTS','COMMENT','COACH_COMMENT','ASSESSMENT_ID','FULLY_ASSESSED');
private boolean processCourseAssessmentData(RepositoryEntry courseEntry) {
boolean allOk = true;
try {
final Long courseResourceId = courseEntry.getOlatResource().getResourceableId();
final ICourse course = CourseFactory.loadCourse(courseEntry);
// load all assessable identities
List<Identity> assessableIdentities = getAllAssessableIdentities(course, courseEntry);
Map<AssessmentDataKey, AssessmentEntryImpl> curentNodeAssessmentMap = new HashMap<>();
{
// load already migrated data
List<AssessmentEntryImpl> currentNodeAssessmentList = loadAssessmentEntries(courseEntry);
for (AssessmentEntryImpl currentNodeAssessment : currentNodeAssessmentList) {
AssessmentDataKey key = new AssessmentDataKey(currentNodeAssessment.getIdentity().getKey(), courseResourceId, currentNodeAssessment.getSubIdent());
curentNodeAssessmentMap.put(key, currentNodeAssessment);
}
}
Map<AssessmentDataKey, AssessmentEntryImpl> nodeAssessmentMap = new HashMap<>();
{
// processed properties
List<Property> courseProperties = loadAssessmentProperties(courseEntry);
for (Property property : courseProperties) {
String propertyCategory = property.getCategory();
if (StringHelper.containsNonWhitespace(propertyCategory)) {
int nodeIdentIndex = propertyCategory.indexOf("::");
if (nodeIdentIndex > 0) {
String nodeIdent = propertyCategory.substring(propertyCategory.indexOf("::") + 2);
AssessmentDataKey key = new AssessmentDataKey(property.getIdentity().getKey(), property.getResourceTypeId(), nodeIdent);
if (curentNodeAssessmentMap.containsKey(key)) {
continue;
}
AssessmentEntryImpl nodeAssessment;
if (nodeAssessmentMap.containsKey(key)) {
nodeAssessment = nodeAssessmentMap.get(key);
if (nodeAssessment.getCreationDate().after(property.getCreationDate())) {
nodeAssessment.setCreationDate(property.getCreationDate());
}
if (nodeAssessment.getLastModified().before(property.getLastModified())) {
nodeAssessment.setLastModified(property.getLastModified());
}
} else {
nodeAssessment = createAssessmentEntry(property.getIdentity(), property, course, courseEntry, nodeIdent);
}
copyAssessmentProperty(property, nodeAssessment, course);
nodeAssessmentMap.put(key, nodeAssessment);
}
}
}
}
// check the transient qti ser
CourseNode rootNode = course.getRunStructure().getRootNode();
new TreeVisitor(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof AssessableCourseNode) {
processNonPropertiesStates(assessableIdentities, (AssessableCourseNode) node, course, courseEntry, nodeAssessmentMap, curentNodeAssessmentMap);
}
}
}, rootNode, true).visitAll();
dbInstance.commitAndCloseSession();
int count = 0;
for (AssessmentEntryImpl courseNodeAssessment : nodeAssessmentMap.values()) {
dbInstance.getCurrentEntityManager().persist(courseNodeAssessment);
if (++count % 50 == 0) {
dbInstance.commit();
}
}
dbInstance.commitAndCloseSession();
allOk = verifyCourseAssessmentData(assessableIdentities, courseEntry);
dbInstance.commitAndCloseSession();
if (allOk) {
List<STCourseNode> nodes = hasAssessableSTCourseNode(course);
if (nodes.size() > 0) {
log.info("Has assessables ST nodes");
for (Identity identity : assessableIdentities) {
IdentityEnvironment identityEnv = new IdentityEnvironment(identity, null);
UserCourseEnvironmentImpl userCourseEnv = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
userCourseEnv.getScoreAccounting().evaluateAll(true);
dbInstance.commit();
}
}
}
} catch (Exception e) {
log.error("", e);
}
return allOk;
}
use of org.olat.core.util.tree.Visitor in project openolat by klemens.
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 klemens.
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 klemens.
the class EditorMainController method dropNodeAsChild.
private void dropNodeAsChild(UserRequest ureq, ICourse course, String droppedNodeId, String targetNodeId, boolean asChild, boolean atTheEnd) {
// setDirty when moving
menuTree.setDirty(true);
CourseNode droppedNode = cetm.getCourseNode(droppedNodeId);
int position;
CourseEditorTreeNode insertParent;
if (asChild) {
insertParent = cetm.getCourseEditorNodeById(targetNodeId);
position = atTheEnd ? -1 : 0;
} else {
CourseEditorTreeNode selectedNode = cetm.getCourseEditorNodeById(targetNodeId);
if (selectedNode.getParent() == null) {
// root node
insertParent = selectedNode;
position = 0;
} else {
insertParent = course.getEditorTreeModel().getCourseEditorNodeById(selectedNode.getParent().getIdent());
position = 0;
for (position = insertParent.getChildCount(); position-- > 0; ) {
if (insertParent.getChildAt(position).getIdent().equals(selectedNode.getIdent())) {
position++;
break;
}
}
}
}
CourseEditorTreeNode moveFrom = course.getEditorTreeModel().getCourseEditorNodeById(droppedNode.getIdent());
// check if an ancestor is not dropped on a child
if (course.getEditorTreeModel().checkIfIsChild(insertParent, moveFrom)) {
showError("movecopynode.error.overlap");
fireEvent(ureq, Event.CANCELLED_EVENT);
return;
}
// don't generate red screen for that. If the position is too high -> add the node at the end
if (position >= insertParent.getChildCount()) {
position = -1;
}
try {
if (position >= 0) {
insertParent.insert(moveFrom, position);
} else {
insertParent.addChild(moveFrom);
}
} catch (IndexOutOfBoundsException e) {
logError("", e);
// reattach the node as security, if not, the node is lost
insertParent.addChild(moveFrom);
}
moveFrom.setDirty(true);
// mark subtree as dirty
TreeVisitor tv = new TreeVisitor(new Visitor() {
public void visit(INode node) {
CourseEditorTreeNode cetn = (CourseEditorTreeNode) node;
cetn.setDirty(true);
}
}, moveFrom, true);
tv.visitAll();
CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
showInfo("movecopynode.info.condmoved");
ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_EDITOR_NODE_MOVED, getClass());
euce.getCourseEditorEnv().validateCourse();
StatusDescription[] courseStatus = euce.getCourseEditorEnv().getCourseStatus();
updateCourseStatusMessages(ureq.getLocale(), courseStatus);
}
use of org.olat.core.util.tree.Visitor in project openolat by klemens.
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();
}
Aggregations