Search in sources :

Example 51 with CourseEditorEnv

use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.

the class IsUserFunction method call.

/**
 * @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
 */
@Override
public Object call(Object[] inStack) {
    /*
		 * argument check
		 */
    if (inStack.length > 1) {
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.provideone.username"));
    } else if (inStack.length < 1) {
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.provideone.username"));
    }
    /*
		 * argument type check
		 */
    if (!(inStack[0] instanceof String))
        return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.username", "solution.example.name.infunction"));
    String userName = (String) inStack[0];
    /*
		 * expression check only if cev != null
		 */
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        // return a valid value to continue with condition evaluation test
        return defaultValue();
    }
    Identity ident = getUserCourseEnv().getIdentityEnvironment().getIdentity();
    if (ident == null || ident.getName() == null) {
        return ConditionInterpreter.INT_FALSE;
    }
    // compare using lowercase as done in login process
    return ident.getName().toLowerCase().equals(userName.toLowerCase()) ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) Identity(org.olat.core.id.Identity)

Example 52 with CourseEditorEnv

use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.

the class NowVariable method getValue.

/**
 * @see com.neemsoft.jmep.VariableCB#getValue()
 */
public Object getValue() {
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        return new Double(0);
    }
    CourseEnvironment ce = getUserCourseEnv().getCourseEnvironment();
    long time = ce.getCurrentTimeMillis();
    return new Double(time);
}
Also used : CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEditorEnv(org.olat.course.editor.CourseEditorEnv)

Example 53 with CourseEditorEnv

use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.

the class Sleep method call.

/**
 * @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
 */
public Object call(Object[] inStack) {
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        // return a valid value to continue with condition evaluation test
        return defaultValue();
    } else if (Settings.isDebuging()) {
        long sleep = 30000;
        if (inStack == null || inStack.length == 0) {
        // stay with default
        } else if (inStack[0] instanceof String) {
            String sleepStr = (String) inStack[0];
            sleep = Long.parseLong(sleepStr);
        }
        try {
            Thread.sleep(sleep);
        } catch (InterruptedException e) {
            log.error("", e);
        }
    }
    return ConditionInterpreter.INT_TRUE;
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv)

Example 54 with CourseEditorEnv

use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.

the class EditScoreCalculationExpertForm method validateFormLogic.

@Override
public boolean validateFormLogic(UserRequest ureq) {
    String scoreExp = tscoreexpr.getValue().trim();
    if (StringHelper.containsNonWhitespace(scoreExp)) {
        CourseEditorEnv cev = euce.getCourseEditorEnv();
        ConditionExpression ce = new ConditionExpression("score", scoreExp);
        ConditionErrorMessage[] cerrmsgs = cev.validateConditionExpression(ce);
        if (cerrmsgs != null && cerrmsgs.length > 0) {
            setKeys(ureq, tscoreexpr, cerrmsgs);
            return false;
        }
        testElemWithNoResource = getInvalidNodeDescriptions(ce);
    }
    String passedExp = tpassedexpr.getValue().trim();
    if (StringHelper.containsNonWhitespace(passedExp)) {
        CourseEditorEnv cev = euce.getCourseEditorEnv();
        ConditionExpression ce = new ConditionExpression("passed", passedExp);
        ConditionErrorMessage[] cerrmsgs = cev.validateConditionExpression(ce);
        if (cerrmsgs != null && cerrmsgs.length > 0) {
            setKeys(ureq, tpassedexpr, cerrmsgs);
            return false;
        }
    }
    // reset HINTS
    tscoreexpr.setExampleKey("rules.example", EXAMPLE_SCORE);
    tpassedexpr.setExampleKey("rules.example", EXAMPLE_PASSED);
    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 55 with CourseEditorEnv

use of org.olat.course.editor.CourseEditorEnv in project openolat by klemens.

the class InLearningAreaFunction method call.

/**
 * @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
 */
public Object call(Object[] inStack) {
    /*
		 * argument check
		 */
    if (inStack.length > 1) {
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.provideone.areaname"));
    } else if (inStack.length < 1) {
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.provideone.areaname"));
    }
    /*
		 * argument type check
		 */
    if (!(inStack[0] instanceof String))
        return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.areanameexpected", "solution.example.name.infunction"));
    String areaName = (String) inStack[0];
    areaName = areaName != null ? areaName.trim() : areaName;
    /*
		 * check reference integrity
		 */
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        if (!cev.existsArea(areaName)) {
            return handleException(new ArgumentParseException(ArgumentParseException.REFERENCE_NOT_FOUND, name, areaName, "error.notfound.name", "solution.checkgroupmanagement"));
        }
        // remember the reference to the node id for this condtion
        cev.addSoftReference("areaId", areaName, false);
        // return a valid value to continue with condition evaluation test
        return defaultValue();
    }
    // The real function evaluation which is used during run time
    Identity ident = getUserCourseEnv().getIdentityEnvironment().getIdentity();
    CourseGroupManager cgm = getUserCourseEnv().getCourseEnvironment().getCourseGroupManager();
    if (StringHelper.isLong(areaName)) {
        Long areaKey = new Long(areaName);
        return cgm.isIdentityInLearningArea(ident, areaKey) ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
    }
    List<Long> areaKeys = CoreSpringFactory.getImpl(BGAreaManager.class).toAreaKeys(areaName, cgm.getCourseResource());
    if (!areaKeys.isEmpty()) {
        return cgm.isIdentityInLearningArea(ident, areaKeys.get(0)) ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
    }
    return ConditionInterpreter.INT_FALSE;
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) Identity(org.olat.core.id.Identity) BGAreaManager(org.olat.group.area.BGAreaManager)

Aggregations

CourseEditorEnv (org.olat.course.editor.CourseEditorEnv)68 Identity (org.olat.core.id.Identity)32 ArgumentParseException (org.olat.course.condition.interpreter.ArgumentParseException)10 CourseGroupManager (org.olat.course.groupsandrights.CourseGroupManager)8 CourseNode (org.olat.course.nodes.CourseNode)8 Date (java.util.Date)6 BusinessGroupService (org.olat.group.BusinessGroupService)6 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)4 User (org.olat.core.id.User)4 AssessmentManager (org.olat.course.assessment.AssessmentManager)4 UserCourseInformations (org.olat.course.assessment.UserCourseInformations)4 UserEfficiencyStatement (org.olat.course.assessment.UserEfficiencyStatement)4 EfficiencyStatementManager (org.olat.course.assessment.manager.EfficiencyStatementManager)4 UserCourseInformationsManager (org.olat.course.assessment.manager.UserCourseInformationsManager)4 ConditionErrorMessage (org.olat.course.condition.interpreter.ConditionErrorMessage)4 ConditionExpression (org.olat.course.condition.interpreter.ConditionExpression)4 ENCourseNode (org.olat.course.nodes.ENCourseNode)4 STCourseNode (org.olat.course.nodes.STCourseNode)4 CoursePropertyManager (org.olat.course.properties.CoursePropertyManager)4 CourseEnvironment (org.olat.course.run.environment.CourseEnvironment)4