use of org.olat.core.util.nodes.INode in project openolat by klemens.
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.nodes.INode 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.nodes.INode 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.nodes.INode in project openolat by klemens.
the class GTAManagerTest method getGTACourseNode.
private GTACourseNode getGTACourseNode(RepositoryEntry courseEntry) {
ICourse course = CourseFactory.loadCourse(courseEntry);
CourseNode rootNode = course.getRunStructure().getRootNode();
for (int i = rootNode.getChildCount(); i-- > 0; ) {
INode child = rootNode.getChildAt(i);
if (child instanceof GTACourseNode) {
return ((GTACourseNode) child);
}
}
return null;
}
use of org.olat.core.util.nodes.INode in project openolat by klemens.
the class GTAReminderRuleTest method getGTACourseNode.
private GTACourseNode getGTACourseNode(RepositoryEntry courseEntry) {
ICourse course = CourseFactory.loadCourse(courseEntry);
CourseNode rootNode = course.getRunStructure().getRootNode();
for (int i = rootNode.getChildCount(); i-- > 0; ) {
INode child = rootNode.getChildAt(i);
if (child instanceof GTACourseNode) {
return ((GTACourseNode) child);
}
}
return null;
}
Aggregations