use of org.olat.course.editor.CourseEditorEnv 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.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.
the class EvalUserPropertyFunction method call.
/**
* @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
*/
public Object call(Object[] inStack) {
/*
* argument check
*/
if (inStack.length > 2) {
String name = getFunctionName(functionType);
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.providetwo.attrvalue"));
} else if (inStack.length < 2) {
String name = getFunctionName(functionType);
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.providetwo.attrvalue"));
}
/*
* argument type check
*/
if (!(inStack[0] instanceof String)) {
String name = getFunctionName(functionType);
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.attributename", "solution.example.name.infunction"));
}
if (!(inStack[1] instanceof String)) {
String name = getFunctionName(functionType);
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.attribvalue", "solution.example.name.infunction"));
} else {
String propValue = (String) inStack[1];
if (!StringHelper.containsNonWhitespace(propValue)) {
String name = getFunctionName(functionType);
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.attribvalue", "solution.example.whiteSpace"));
}
}
/*
* check reference integrity
*/
CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
if (cev != null) {
// return a valid value to continue with condition evaluation test
return defaultValue();
}
/*
* the real function evaluation which is used during run time
*/
String propName = (String) inStack[0];
String searchValue = (String) inStack[1];
Identity ident = getUserCourseEnv().getIdentityEnvironment().getIdentity();
if (ident == null) {
return defaultValue();
}
User user = ident.getUser();
String userValue = user.getPropertyOrIdentityEnvAttribute(propName, null);
boolean match = false;
boolean debug = log.isDebug();
if (debug) {
log.debug("value : " + userValue);
log.debug("searchValue: " + searchValue);
log.debug("fT : " + functionType);
}
if (StringHelper.containsNonWhitespace(userValue)) {
match = checkPropertyValue(searchValue, userValue);
}
if (debug) {
log.debug("identity '" + ident.getName() + "' tested on properties '" + propName + "' to have value '" + searchValue + "' user's value was '" + userValue + "', match=" + match);
}
return match ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.
the class GetLastAttemptDateFunction 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.nodereference"));
} else if (inStack.length < 1) {
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.provideone.nodereference"));
}
/*
* argument type check
*/
if (!(inStack[0] instanceof String))
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.coursnodeidexpeted", "solution.example.node.infunction"));
String nodeId = (String) inStack[0];
/*
* check reference integrity
*/
CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
if (cev != null) {
if (!cev.existsNode(nodeId)) {
return handleException(new ArgumentParseException(ArgumentParseException.REFERENCE_NOT_FOUND, name, nodeId, "error.notfound.coursenodeid", "solution.copypastenodeid"));
}
// Allow self-referencing but do not allow dependencies to parents as they create cycles.
if (!nodeId.equals(cev.getCurrentCourseNodeId())) {
cev.addSoftReference("courseNodeId", nodeId, false);
}
// return a valid value to continue with condition evaluation test
return defaultValue();
}
/*
* the real function evaluation which is used during run time
*/
CourseNode node = getUserCourseEnv().getCourseEnvironment().getRunStructure().getNode(nodeId);
AssessmentManager am = getUserCourseEnv().getCourseEnvironment().getAssessmentManager();
Identity identity = getUserCourseEnv().getIdentityEnvironment().getIdentity();
// use the last modified date from the course node
Date lastModified = am.getScoreLastModifiedDate(node, identity);
if (lastModified != null && lastModified.getTime() > 0) {
return Double.valueOf(lastModified.getTime());
} else {
// what to do in case of no date available??? -> return date in the future
return new Double(Double.POSITIVE_INFINITY);
}
}
use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.
the class HasLanguageFunction 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.providetwo.attrvalue"));
} else if (inStack.length < 1) {
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.providetwo.attrvalue"));
}
/*
* argument type check
*/
if (!(inStack[0] instanceof String))
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.attributename", "solution.example.name.infunction"));
String lang = (String) inStack[0];
Locale locale;
CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
if (cev != null) {
locale = cev.getEditorEnvLocale();
} else {
IdentityEnvironment ienv = getUserCourseEnv().getIdentityEnvironment();
locale = ienv.getLocale();
}
// return true for locale="de_CH" and given lang="de"
return (locale.toString().toLowerCase().startsWith(lang.toLowerCase()) ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE);
}
use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.
the class InLearningGroupFunction 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.groupname"));
} else if (inStack.length < 1) {
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.provideone.groupname"));
}
/*
* argument type check
*/
if (!(inStack[0] instanceof String))
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.groupnameexpected", "solution.example.name.infunction"));
String groupName = (String) inStack[0];
groupName = groupName != null ? groupName.trim() : null;
/*
* check reference integrity
*/
CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
if (cev != null) {
if (!cev.existsGroup(groupName)) {
return handleException(new ArgumentParseException(ArgumentParseException.REFERENCE_NOT_FOUND, name, groupName, "error.notfound.name", "solution.checkgroupmanagement"));
}
// remember the reference to the node id for this condtion
cev.addSoftReference("groupId", groupName, false);
// return a valid value to continue with condition evaluation test
return defaultValue();
}
// the real function evaluation which is used during run time
if (StringHelper.isLong(groupName)) {
try {
Long groupKey = Long.parseLong(groupName);
return getUserCourseEnv().isIdentityInCourseGroup(groupKey) ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
} catch (NumberFormatException e) {
log.error("" + groupName, e);
}
}
CourseGroupManager cgm = getUserCourseEnv().getCourseEnvironment().getCourseGroupManager();
List<Long> groupKeys = CoreSpringFactory.getImpl(BusinessGroupService.class).toGroupKeys(groupName, cgm.getCourseEntry());
if (!groupKeys.isEmpty()) {
Identity ident = getUserCourseEnv().getIdentityEnvironment().getIdentity();
return cgm.isIdentityInGroup(ident, groupKeys.get(0)) ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
return ConditionInterpreter.INT_FALSE;
}
Aggregations