use of org.olat.course.condition.interpreter.ConditionExpression in project openolat by klemens.
the class WikiCourseNode method getConditionExpressions.
@Override
public List<ConditionExpression> getConditionExpressions() {
List<ConditionExpression> parentConditions = super.getConditionExpressions();
List<ConditionExpression> conditions = new ArrayList<>();
if (parentConditions != null && parentConditions.size() > 0) {
conditions.addAll(parentConditions);
}
Condition editCondition = getPreConditionEdit();
if (editCondition != null && StringHelper.containsNonWhitespace(editCondition.getConditionExpression())) {
ConditionExpression ce = new ConditionExpression(editCondition.getConditionId());
ce.setExpressionString(editCondition.getConditionExpression());
conditions.add(ce);
}
return conditions;
}
use of org.olat.course.condition.interpreter.ConditionExpression in project openolat by klemens.
the class ConditionConfigExpertForm method validateFormLogic.
@Override
public boolean validateFormLogic(UserRequest ureq) {
if (tprecond.isEmpty()) {
// the precondition
return true;
}
/*
* not empty, nowOLAT - Demo Course_1264602504362 test precondition syntax and for existing soft references
*/
CourseEditorEnv cev = euce.getCourseEditorEnv();
ConditionExpression ce = new ConditionExpression(conditionId, tprecond.getValue());
ConditionErrorMessage[] cerrmsg = cev.validateConditionExpression(ce);
/*
* display any error detected in the condition expression testing.
*/
if (cerrmsg != null && cerrmsg.length > 0) {
// the error messOLAT - Demo Course_1264602504362age
tprecond.setErrorKey(cerrmsg[0].errorKey, cerrmsg[0].errorKeyParams);
if (cerrmsg[0].solutionMsgKey != null && !"".equals(cerrmsg[0].solutionMsgKey)) {
// and a hint or example to clarify the error message
tprecond.setExampleKey(cerrmsg[0].solutionMsgKey, cerrmsg[0].errorKeyParams);
}
return false;
}
// reset HINTS
tprecond.setExampleKey("xx", new String[] { "" });
return true;
}
use of org.olat.course.condition.interpreter.ConditionExpression in project openolat by klemens.
the class BCCourseNode method getConditionExpressions.
/**
* @see org.olat.course.nodes.GenericCourseNode#getConditionExpressions()
*/
public List<ConditionExpression> getConditionExpressions() {
List<ConditionExpression> retVal;
List<ConditionExpression> parentsConditions = super.getConditionExpressions();
if (parentsConditions.size() > 0) {
retVal = new ArrayList<ConditionExpression>(parentsConditions);
} else {
retVal = new ArrayList<ConditionExpression>();
}
//
String coS = getPreConditionDownloaders().getConditionExpression();
if (coS != null && !coS.equals("")) {
// an active condition is defined
ConditionExpression ce = new ConditionExpression(getPreConditionDownloaders().getConditionId());
ce.setExpressionString(getPreConditionDownloaders().getConditionExpression());
retVal.add(ce);
}
//
coS = getPreConditionUploaders().getConditionExpression();
if (coS != null && !coS.equals("")) {
// an active condition is defined
ConditionExpression ce = new ConditionExpression(getPreConditionUploaders().getConditionId());
ce.setExpressionString(getPreConditionUploaders().getConditionExpression());
retVal.add(ce);
}
//
return retVal;
}
use of org.olat.course.condition.interpreter.ConditionExpression in project openolat by klemens.
the class CourseEditorEnvImpl method toString.
@Override
public String toString() {
String retVal = "";
Set<String> keys = softRefs.keySet();
for (Iterator<String> iter = keys.iterator(); iter.hasNext(); ) {
String nodId = iter.next();
retVal += "nodeId:" + nodId + "\n";
List<ConditionExpression> conditionExprs = softRefs.get(nodId);
for (Iterator<ConditionExpression> iterator = conditionExprs.iterator(); iterator.hasNext(); ) {
ConditionExpression ce = iterator.next();
retVal += "\t" + ce.toString() + "\n";
}
retVal += "\n";
}
return retVal;
}
use of org.olat.course.condition.interpreter.ConditionExpression 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;
}
Aggregations