use of org.olat.core.util.tree.Visitor in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_11_2_1 method processCourse.
private boolean processCourse(RepositoryEntry entry) {
try {
ICourse course = CourseFactory.loadCourse(entry);
CourseNode rootNode = course.getRunStructure().getRootNode();
final List<TACourseNode> taskNodes = new ArrayList<>();
new TreeVisitor(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof TACourseNode) {
taskNodes.add((TACourseNode) node);
}
}
}, rootNode, false).visitAll();
for (TACourseNode taskNode : taskNodes) {
processTaskCourseNode(course, entry, taskNode);
}
return true;
} catch (CorruptedCourseException e) {
log.warn("Corrupted course: " + entry.getDisplayname() + " (" + entry.getKey() + ")", e);
return true;
} catch (Exception e) {
log.error("", e);
return true;
}
}
use of org.olat.core.util.tree.Visitor in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class CourseRuntimeController method isAllowedToLeave.
private boolean isAllowedToLeave(UserCourseEnvironmentImpl uce) {
if (uce.getParticipatingGroups().size() > 0) {
CourseNode rootNode = uce.getCourseEnvironment().getRunStructure().getRootNode();
OLATResource courseResource = uce.getCourseEnvironment().getCourseGroupManager().getCourseResource();
AtomicBoolean bool = new AtomicBoolean(false);
new TreeVisitor(new Visitor() {
@Override
public void visit(INode node) {
if (!bool.get() && node instanceof ENCourseNode) {
try {
ENCourseNode enNode = (ENCourseNode) node;
boolean cancelEnrollEnabled = enNode.getModuleConfiguration().getBooleanSafe(ENCourseNode.CONF_CANCEL_ENROLL_ENABLED);
if (!cancelEnrollEnabled && enNode.isUsedForEnrollment(uce.getParticipatingGroups(), courseResource)) {
bool.set(true);
}
} catch (Exception e) {
logError("", e);
}
}
}
}, rootNode, true).visitAll();
if (bool.get()) {
// is in a enrollment group
return false;
}
}
return (uce.isParticipant() || !uce.getParticipatingGroups().isEmpty());
}
use of org.olat.core.util.tree.Visitor in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class MoveCopySubtreeController method doInsert.
private void doInsert(UserRequest ureq, TreePosition tp) {
ICourse course = CourseFactory.getCourseEditSession(ores.getResourceableId());
int insertPos = tp.getChildpos();
CourseNode selectedNode = getCourseNode(tp.getParentTreeNode());
CourseEditorTreeNode insertParent = course.getEditorTreeModel().getCourseEditorNodeById(selectedNode.getIdent());
// check if insert position is within the to-be-copied tree
if (course.getEditorTreeModel().checkIfIsChild(insertParent, moveCopyFrom)) {
showError("movecopynode.error.overlap");
fireEvent(ureq, Event.CANCELLED_EVENT);
} else if (copy) {
// do a copy
// copy subtree and save model
recursiveCopy(moveCopyFrom, insertParent, insertPos, true, CourseFactory.getCourseEditSession(ores.getResourceableId()));
CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_EDITOR_NODE_COPIED, getClass());
fireEvent(ureq, Event.DONE_EVENT);
} else {
// move only
if (insertParent.getIdent().equals(moveCopyFrom.getParent().getIdent())) {
// same parent, adjust insertPos
if (insertPos > moveCopyFrom.getPosition())
insertPos--;
}
insertParent.insert(moveCopyFrom, insertPos);
moveCopyFrom.setDirty(true);
// mark subtree as dirty
TreeVisitor tv = new TreeVisitor(new Visitor() {
@Override
public void visit(INode node) {
CourseEditorTreeNode cetn = (CourseEditorTreeNode) node;
cetn.setDirty(true);
}
}, moveCopyFrom, true);
tv.visitAll();
CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
showInfo("movecopynode.info.condmoved");
ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_EDITOR_NODE_MOVED, getClass());
fireEvent(ureq, Event.DONE_EVENT);
}
}
Aggregations