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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations