Search in sources :

Example 16 with ConditionExpression

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;
}
Also used : Condition(org.olat.course.condition.Condition) ConditionExpression(org.olat.course.condition.interpreter.ConditionExpression) ArrayList(java.util.ArrayList)

Example 17 with ConditionExpression

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;
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) ConditionExpression(org.olat.course.condition.interpreter.ConditionExpression) ConditionErrorMessage(org.olat.course.condition.interpreter.ConditionErrorMessage)

Example 18 with ConditionExpression

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;
}
Also used : ConditionExpression(org.olat.course.condition.interpreter.ConditionExpression)

Example 19 with ConditionExpression

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;
}
Also used : ConditionExpression(org.olat.course.condition.interpreter.ConditionExpression)

Example 20 with ConditionExpression

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;
}
Also used : Set(java.util.Set) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) DefaultDirectedGraph(org._3pq.jgrapht.graph.DefaultDirectedGraph) HashMap(java.util.HashMap) CycleDetector(org._3pq.jgrapht.alg.CycleDetector) TreeVisitor(org.olat.core.util.tree.TreeVisitor) DefaultDirectedGraph(org._3pq.jgrapht.graph.DefaultDirectedGraph) DirectedGraph(org._3pq.jgrapht.DirectedGraph) DirectedEdgeFactory(org._3pq.jgrapht.edge.EdgeFactories.DirectedEdgeFactory) ConditionExpression(org.olat.course.condition.interpreter.ConditionExpression) Edge(org._3pq.jgrapht.Edge)

Aggregations

ConditionExpression (org.olat.course.condition.interpreter.ConditionExpression)34 ArrayList (java.util.ArrayList)12 ConditionErrorMessage (org.olat.course.condition.interpreter.ConditionErrorMessage)8 Condition (org.olat.course.condition.Condition)6 CourseEditorEnv (org.olat.course.editor.CourseEditorEnv)4 HashMap (java.util.HashMap)2 Set (java.util.Set)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 DirectedGraph (org._3pq.jgrapht.DirectedGraph)2 Edge (org._3pq.jgrapht.Edge)2 CycleDetector (org._3pq.jgrapht.alg.CycleDetector)2 DirectedEdgeFactory (org._3pq.jgrapht.edge.EdgeFactories.DirectedEdgeFactory)2 DefaultDirectedGraph (org._3pq.jgrapht.graph.DefaultDirectedGraph)2 TreeVisitor (org.olat.core.util.tree.TreeVisitor)2 Visitor (org.olat.core.util.tree.Visitor)2 ICourse (org.olat.course.ICourse)2 StatusDescription (org.olat.course.editor.StatusDescription)2 AbstractFeedCourseNode (org.olat.course.nodes.AbstractFeedCourseNode)2