Search in sources :

Example 16 with ConditionInterpreter

use of org.olat.course.condition.interpreter.ConditionInterpreter in project OpenOLAT by OpenOLAT.

the class STCourseNode method getUserScoreEvaluation.

/**
 * the structure node does not have a score itself, but calculates the
 * score/passed info by evaluating the configured expression in the the
 * (condition)interpreter.
 *
 * @see org.olat.course.nodes.AssessableCourseNode#getUserScoreEvaluation(org.olat.course.run.userview.UserCourseEnvironment)
 */
@Override
public AssessmentEvaluation getUserScoreEvaluation(UserCourseEnvironment userCourseEnv) {
    Float score = null;
    Boolean passed = null;
    if (scoreCalculator == null) {
        // this is a not-computable course node at the moment (no scoring/passing rules defined)
        return null;
    }
    String scoreExpressionStr = scoreCalculator.getScoreExpression();
    String passedExpressionStr = scoreCalculator.getPassedExpression();
    ConditionInterpreter ci = userCourseEnv.getConditionInterpreter();
    if (scoreExpressionStr != null) {
        score = new Float(ci.evaluateCalculation(scoreExpressionStr));
    }
    if (passedExpressionStr != null) {
        passed = new Boolean(ci.evaluateCondition(passedExpressionStr));
    }
    return new AssessmentEvaluation(score, passed);
}
Also used : ConditionInterpreter(org.olat.course.condition.interpreter.ConditionInterpreter) AssessmentEvaluation(org.olat.course.run.scoring.AssessmentEvaluation)

Example 17 with ConditionInterpreter

use of org.olat.course.condition.interpreter.ConditionInterpreter in project openolat by klemens.

the class ConditionTest method testHasPropertyFunction.

@Test
public void testHasPropertyFunction() throws Exception {
    UserCourseEnvironment uce = getUserDemoCourseEnvironment();
    ConditionInterpreter interpreter = new ConditionInterpreter(uce);
    String condition = "hasUserProperty(\"firstName\", \"firstcondition\")";
    boolean result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
    condition = "hasUserProperty(\"firstName\", \"\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "hasUserProperty(\"firstName\", \"firstcondition \")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "hasUserProperty(\"firstName\", \" firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "hasUserProperty(\"firstName\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "hasUserProperty(\"firstName\", \"firstcondition\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "hasUserProperty(\"firstName\", \"someThing\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "hasUserProperty(\"firstName\", \"firstconditiongugus\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "hasUserProperty(\"firstName\", \"gugusfirstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "hasUserProperty(\"lastName\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
}
Also used : ConditionInterpreter(org.olat.course.condition.interpreter.ConditionInterpreter) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) Test(org.junit.Test)

Example 18 with ConditionInterpreter

use of org.olat.course.condition.interpreter.ConditionInterpreter in project openolat by klemens.

the class ConditionTest method testIsInUserPropertyFunction.

@Test
public void testIsInUserPropertyFunction() throws Exception {
    UserCourseEnvironment uce = getUserDemoCourseEnvironment();
    ConditionInterpreter interpreter = new ConditionInterpreter(uce);
    String condition = "isInUserProperty(\"firstName\", \"firstcondition\")";
    boolean result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
    condition = "isInUserProperty(\"firstName\", \"stcondit\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
    condition = "isInUserProperty(\"firstName\", \"\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "isInUserProperty(\"firstName\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "isInUserProperty(\"firstName\", \"firstcondition\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "isInUserProperty(\"firstName\", \"someThing\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "isInUserProperty(\"firstName\", \"firstconditiongugus\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "isInUserProperty(\"firstName\", \"gugusfirstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "isInUserProperty(\"lastName\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
}
Also used : ConditionInterpreter(org.olat.course.condition.interpreter.ConditionInterpreter) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) Test(org.junit.Test)

Example 19 with ConditionInterpreter

use of org.olat.course.condition.interpreter.ConditionInterpreter in project openolat by klemens.

the class ConditionTest method complexExpression.

@Test
public void complexExpression() throws Exception {
    UserCourseEnvironment uce = getUserDemoCourseEnvironment();
    ConditionInterpreter interpreter = new ConditionInterpreter(uce);
    String condition = "(((inLearningGroup(\"Rule1Group1\") | inLearningGroup(\"Rule1Group2\"))|inLearningArea(\"Rule1Area1\")))";
    boolean result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(result);
}
Also used : ConditionInterpreter(org.olat.course.condition.interpreter.ConditionInterpreter) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) Test(org.junit.Test)

Example 20 with ConditionInterpreter

use of org.olat.course.condition.interpreter.ConditionInterpreter in project openolat by klemens.

the class ConditionTest method testHasNotPropertyFunction.

@Test
public void testHasNotPropertyFunction() throws Exception {
    UserCourseEnvironment uce = getUserDemoCourseEnvironment();
    ConditionInterpreter interpreter = new ConditionInterpreter(uce);
    String condition = "hasNotUserProperty(\"firstName\", \"firstcondition\")";
    boolean result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "hasNotUserProperty(\"firstName\", \"\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "hasNotUserProperty(\"firstName\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "hasNotUserProperty(\"firstName\", \"firstcondition\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "hasNotUserProperty(\"firstName\", \"someThing\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
    condition = "hasNotUserProperty(\"firstName\", \"firstconditiongugus\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
    condition = "hasNotUserProperty(\"firstName\", \"gugusfirstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
    condition = "hasNotUserProperty(\"lastName\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
}
Also used : ConditionInterpreter(org.olat.course.condition.interpreter.ConditionInterpreter) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) Test(org.junit.Test)

Aggregations

ConditionInterpreter (org.olat.course.condition.interpreter.ConditionInterpreter)22 Test (org.junit.Test)20 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)20 AssessmentEvaluation (org.olat.course.run.scoring.AssessmentEvaluation)2